Commit a79f5836 authored by Geert Uytterhoeven's avatar Geert Uytterhoeven

clk: renesas: mstp: Combine group-private and clock array allocation

Make mstp_clock_group.clks[] a flexible array member, and use the new
struct_size() helper, to combine the allocation of the group-private
structure and array of module clocks.
Signed-off-by: default avatarGeert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: default avatarSimon Horman <horms+renesas@verge.net.au>
parent ba038611
...@@ -30,11 +30,12 @@ ...@@ -30,11 +30,12 @@
/** /**
* struct mstp_clock_group - MSTP gating clocks group * struct mstp_clock_group - MSTP gating clocks group
* *
* @data: clocks in this group * @data: clock specifier translation for clocks in this group
* @smstpcr: module stop control register * @smstpcr: module stop control register
* @mstpsr: module stop status register (optional) * @mstpsr: module stop status register (optional)
* @lock: protects writes to SMSTPCR * @lock: protects writes to SMSTPCR
* @width_8bit: registers are 8-bit, not 32-bit * @width_8bit: registers are 8-bit, not 32-bit
* @clks: clocks in this group
*/ */
struct mstp_clock_group { struct mstp_clock_group {
struct clk_onecell_data data; struct clk_onecell_data data;
...@@ -42,6 +43,7 @@ struct mstp_clock_group { ...@@ -42,6 +43,7 @@ struct mstp_clock_group {
void __iomem *mstpsr; void __iomem *mstpsr;
spinlock_t lock; spinlock_t lock;
bool width_8bit; bool width_8bit;
struct clk *clks[];
}; };
/** /**
...@@ -186,14 +188,13 @@ static void __init cpg_mstp_clocks_init(struct device_node *np) ...@@ -186,14 +188,13 @@ static void __init cpg_mstp_clocks_init(struct device_node *np)
struct clk **clks; struct clk **clks;
unsigned int i; unsigned int i;
group = kzalloc(sizeof(*group), GFP_KERNEL); group = kzalloc(struct_size(group, clks, MSTP_MAX_CLOCKS), GFP_KERNEL);
clks = kmalloc_array(MSTP_MAX_CLOCKS, sizeof(*clks), GFP_KERNEL); if (group == NULL) {
if (group == NULL || clks == NULL) {
kfree(group); kfree(group);
kfree(clks);
return; return;
} }
clks = group->clks;
spin_lock_init(&group->lock); spin_lock_init(&group->lock);
group->data.clks = clks; group->data.clks = clks;
...@@ -203,7 +204,6 @@ static void __init cpg_mstp_clocks_init(struct device_node *np) ...@@ -203,7 +204,6 @@ static void __init cpg_mstp_clocks_init(struct device_node *np)
if (group->smstpcr == NULL) { if (group->smstpcr == NULL) {
pr_err("%s: failed to remap SMSTPCR\n", __func__); pr_err("%s: failed to remap SMSTPCR\n", __func__);
kfree(group); kfree(group);
kfree(clks);
return; return;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment