public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] clk: Switch to use kmemdup_array()
@ 2024-08-14 12:54 Andy Shevchenko
  2024-08-14 12:54 ` [PATCH v2 1/2] clk: mmp: " Andy Shevchenko
  2024-08-14 12:54 ` [PATCH v2 2/2] clk: visconti: " Andy Shevchenko
  0 siblings, 2 replies; 5+ messages in thread
From: Andy Shevchenko @ 2024-08-14 12:54 UTC (permalink / raw)
  To: Andy Shevchenko, linux-clk, linux-kernel, linux-arm-kernel
  Cc: Michael Turquette, Stephen Boyd, Nobuhiro Iwamatsu

Replace open coded kmemdup_array(), which does an additional
overflow check.

v2:
- dropped upstreamed changes
- fixed a typo in the commit messages

Andy Shevchenko (2):
  clk: mmp: Switch to use kmemdup_array()
  clk: visconti: Switch to use kmemdup_array()

 drivers/clk/mmp/clk-mix.c  | 10 ++++------
 drivers/clk/visconti/pll.c |  6 +++---
 2 files changed, 7 insertions(+), 9 deletions(-)

-- 
2.43.0.rc1.1336.g36b5255a03ac


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

* [PATCH v2 1/2] clk: mmp: Switch to use kmemdup_array()
  2024-08-14 12:54 [PATCH v2 0/2] clk: Switch to use kmemdup_array() Andy Shevchenko
@ 2024-08-14 12:54 ` Andy Shevchenko
  2024-08-15  0:37   ` Stephen Boyd
  2024-08-14 12:54 ` [PATCH v2 2/2] clk: visconti: " Andy Shevchenko
  1 sibling, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2024-08-14 12:54 UTC (permalink / raw)
  To: Andy Shevchenko, linux-clk, linux-kernel, linux-arm-kernel
  Cc: Michael Turquette, Stephen Boyd, Nobuhiro Iwamatsu

Let the kmemdup_array() take care about multiplication and possible
overflows.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/clk/mmp/clk-mix.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/clk/mmp/clk-mix.c b/drivers/clk/mmp/clk-mix.c
index 454d131f475e..07ac9e6937e5 100644
--- a/drivers/clk/mmp/clk-mix.c
+++ b/drivers/clk/mmp/clk-mix.c
@@ -447,7 +447,6 @@ struct clk *mmp_clk_register_mix(struct device *dev,
 	struct mmp_clk_mix *mix;
 	struct clk *clk;
 	struct clk_init_data init;
-	size_t table_bytes;
 
 	mix = kzalloc(sizeof(*mix), GFP_KERNEL);
 	if (!mix)
@@ -461,8 +460,8 @@ struct clk *mmp_clk_register_mix(struct device *dev,
 
 	memcpy(&mix->reg_info, &config->reg_info, sizeof(config->reg_info));
 	if (config->table) {
-		table_bytes = sizeof(*config->table) * config->table_size;
-		mix->table = kmemdup(config->table, table_bytes, GFP_KERNEL);
+		mix->table = kmemdup_array(config->table, config->table_size,
+					   sizeof(*mix->table), GFP_KERNEL);
 		if (!mix->table)
 			goto free_mix;
 
@@ -470,9 +469,8 @@ struct clk *mmp_clk_register_mix(struct device *dev,
 	}
 
 	if (config->mux_table) {
-		table_bytes = sizeof(u32) * num_parents;
-		mix->mux_table = kmemdup(config->mux_table, table_bytes,
-					 GFP_KERNEL);
+		mix->mux_table = kmemdup_array(config->mux_table, num_parents,
+					       sizeof(*mix->mux_table), GFP_KERNEL);
 		if (!mix->mux_table) {
 			kfree(mix->table);
 			goto free_mix;
-- 
2.43.0.rc1.1336.g36b5255a03ac


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

* [PATCH v2 2/2] clk: visconti: Switch to use kmemdup_array()
  2024-08-14 12:54 [PATCH v2 0/2] clk: Switch to use kmemdup_array() Andy Shevchenko
  2024-08-14 12:54 ` [PATCH v2 1/2] clk: mmp: " Andy Shevchenko
@ 2024-08-14 12:54 ` Andy Shevchenko
  2024-08-15  0:37   ` Stephen Boyd
  1 sibling, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2024-08-14 12:54 UTC (permalink / raw)
  To: Andy Shevchenko, linux-clk, linux-kernel, linux-arm-kernel
  Cc: Michael Turquette, Stephen Boyd, Nobuhiro Iwamatsu

Let the kmemdup_array() take care about multiplication and possible
overflows.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/clk/visconti/pll.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/clk/visconti/pll.c b/drivers/clk/visconti/pll.c
index e9cd80e085dc..3f929cf8dd2f 100644
--- a/drivers/clk/visconti/pll.c
+++ b/drivers/clk/visconti/pll.c
@@ -262,9 +262,9 @@ static struct clk_hw *visconti_register_pll(struct visconti_pll_provider *ctx,
 	for (len = 0; rate_table[len].rate != 0; )
 		len++;
 	pll->rate_count = len;
-	pll->rate_table = kmemdup(rate_table,
-				  pll->rate_count * sizeof(struct visconti_pll_rate_table),
-				  GFP_KERNEL);
+	pll->rate_table = kmemdup_array(rate_table,
+					pll->rate_count, sizeof(*pll->rate_table),
+					GFP_KERNEL);
 	WARN(!pll->rate_table, "%s: could not allocate rate table for %s\n", __func__, name);
 
 	init.ops = &visconti_pll_ops;
-- 
2.43.0.rc1.1336.g36b5255a03ac


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

* Re: [PATCH v2 1/2] clk: mmp: Switch to use kmemdup_array()
  2024-08-14 12:54 ` [PATCH v2 1/2] clk: mmp: " Andy Shevchenko
@ 2024-08-15  0:37   ` Stephen Boyd
  0 siblings, 0 replies; 5+ messages in thread
From: Stephen Boyd @ 2024-08-15  0:37 UTC (permalink / raw)
  To: Andy Shevchenko, linux-arm-kernel, linux-clk, linux-kernel
  Cc: Michael Turquette, Nobuhiro Iwamatsu

Quoting Andy Shevchenko (2024-08-14 05:54:07)
> Let the kmemdup_array() take care about multiplication and possible
> overflows.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---

Applied to clk-next

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

* Re: [PATCH v2 2/2] clk: visconti: Switch to use kmemdup_array()
  2024-08-14 12:54 ` [PATCH v2 2/2] clk: visconti: " Andy Shevchenko
@ 2024-08-15  0:37   ` Stephen Boyd
  0 siblings, 0 replies; 5+ messages in thread
From: Stephen Boyd @ 2024-08-15  0:37 UTC (permalink / raw)
  To: Andy Shevchenko, linux-arm-kernel, linux-clk, linux-kernel
  Cc: Michael Turquette, Nobuhiro Iwamatsu

Quoting Andy Shevchenko (2024-08-14 05:54:08)
> Let the kmemdup_array() take care about multiplication and possible
> overflows.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---

Applied to clk-next

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

end of thread, other threads:[~2024-08-15  0:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-14 12:54 [PATCH v2 0/2] clk: Switch to use kmemdup_array() Andy Shevchenko
2024-08-14 12:54 ` [PATCH v2 1/2] clk: mmp: " Andy Shevchenko
2024-08-15  0:37   ` Stephen Boyd
2024-08-14 12:54 ` [PATCH v2 2/2] clk: visconti: " Andy Shevchenko
2024-08-15  0:37   ` Stephen Boyd

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox