clk: keystone: sci-clk: fix application of sizeof to pointer
Subsystems (3)
Nishanth Menon
maintainerPATCH 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
@@ -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
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 'structsci_clk**', so sizeof(clk) issizeof(struct sci_clk **)which is the size of a pointer rather than the size of an array element.provider->clocksis an array of 'structsci_clk*', so the canonical size argument tobsearch()issizeof(*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
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]>Reviewed-by Stepan Ionichev <[email protected]>Reviewed-by Andrew Davis <[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]>
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 'structsci_clk**', so sizeof(clk) issizeof(struct sci_clk **)which is the size of a pointer rather than the size of an array element.provider->clocksis an array of 'structsci_clk*', so the canonical size argument tobsearch()issizeof(*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