Skip to contentSkip to conversation

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

PATCH Applied Nishanth Menon 2 participants 3 messages May 12 – Jun 4

Subsystems (3)
lore
Share & tools
lore

Nishanth Menon

author maintainer
#0 lore raw

PATCH v2 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

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.

---
Changes in V2:
- Picked up Stepan's suggestion on commit message
- Picked up Andrew and Stepan's reviewed-by
V1: https://lore.kernel.org/all/[email protected]/

 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.32.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 18 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

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.

Quoted 12 lines
author maintainer Applied
#2 lore raw
In reply to Nishanth Menon

Hi Nishanth Menon,

Quoted 5 lines · Nishanth Menon

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

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

Quoted 7 lines

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 *)).

[...]

I have applied the following to branch ti-k3-sci-clk-next on [1]. Thank you!

[1/1] clk: keystone: sci-clk: fix application of sizeof to pointer

      commit: 2b0123e4a9257fa2933d13d1bca9ac36467efac1

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent up the chain during the next merge window (or sooner if it is a relevant bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/ti/linux.git

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