All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Heiko Stübner" <heiko@sntech.de>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Sam Protsenko <semen.protsenko@linaro.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>,
	linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-rockchip@lists.infradead.org,
	linux-samsung-soc@vger.kernel.org,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Michael Turquette <mturquette@baylibre.com>,
	Stephen Boyd <sboyd@kernel.org>,
	Krzysztof Kozlowski <krzk@kernel.org>,
	Sylwester Nawrocki <s.nawrocki@samsung.com>,
	Chanwoo Choi <cw00.choi@samsung.com>,
	Alim Akhtar <alim.akhtar@samsung.com>,
	Nobuhiro Iwamatsu <nobuhiro1.iwamatsu@toshiba.co.jp>
Subject: Re: [PATCH v1 2/4] clk: rockchip: Switch to use kmemdup_array()
Date: Fri, 07 Jun 2024 10:13:04 +0200	[thread overview]
Message-ID: <8182279.JRmrKFJ9eK@diego> (raw)
In-Reply-To: <20240606161028.2986587-3-andriy.shevchenko@linux.intel.com>

Hi Andy,

Am Donnerstag, 6. Juni 2024, 18:09:32 CEST schrieb Andy Shevchenko:
> Let the kememdup_array() take care about multiplication and possible
> overflows.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/clk/rockchip/clk-cpu.c | 5 ++---
>  drivers/clk/rockchip/clk-pll.c | 8 ++++----
>  2 files changed, 6 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/clk/rockchip/clk-cpu.c b/drivers/clk/rockchip/clk-cpu.c
> index 6ea7fba9f9e5..398a226ad34e 100644
> --- a/drivers/clk/rockchip/clk-cpu.c
> +++ b/drivers/clk/rockchip/clk-cpu.c
> @@ -369,9 +369,8 @@ struct clk *rockchip_clk_register_cpuclk(const char *name,
>  
>  	if (nrates > 0) {
>  		cpuclk->rate_count = nrates;
> -		cpuclk->rate_table = kmemdup(rates,
> -					     sizeof(*rates) * nrates,
> -					     GFP_KERNEL);
> +		cpuclk->rate_table = kmemdup_array(rates, nrates, sizeof(*rates),
> +						   GFP_KERNEL);

are you sure the param order is correct?

According to [0], it's (src, element_size, count, gfp), while above
(and below) element_size and count seems switched in the
kmemdup_array calls.


Heiko

[0] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/mm/util.c#n149

>  		if (!cpuclk->rate_table) {
>  			ret = -ENOMEM;
>  			goto unregister_notifier;
> diff --git a/drivers/clk/rockchip/clk-pll.c b/drivers/clk/rockchip/clk-pll.c
> index 2d42eb628926..606ce5458f54 100644
> --- a/drivers/clk/rockchip/clk-pll.c
> +++ b/drivers/clk/rockchip/clk-pll.c
> @@ -1136,10 +1136,10 @@ struct clk *rockchip_clk_register_pll(struct rockchip_clk_provider *ctx,
>  			len++;
>  
>  		pll->rate_count = len;
> -		pll->rate_table = kmemdup(rate_table,
> -					pll->rate_count *
> -					sizeof(struct rockchip_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);
> 





WARNING: multiple messages have this Message-ID (diff)
From: "Heiko Stübner" <heiko@sntech.de>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Sam Protsenko <semen.protsenko@linaro.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>,
	linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-rockchip@lists.infradead.org,
	linux-samsung-soc@vger.kernel.org,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Michael Turquette <mturquette@baylibre.com>,
	Stephen Boyd <sboyd@kernel.org>,
	Krzysztof Kozlowski <krzk@kernel.org>,
	Sylwester Nawrocki <s.nawrocki@samsung.com>,
	Chanwoo Choi <cw00.choi@samsung.com>,
	Alim Akhtar <alim.akhtar@samsung.com>,
	Nobuhiro Iwamatsu <nobuhiro1.iwamatsu@toshiba.co.jp>
Subject: Re: [PATCH v1 2/4] clk: rockchip: Switch to use kmemdup_array()
Date: Fri, 07 Jun 2024 10:13:04 +0200	[thread overview]
Message-ID: <8182279.JRmrKFJ9eK@diego> (raw)
In-Reply-To: <20240606161028.2986587-3-andriy.shevchenko@linux.intel.com>

Hi Andy,

Am Donnerstag, 6. Juni 2024, 18:09:32 CEST schrieb Andy Shevchenko:
> Let the kememdup_array() take care about multiplication and possible
> overflows.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/clk/rockchip/clk-cpu.c | 5 ++---
>  drivers/clk/rockchip/clk-pll.c | 8 ++++----
>  2 files changed, 6 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/clk/rockchip/clk-cpu.c b/drivers/clk/rockchip/clk-cpu.c
> index 6ea7fba9f9e5..398a226ad34e 100644
> --- a/drivers/clk/rockchip/clk-cpu.c
> +++ b/drivers/clk/rockchip/clk-cpu.c
> @@ -369,9 +369,8 @@ struct clk *rockchip_clk_register_cpuclk(const char *name,
>  
>  	if (nrates > 0) {
>  		cpuclk->rate_count = nrates;
> -		cpuclk->rate_table = kmemdup(rates,
> -					     sizeof(*rates) * nrates,
> -					     GFP_KERNEL);
> +		cpuclk->rate_table = kmemdup_array(rates, nrates, sizeof(*rates),
> +						   GFP_KERNEL);

are you sure the param order is correct?

According to [0], it's (src, element_size, count, gfp), while above
(and below) element_size and count seems switched in the
kmemdup_array calls.


Heiko

[0] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/mm/util.c#n149

>  		if (!cpuclk->rate_table) {
>  			ret = -ENOMEM;
>  			goto unregister_notifier;
> diff --git a/drivers/clk/rockchip/clk-pll.c b/drivers/clk/rockchip/clk-pll.c
> index 2d42eb628926..606ce5458f54 100644
> --- a/drivers/clk/rockchip/clk-pll.c
> +++ b/drivers/clk/rockchip/clk-pll.c
> @@ -1136,10 +1136,10 @@ struct clk *rockchip_clk_register_pll(struct rockchip_clk_provider *ctx,
>  			len++;
>  
>  		pll->rate_count = len;
> -		pll->rate_table = kmemdup(rate_table,
> -					pll->rate_count *
> -					sizeof(struct rockchip_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);
> 





_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip

WARNING: multiple messages have this Message-ID (diff)
From: "Heiko Stübner" <heiko@sntech.de>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Sam Protsenko <semen.protsenko@linaro.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>,
	linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-rockchip@lists.infradead.org,
	linux-samsung-soc@vger.kernel.org,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Michael Turquette <mturquette@baylibre.com>,
	Stephen Boyd <sboyd@kernel.org>,
	Krzysztof Kozlowski <krzk@kernel.org>,
	Sylwester Nawrocki <s.nawrocki@samsung.com>,
	Chanwoo Choi <cw00.choi@samsung.com>,
	Alim Akhtar <alim.akhtar@samsung.com>,
	Nobuhiro Iwamatsu <nobuhiro1.iwamatsu@toshiba.co.jp>
Subject: Re: [PATCH v1 2/4] clk: rockchip: Switch to use kmemdup_array()
Date: Fri, 07 Jun 2024 10:13:04 +0200	[thread overview]
Message-ID: <8182279.JRmrKFJ9eK@diego> (raw)
In-Reply-To: <20240606161028.2986587-3-andriy.shevchenko@linux.intel.com>

Hi Andy,

Am Donnerstag, 6. Juni 2024, 18:09:32 CEST schrieb Andy Shevchenko:
> Let the kememdup_array() take care about multiplication and possible
> overflows.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/clk/rockchip/clk-cpu.c | 5 ++---
>  drivers/clk/rockchip/clk-pll.c | 8 ++++----
>  2 files changed, 6 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/clk/rockchip/clk-cpu.c b/drivers/clk/rockchip/clk-cpu.c
> index 6ea7fba9f9e5..398a226ad34e 100644
> --- a/drivers/clk/rockchip/clk-cpu.c
> +++ b/drivers/clk/rockchip/clk-cpu.c
> @@ -369,9 +369,8 @@ struct clk *rockchip_clk_register_cpuclk(const char *name,
>  
>  	if (nrates > 0) {
>  		cpuclk->rate_count = nrates;
> -		cpuclk->rate_table = kmemdup(rates,
> -					     sizeof(*rates) * nrates,
> -					     GFP_KERNEL);
> +		cpuclk->rate_table = kmemdup_array(rates, nrates, sizeof(*rates),
> +						   GFP_KERNEL);

are you sure the param order is correct?

According to [0], it's (src, element_size, count, gfp), while above
(and below) element_size and count seems switched in the
kmemdup_array calls.


Heiko

[0] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/mm/util.c#n149

>  		if (!cpuclk->rate_table) {
>  			ret = -ENOMEM;
>  			goto unregister_notifier;
> diff --git a/drivers/clk/rockchip/clk-pll.c b/drivers/clk/rockchip/clk-pll.c
> index 2d42eb628926..606ce5458f54 100644
> --- a/drivers/clk/rockchip/clk-pll.c
> +++ b/drivers/clk/rockchip/clk-pll.c
> @@ -1136,10 +1136,10 @@ struct clk *rockchip_clk_register_pll(struct rockchip_clk_provider *ctx,
>  			len++;
>  
>  		pll->rate_count = len;
> -		pll->rate_table = kmemdup(rate_table,
> -					pll->rate_count *
> -					sizeof(struct rockchip_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);
> 





_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2024-06-07  8:13 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-06 16:09 [PATCH v1 0/4] clk: Switch to use kmemdup_array() Andy Shevchenko
2024-06-06 16:09 ` Andy Shevchenko
2024-06-06 16:09 ` Andy Shevchenko
2024-06-06 16:09 ` [PATCH v1 1/4] clk: mmp: " Andy Shevchenko
2024-06-06 16:09   ` Andy Shevchenko
2024-06-06 16:09   ` Andy Shevchenko
2024-06-06 16:09 ` [PATCH v1 2/4] clk: rockchip: " Andy Shevchenko
2024-06-06 16:09   ` Andy Shevchenko
2024-06-06 16:09   ` Andy Shevchenko
2024-06-07  8:13   ` Heiko Stübner [this message]
2024-06-07  8:13     ` Heiko Stübner
2024-06-07  8:13     ` Heiko Stübner
2024-06-11 13:20     ` Andy Shevchenko
2024-06-11 13:20       ` Andy Shevchenko
2024-06-11 13:20       ` Andy Shevchenko
2024-06-16  8:00       ` Heiko Stuebner
2024-06-16  8:00         ` Heiko Stuebner
2024-06-06 16:09 ` [PATCH v1 3/4] clk: samsung: " Andy Shevchenko
2024-06-06 16:09   ` Andy Shevchenko
2024-06-06 16:09   ` Andy Shevchenko
2024-06-16  7:24   ` (subset) " Krzysztof Kozlowski
2024-06-16  7:24     ` Krzysztof Kozlowski
2024-06-06 16:09 ` [PATCH v1 4/4] clk: visconti: " Andy Shevchenko
2024-06-06 16:09   ` Andy Shevchenko
2024-06-06 16:09   ` Andy Shevchenko
2024-06-16  7:59 ` (subset) [PATCH v1 0/4] clk: " Heiko Stuebner
2024-06-16  7:59   ` Heiko Stuebner
2024-08-13  8:37 ` Andy Shevchenko
2024-08-13  8:37   ` Andy Shevchenko
2024-08-14  0:01   ` Stephen Boyd
2024-08-14  0:01     ` Stephen Boyd
2024-08-14 12:55     ` Andy Shevchenko
2024-08-14 12:55       ` Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8182279.JRmrKFJ9eK@diego \
    --to=heiko@sntech.de \
    --cc=alim.akhtar@samsung.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=cw00.choi@samsung.com \
    --cc=krzk@kernel.org \
    --cc=krzysztof.kozlowski@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=linux-samsung-soc@vger.kernel.org \
    --cc=mturquette@baylibre.com \
    --cc=nobuhiro1.iwamatsu@toshiba.co.jp \
    --cc=s.nawrocki@samsung.com \
    --cc=sboyd@kernel.org \
    --cc=semen.protsenko@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.