The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] clk: keystone: sci-clk: fix application of sizeof to pointer
@ 2026-05-08 15:23 Nishanth Menon
  2026-05-08 16:59 ` Andrew Davis
  2026-05-09 11:34 ` Stepan Ionichev
  0 siblings, 2 replies; 4+ messages in thread
From: Nishanth Menon @ 2026-05-08 15:23 UTC (permalink / raw)
  To: Brian Masney, Stephen Boyd, Michael Turquette, Santosh Shilimkar,
	Tero Kristo, Nishanth Menon
  Cc: linux-clk, linux-kernel, linux-arm-kernel, Jing Yangyang,
	Zeal Robot, kernel test robot, Julia Lawall, David Yang,
	Jing Yangyang, Ran Sun

From: Jing Yangyang <jing.yangyang@zte.com.cn>

Coccinelle (scripts/coccinelle/misc/noderef.cocci) reports:

  drivers/clk/keystone/sci-clk.c:391:8-14: ERROR: application of
  sizeof to pointer

provider->clocks is an array of struct sci_clk *, so bsearch()
expects the size of each element (struct sci_clk *). However,
sizeof(clk) evaluates to the size of a pointer-to-pointer.

Use sizeof(*clk) to pass the correct element size.

Reported-by: Zeal Robot <zealci@zte.com.cn>
Closes: https://lore.kernel.org/all/84a6ba16686347099a3dab2e5161a930e792eb6e.1629198281.git.jing.yangyang@zte.com.cn/
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Julia Lawall <julia.lawall@inria.fr>
Closes: https://lore.kernel.org/all/202512040525.zrHSDl5h-lkp@intel.com/
Link: https://lore.kernel.org/linux-clk/20211012021931.176727-1-davidcomponentone@gmail.com/
Signed-off-by: Jing Yangyang <jing.yangyang@zte.com.cn>
Signed-off-by: David Yang <davidcomponentone@gmail.com>
[nm@ti.com: Improved commit message]
Signed-off-by: Nishanth Menon <nm@ti.com>
---
Cc: Jing Yangyang <cgel.zte@gmail.com>
Cc: Ran Sun <sunran001@208suo.com>

 - Functionality: No impact (on Linux architectures), thus no Fixes/Stable tag.
 - History: This patch has long-standing history; I have attributed it to the
  earliest valid author found during a recent scrub.
 - Reports: Retained chronological attribution even where public reports (Zeal
  Robot) are unavailable.
 - Checkpatch: Acknowledging minor warning regarding tag ordering (Reported-by
  / Closes sequence); chosen to maintain link integrity for automated tools.
 - Testing: Verified on available K3 SoCs against 2026-05-07:
  https://gist.github.com/nmenon/afa9ac915e189334f048c177f16fe54f

 drivers/clk/keystone/sci-clk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/clk/keystone/sci-clk.c b/drivers/clk/keystone/sci-clk.c
index 9d5071223f4c..2fc1f050779b 100644
--- a/drivers/clk/keystone/sci-clk.c
+++ b/drivers/clk/keystone/sci-clk.c
@@ -388,7 +388,7 @@ static struct clk_hw *sci_clk_get(struct of_phandle_args *clkspec, void *data)
 	key.clk_id = clkspec->args[1];
 
 	clk = bsearch(&key, provider->clocks, provider->num_clocks,
-		      sizeof(clk), _cmp_sci_clk);
+		      sizeof(*clk), _cmp_sci_clk);
 
 	if (!clk)
 		return ERR_PTR(-ENODEV);
-- 
2.47.0


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

* Re: [PATCH] clk: keystone: sci-clk: fix application of sizeof to pointer
  2026-05-08 15:23 [PATCH] clk: keystone: sci-clk: fix application of sizeof to pointer Nishanth Menon
