clk: keystone: sci-clk: fix application of sizeof to pointer
Subsystems (3)
Nishanth Menon
maintainerPATCH 1/1 clk: keystone: sci-clk: fix application of sizeof to pointer
From: Jing Yangyang <[email protected]>
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.
---
Cc: Jing Yangyang <[email protected]>
Cc: Ran Sun <[email protected]>
- 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(-)
drivers/clk/keystone/sci-clk.c +1 -1
@@ -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 );
Signature · 1 line
2.47.0
Quoted 23 lines · Nishanth Menon
From: Jing Yangyang <[email protected]>
Coccinelle (
scripts/coccinelle/misc/noderef.cocci) reports:drivers/clk/keystone/sci-clk.c:391:8-14: ERROR: application of sizeof to pointer
provider->clocksis an array of structsci_clk*, sobsearch()expects the size of each element (structsci_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 <[email protected]>Closes https://lore.kernel.org/all/84a6ba16686347099a3dab2e5161a930e792eb6e.1629198281.git.jing.yangyang@zte.com.cn/ open hereReported-by kernel test robot <[email protected]>Reported-by Julia Lawall <[email protected]>Signed-off-by Jing Yangyang <[email protected]>Signed-off-by David Yang <[email protected]>[[email protected]: Improved commit message]Signed-off-by Nishanth Menon <[email protected]>
Quoted 5 lines
---
Cc: Jing Yangyang <[email protected]>
Cc: Ran Sun <[email protected]>- 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,
Quoted 25 lines
- 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/afa9ac915e189334f048c177f16fe54fdrivers/clk/keystone/sci-clk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/clk/keystone/sci-clk.c +1
-1@@ -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 );
Nishanth Menon
maintainerOn 11:59-20260508, Andrew Davis wrote:
[...]
Quoted 5 lines
Quoted 1 line
- 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.
Quoted 1 line
correct and silence a Coccinelle warning. Anyway,
Yep, That is all this is.. patches keep popping up every few years.
Quoted 3 lines
Reviewed-by Andrew Davis <[email protected]>
Signature · 4 lines
Regards, Nishanth Menon Key (0xDDB5849D1736249D) / Fingerprint: F8A2 8693 54EB 8232 17A3 1A34 DDB5 849D 1736 249D https://ti.com/opensource
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.
Stepan