linux-renesas-soc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] clk: renesas: mstp: Combine private data and array allocation
@ 2019-06-17 12:39 Geert Uytterhoeven
  2019-06-17 12:39 ` [PATCH 1/3] clk: renesas: cpg-mssr: Combine driver-private and clock " Geert Uytterhoeven
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Geert Uytterhoeven @ 2019-06-17 12:39 UTC (permalink / raw)
  To: Michael Turquette, Stephen Boyd
  Cc: linux-clk, linux-renesas-soc, Geert Uytterhoeven

	Hi Mike, Stephen,

This patch series combines multiple allocations of driver-private data
and arrays in the Renesas clock drivers to single allocations, using
flexible array members and the new struct_size() helper.

This has a contextual dependency on "[PATCH] clk: renesas: cpg-mssr:
Update kerneldoc for struct cpg_mssr_priv".

To be queued in clk-renesas-for-v5.3, if approved.

Thanks for your comments!

Geert Uytterhoeven (3):
  clk: renesas: cpg-mssr: Combine driver-private and clock array
    allocation
  clk: renesas: div6: Combine clock-private and parent array allocation
  clk: renesas: mstp: Combine group-private and clock array allocation

 drivers/clk/renesas/clk-div6.c         | 19 +++++--------------
 drivers/clk/renesas/clk-mstp.c         | 12 ++++++------
 drivers/clk/renesas/renesas-cpg-mssr.c | 20 ++++++--------------
 3 files changed, 17 insertions(+), 34 deletions(-)

-- 
2.17.1

Gr{oetje,eeting}s,

						Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
							    -- Linus Torvalds

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/3] clk: renesas: cpg-mssr: Combine driver-private and clock array allocation
  2019-06-17 12:39 [PATCH 0/3] clk: renesas: mstp: Combine private data and array allocation Geert Uytterhoeven
@ 2019-06-17 12:39 ` Geert Uytterhoeven
  2019-06-18 10:52   ` Simon Horman
  2019-06-17 12:39 ` [PATCH 2/3] clk: renesas: div6: Combine clock-private and parent " Geert Uytterhoeven
  2019-06-17 12:39 ` [PATCH 3/3] clk: renesas: mstp: Combine group-private and clock " Geert Uytterhoeven
  2 siblings, 1 reply; 7+ messages in thread
From: Geert Uytterhoeven @ 2019-06-17 12:39 UTC (permalink / raw)
  To: Michael Turquette, Stephen Boyd
  Cc: linux-clk, linux-renesas-soc, Geert Uytterhoeven

Make cpg_mssr_priv.clks[] a flexible array member, and use the new
struct_size() helper, to combine the allocation of the driver-private
structure and array of available clocks.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
 drivers/clk/renesas/renesas-cpg-mssr.c | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)

diff --git a/drivers/clk/renesas/renesas-cpg-mssr.c b/drivers/clk/renesas/renesas-cpg-mssr.c
index 4ddf688b8bcc7ed8..7c241ff3ae2f0153 100644
--- a/drivers/clk/renesas/renesas-cpg-mssr.c
+++ b/drivers/clk/renesas/renesas-cpg-mssr.c
@@ -113,7 +113,6 @@ static const u16 srcr[] = {
  * @base: CPG/MSSR register block base address
  * @rmw_lock: protects RMW register accesses
  * @np: Device node in DT for this CPG/MSSR module
- * @clks: Array containing all Core and Module Clocks
  * @num_core_clks: Number of Core Clocks in clks[]
  * @num_mod_clks: Number of Module Clocks in clks[]
  * @last_dt_core_clk: ID of the last Core Clock exported to DT
@@ -121,6 +120,7 @@ static const u16 srcr[] = {
  * @notifiers: Notifier chain to save/restore clock state for system resume
  * @smstpcr_saved[].mask: Mask of SMSTPCR[] bits under our control
  * @smstpcr_saved[].val: Saved values of SMSTPCR[]
+ * @clks: Array containing all Core and Module Clocks
  */
 struct cpg_mssr_priv {
 #ifdef CONFIG_RESET_CONTROLLER
@@ -131,7 +131,6 @@ struct cpg_mssr_priv {
 	spinlock_t rmw_lock;
 	struct device_node *np;
 
-	struct clk **clks;
 	unsigned int num_core_clks;
 	unsigned int num_mod_clks;
 	unsigned int last_dt_core_clk;
@@ -142,6 +141,8 @@ struct cpg_mssr_priv {
 		u32 mask;
 		u32 val;
 	} smstpcr_saved[ARRAY_SIZE(smstpcr)];
+
+	struct clk *clks[];
 };
 
 static struct cpg_mssr_priv *cpg_mssr_priv;
@@ -891,7 +892,6 @@ static int __init cpg_mssr_common_init(struct device *dev,
 				       const struct cpg_mssr_info *info)
 {
 	struct cpg_mssr_priv *priv;
-	struct clk **clks = NULL;
 	unsigned int nclks, i;
 	int error;
 
@@ -901,7 +901,8 @@ static int __init cpg_mssr_common_init(struct device *dev,
 			return error;
 	}
 
-	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
+	nclks = info->num_total_core_clks + info->num_hw_mod_clks;
+	priv = kzalloc(struct_size(priv, clks, nclks), GFP_KERNEL);
 	if (!priv)
 		return -ENOMEM;
 
@@ -915,15 +916,7 @@ static int __init cpg_mssr_common_init(struct device *dev,
 		goto out_err;
 	}
 
-	nclks = info->num_total_core_clks + info->num_hw_mod_clks;
-	clks = kmalloc_array(nclks, sizeof(*clks), GFP_KERNEL);
-	if (!clks) {
-		error = -ENOMEM;
-		goto out_err;
-	}
-
 	cpg_mssr_priv = priv;
-	priv->clks = clks;
 	priv->num_core_clks = info->num_total_core_clks;
 	priv->num_mod_clks = info->num_hw_mod_clks;
 	priv->last_dt_core_clk = info->last_dt_core_clk;
@@ -931,7 +924,7 @@ static int __init cpg_mssr_common_init(struct device *dev,
 	priv->stbyctrl = info->stbyctrl;
 
 	for (i = 0; i < nclks; i++)
-		clks[i] = ERR_PTR(-ENOENT);
+		priv->clks[i] = ERR_PTR(-ENOENT);
 
 	error = of_clk_add_provider(np, cpg_mssr_clk_src_twocell_get, priv);
 	if (error)
@@ -940,7 +933,6 @@ static int __init cpg_mssr_common_init(struct device *dev,
 	return 0;
 
 out_err:
-	kfree(clks);
 	if (priv->base)
 		iounmap(priv->base);
 	kfree(priv);
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/3] clk: renesas: div6: Combine clock-private and parent array allocation
  2019-06-17 12:39 [PATCH 0/3] clk: renesas: mstp: Combine private data and array allocation Geert Uytterhoeven
  2019-06-17 12:39 ` [PATCH 1/3] clk: renesas: cpg-mssr: Combine driver-private and clock " Geert Uytterhoeven