@ 2026-05-08 16:59 ` Andrew Davis
  2026-05-08 17:07   ` Nishanth Menon
  2026-05-09 11:34 ` Stepan Ionichev
  1 sibling, 1 reply; 4+ messages in thread
From: Andrew Davis @ 2026-05-08 16:59 UTC (permalink / raw)
  To: Nishanth Menon, Brian Masney, Stephen Boyd, Michael Turquette,
	Santosh Shilimkar, Tero Kristo
  Cc: linux-clk, linux-kernel, linux-arm-kernel, Jing Yangyang,
	Zeal Robot, kernel test robot, Julia Lawall, David Yang,
	Jing Yangyang, Ran Sun

On 5/8/26 10:23 AM, Nishanth Menon wrote:
> From: Jing Yangyang <jing.yangyang@zte.com.cn>
> 
> Coccinelle (scripts/coccinelle/misc/noderef.cocci) reports:
> 
>    drivers/clk/keystone/sci-clk.c:391:8-14: ERROR: application of
>    sizeof to pointer
> 
> provider->clocks is an array of struct sci_clk *, so bsearch()
> expects the size of each element (struct sci_clk *). However,
> sizeof(clk) evaluates to the size of a pointer-to-pointer.
> 
> Use sizeof(*clk) to pass the correct element size.
> 
> Reported-by: Zeal Robot <zealci@zte.com.cn>
> Closes: https://lore.kernel.org/all/84a6ba16686347099a3dab2e5161a930e792eb6e.1629198281.git.jing.yangyang@zte.com.cn/
> Reported-by: kernel test robot <lkp@intel.com>
> Reported-by: Julia Lawall <julia.lawall@inria.fr>
> Closes: https://lore.kernel.org/all/202512040525.zrHSDl5h-lkp@intel.com/
> Link: https://lore.kernel.org/linux-clk/20211012021931.176727-1-davidcomponentone@gmail.com/
> Signed-off-by: Jing Yangyang <jing.yangyang@zte.com.cn>
> Signed-off-by: David Yang <davidcomponentone@gmail.com>
> [nm@ti.com: Improved commit message]
> Signed-off-by: Nishanth Menon <nm@ti.com>
> ---
> Cc: Jing Yangyang <cgel.zte@gmail.com>
> Cc: Ran Sun <sunran001@208suo.com>
> 
>   - Functionality: No impact (on Linux architectures), thus no Fixes/Stable tag.

Not sure what "on Linux architectures" means here, this should be true for any
sane system, right? You are going from the sizeof(pointer-to-pointer) to the
sizeof(pointer), both should be equal. This is just to be more technically
correct and silence a Coccinelle warning. Anyway,

Reviewed-by: Andrew Davis <afd@ti.com>

>   - History: This patch has long-standing history; I have attributed it to the
>    earliest valid author found during a recent scrub.
>   - Reports: Retained chronological attribution even where public reports (Zeal
>    Robot) are unavailable.
>   - Checkpatch: Acknowledging minor warning regarding tag ordering (Reported-by
>    / Closes sequence); chosen to maintain link integrity for automated tools.
>   - Testing: Verified on available K3 SoCs against 2026-05-07:
>    https://gist.github.com/nmenon/afa9ac915e189334f048c177f16fe54f
> 
>   drivers/clk/keystone/sci-clk.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/clk/keystone/sci-clk.c b/drivers/clk/keystone/sci-clk.c
> index 9d5071223f4c..2fc1f050779b 100644
> --- a/drivers/clk/keystone/sci-clk.c
> +++ b/drivers/clk/keystone/sci-clk.c
> @@ -388,7 +388,7 @@ static struct clk_hw *sci_clk_get(struct of_phandle_args *clkspec, void *data)
>   	key.clk_id = clkspec->args[1];
>   
>   	clk = bsearch(&key, provider->clocks, provider->num_clocks,
> -		      sizeof(clk), _cmp_sci_clk);
> +		      sizeof(*clk), _cmp_sci_clk);
>   
>   	if (!clk)
>   		return ERR_PTR(-ENODEV);


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

* Re: [PATCH] clk: keystone: sci-clk: fix application of sizeof to pointer
  2026-05-08 16:59 ` Andrew Davis
@ 2026-05-08 17:07   ` Nishanth Menon
  0 siblings, 0 replies; 4+ messages in thread
From: Nishanth Menon @ 2026-05-08 17:07 UTC (permalink / raw)
  To: Andrew Davis
  Cc: Brian Masney, Stephen Boyd, Michael Turquette, Santosh Shilimkar,
	Tero Kristo, linux-clk, linux-kernel, linux-arm-kernel,
	Jing Yangyang, Zeal Robot, kernel test robot, Julia Lawall,
	David Yang, Jing Yangyang, Ran Sun

On 11:59-20260508, Andrew Davis wrote:

[...]
> >   - Functionality: No impact (on Linux architectures), thus no Fixes/Stable tag.
> 
> Not sure what "on Linux architectures" means here, this should be true for any
> sane system, right? You are going from the sizeof(pointer-to-pointer) to the
> sizeof(pointer), both should be equal. This is just to be more technically

Yep (also why i put it in diffstat notes ;) ) - any sane system
(which is what we support in Linux ;) ) - though C standard does'nt
explicitly call that out from what I could gather, it is practically
what all systems tend to do. i had the extreme paranoia about this
and got claude[1] to check it out using clang.. Results match the
expectation.

> correct and silence a Coccinelle warning. Anyway,

Yep, That is all this is.. patches keep popping up every few years.

> 
> Reviewed-by: Andrew Davis <afd@ti.com>
> 

Thanks.
[1] https://gist.githubusercontent.com/nmenon/afa9ac915e189334f048c177f16fe54f/raw/ccd08843ff7193090f9fbdca3f5c76d0a4366c85/quick%2520check%2520with%2520clang

-- 
Regards,
Nishanth Menon
Key (0xDDB5849D1736249D) / Fingerprint: F8A2 8693 54EB 8232 17A3  1A34 DDB5 849D 1736 249D
https://ti.com/opensource

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

* Re: [PATCH] clk: keystone: sci-clk: fix application of sizeof to pointer
  2026-05-08 15:23 [PATCH] clk: keystone: sci-clk: fix application of sizeof to pointer Nishanth Menon
  2026-05-08 16:59 ` Andrew Davis
@ 2026-05-09 11:34 ` Stepan Ionichev
  1 sibling, 0 replies; 4+ messages in thread
From: Stepan Ionichev @ 2026-05-09 11:34 UTC (permalink / raw)
  To: nm
  Cc: sboyd, mturquette, afd, linux-clk, linux-arm-kernel, linux-kernel,
	sozdayvek

In sci_clk_get(), 'clk' is declared as 'struct sci_clk **', so
sizeof(clk) is sizeof(struct sci_clk **) which is the size of a
pointer rather than the size of an array element. provider->clocks
is an array of 'struct sci_clk *', so the canonical size argument
to bsearch() is sizeof(*clk) (i.e. sizeof(struct sci_clk *)).

The two values are equal on every supported architecture, so this
is correctness/idiom, not a runtime fix, but the new form matches
the rest of the bsearch() callers in the tree and silences the
Coccinelle warning the script flagged.

Reviewed-by: Stepan Ionichev <sozdayvek@gmail.com>

Stepan

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

end of thread, other threads:[~2026-05-09 18:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-08 15:23 [PATCH] clk: keystone: sci-clk: fix application of sizeof to pointer Nishanth Menon
2026-05-08 16:59 ` Andrew Davis
2026-05-08 17:07   ` Nishanth Menon
2026-05-09 11:34 ` Stepan Ionichev

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