Skip to contentSkip to conversation

clk: keystone: sci-clk: fix application of sizeof to pointer

PATCH Superseded Nishanth Menon 3 participants 4 messages May 8 – May 9

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Nishanth Menon

author maintainer
#0 lore raw

PATCH 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
index 9d5071223f4c..2fc1f050779b 100644
@@ -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
Reviewed-by on v1 1/1
#1 lore raw
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->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.

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/afa9ac915e189334f048c177f16fe54f
  drivers/clk/keystone/sci-clk.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/keystone/sci-clk.c +1 -1
index 9d5071223f4c..2fc1f050779b 100644
@@ -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);
author maintainer
#2 lore raw

On 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

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

Signature · 4 lines
Regards,
Nishanth Menon
Key (0xDDB5849D1736249D) / Fingerprint: F8A2 8693 54EB 8232 17A3  1A34 DDB5 849D 1736 249D
https://ti.com/opensource
Reviewed-by on v1 1/1
#3 lore raw
In reply to Nishanth Menon

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