@ 2019-06-17 12:39 ` Geert Uytterhoeven
  2019-06-18 11:02   ` Simon Horman
  2019-06-17 12:39 ` [PATCH 3/3] clk: renesas: mstp: Combine group-private and clock " Geert Uytterhoeven
  2 siblings, 1 reply; 7+ messages in thread
From: Geert Uytterhoeven @ 2019-06-17 12:39 UTC (permalink / raw)
  To: Michael Turquette, Stephen Boyd
  Cc: linux-clk, linux-renesas-soc, Geert Uytterhoeven

Make div6_clock.parents[] a flexible array member, and use the new
struct_size() helper, to combine the allocation of the clock-private
structure and array of parent clocks.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
 drivers/clk/renesas/clk-div6.c | 19 +++++--------------
 1 file changed, 5 insertions(+), 14 deletions(-)

diff --git a/drivers/clk/renesas/clk-div6.c b/drivers/clk/renesas/clk-div6.c
index e98a9f5b3c90cc98..5ca183e701667b46 100644
--- a/drivers/clk/renesas/clk-div6.c
+++ b/drivers/clk/renesas/clk-div6.c
@@ -30,8 +30,8 @@
  * @div: divisor value (1-64)
  * @src_shift: Shift to access the register bits to select the parent clock
  * @src_width: Number of register bits to select the parent clock (may be 0)
- * @parents: Array to map from valid parent clocks indices to hardware indices
  * @nb: Notifier block to save/restore clock state for system resume
+ * @parents: Array to map from valid parent clocks indices to hardware indices
  */
 struct div6_clock {
 	struct clk_hw hw;
@@ -39,8 +39,8 @@ struct div6_clock {
 	unsigned int div;
 	u32 src_shift;
 	u32 src_width;
-	u8 *parents;
 	struct notifier_block nb;
+	u8 parents[];
 };
 
 #define to_div6_clock(_hw) container_of(_hw, struct div6_clock, hw)
@@ -221,17 +221,10 @@ struct clk * __init cpg_div6_register(const char *name,
 	struct clk *clk;
 	unsigned int i;
 
-	clock = kzalloc(sizeof(*clock), GFP_KERNEL);
+	clock = kzalloc(struct_size(clock, parents, num_parents), GFP_KERNEL);
 	if (!clock)
 		return ERR_PTR(-ENOMEM);
 
-	clock->parents = kmalloc_array(num_parents, sizeof(*clock->parents),
-				       GFP_KERNEL);
-	if (!clock->parents) {
-		clk = ERR_PTR(-ENOMEM);
-		goto free_clock;
-	}
-
 	clock->reg = reg;
 
 	/*
@@ -259,7 +252,7 @@ struct clk * __init cpg_div6_register(const char *name,
 		pr_err("%s: invalid number of parents for DIV6 clock %s\n",
 		       __func__, name);
 		clk = ERR_PTR(-EINVAL);
-		goto free_parents;
+		goto free_clock;
 	}
 
 	/* Filter out invalid parents */
@@ -282,7 +275,7 @@ struct clk * __init cpg_div6_register(const char *name,
 
 	clk = clk_register(NULL, &clock->hw);
 	if (IS_ERR(clk))
-		goto free_parents;
+		goto free_clock;
 
 	if (notifiers) {
 		clock->nb.notifier_call = cpg_div6_clock_notifier_call;
@@ -291,8 +284,6 @@ struct clk * __init cpg_div6_register(const char *name,
 
 	return clk;
 
-free_parents:
-	kfree(clock->parents);
 free_clock:
 	kfree(clock);
 	return clk;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/3] clk: renesas: mstp: Combine group-private and clock array allocation
  2019-06-17 12:39 [PATCH 0/3] clk: renesas: mstp: Combine private data and array allocation Geert Uytterhoeven
  2019-06-17 12:39 ` [PATCH 1/3] clk: renesas: cpg-mssr: Combine driver-private and clock " Geert Uytterhoeven
  2019-06-17 12:39 ` [PATCH 2/3] clk: renesas: div6: Combine clock-private and parent " Geert Uytterhoeven
@ 2019-06-17 12:39 ` Geert Uytterhoeven
  2019-06-18 11:02   ` Simon Horman
  2 siblings, 1 reply; 7+ messages in thread
From: Geert Uytterhoeven @ 2019-06-17 12:39 UTC (permalink / raw)
  To: Michael Turquette, Stephen Boyd
  Cc: linux-clk, linux-renesas-soc, Geert Uytterhoeven

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: Geert Uytterhoeven <geert+renesas@glider.be>
---
 drivers/clk/renesas/clk-mstp.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/clk/renesas/clk-mstp.c b/drivers/clk/renesas/clk-mstp.c
index a5e9f9edf04079c7..dfbef37eed4a82e8 100644
--- a/drivers/clk/renesas/clk-mstp.c
+++ b/drivers/clk/renesas/clk-mstp.c
@@ -30,11 +30,12 @@
 /**
  * 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
  * @mstpsr: module stop status register (optional)
  * @lock: protects writes to SMSTPCR
  * @width_8bit: registers are 8-bit, not 32-bit
+ * @clks: clocks in this group
  */
 struct mstp_clock_group {
 	struct clk_onecell_data data;
@@ -42,6 +43,7 @@ struct mstp_clock_group {
 	void __iomem *mstpsr;
 	spinlock_t lock;
 	bool width_8bit;
+	struct clk *clks[];
 };
 
 /**
@@ -187,14 +189,13 @@ static void __init cpg_mstp_clocks_init(struct device_node *np)
 	struct clk **clks;
 	unsigned int i;
 
-	group = kzalloc(sizeof(*group), GFP_KERNEL);
-	clks = kmalloc_array(MSTP_MAX_CLOCKS, sizeof(*clks), GFP_KERNEL);
-	if (group == NULL || clks == NULL) {
+	group = kzalloc(struct_size(group, clks, MSTP_MAX_CLOCKS), GFP_KERNEL);
+	if (group == NULL) {
 		kfree(group);
-		kfree(clks);
 		return;
 	}
 
+	clks = group->clks;
 	spin_lock_init(&group->lock);
 	group->data.clks = clks;
 
@@ -204,7 +205,6 @@ static void __init cpg_mstp_clocks_init(struct device_node *np)
 	if (group->smstpcr == NULL) {
 		pr_err("%s: failed to remap SMSTPCR\n", __func__);
 		kfree(group);
-		kfree(clks);
 		return;
 	}
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/3] clk: renesas: cpg-mssr: Combine driver-private and clock array allocation
  2019-06-17 12:39 ` [PATCH 1/3] clk: renesas: cpg-mssr: Combine driver-private and clock " Geert Uytterhoeven
@ 2019-06-18 10:52   ` Simon Horman
  0 siblings, 0 replies; 7+ messages in thread
From: Simon Horman @ 2019-06-18 10:52 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Michael Turquette, Stephen Boyd, linux-clk, linux-renesas-soc

On Mon, Jun 17, 2019 at 02:39:41PM +0200, Geert Uytterhoeven wrote:
> Make cpg_mssr_priv.clks[] a flexible array member, and use the new
> struct_size() helper, to combine the allocation of the driver-private
> structure and array of available clocks.
> 
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>

Reviewed-by: Simon Horman <horms+renesas@verge.net.au>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/3] clk: renesas: div6: Combine clock-private and parent array allocation
  2019-06-17 12:39 ` [PATCH 2/3] clk: renesas: div6: Combine clock-private and parent " Geert Uytterhoeven
@ 2019-06-18 11:02   ` Simon Horman
  0 siblings, 0 replies; 7+ messages in thread
From: Simon Horman @ 2019-06-18 11:02 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Michael Turquette, Stephen Boyd, linux-clk, linux-renesas-soc

On Mon, Jun 17, 2019 at 02:39:42PM +0200, Geert Uytterhoeven wrote:
> Make div6_clock.parents[] a flexible array member, and use the new
> struct_size() helper, to combine the allocation of the clock-private
> structure and array of parent clocks.
> 
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>

Reviewed-by: Simon Horman <horms+renesas@verge.net.au>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/3] clk: renesas: mstp: Combine group-private and clock array allocation
  2019-06-17 12:39 ` [PATCH 3/3] clk: renesas: mstp: Combine group-private and clock " Geert Uytterhoeven
@ 2019-06-18 11:02   ` Simon Horman
  0 siblings, 0 replies; 7+ messages in thread
From: Simon Horman @ 2019-06-18 11:02 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Michael Turquette, Stephen Boyd, linux-clk, linux-renesas-soc

On Mon, Jun 17, 2019 at 02:39:43PM +0200, Geert Uytterhoeven wrote:
> 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: Geert Uytterhoeven <geert+renesas@glider.be>

Reviewed-by: Simon Horman <horms+renesas@verge.net.au>


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-06-18 11:02 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-17 12:39 [PATCH 0/3] clk: renesas: mstp: Combine private data and array allocation Geert Uytterhoeven
2019-06-17 12:39 ` [PATCH 1/3] clk: renesas: cpg-mssr: Combine driver-private and clock " Geert Uytterhoeven
2019-06-18 10:52   ` Simon Horman
2019-06-17 12:39 ` [PATCH 2/3] clk: renesas: div6: Combine clock-private and parent " Geert Uytterhoeven
2019-06-18 11:02   ` Simon Horman
2019-06-17 12:39 ` [PATCH 3/3] clk: renesas: mstp: Combine group-private and clock " Geert Uytterhoeven
2019-06-18 11:02   ` Simon Horman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).