Skip to content

Commit

Permalink
hwspinlock: sprd: Use struct_size() helper in devm_kzalloc()
Browse files Browse the repository at this point in the history
Make use of the struct_size() helper instead of an open-coded version,
in order to avoid any potential type mistakes or integer overflows that,
in the worst scenario, could lead to heap overflows.

Also, address the following sparse warnings:
drivers/hwspinlock/sprd_hwspinlock.c:96:36: warning: using sizeof on a flexible structure

Link: KSPP#174
Signed-off-by: Gustavo A. R. Silva <[email protected]>
Reviewed-by: Baolin Wang <[email protected]>
Signed-off-by: Bjorn Andersson <[email protected]>
Link: https://lore.kernel.org/r/20220125225723.GA78256@embeddedor
  • Loading branch information
GustavoARSilva authored and andersson committed Mar 11, 2022
1 parent 3e5f1ff commit 9a41358
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions drivers/hwspinlock/sprd_hwspinlock.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ static int sprd_hwspinlock_probe(struct platform_device *pdev)
return -ENODEV;

sprd_hwlock = devm_kzalloc(&pdev->dev,
sizeof(struct sprd_hwspinlock_dev) +
SPRD_HWLOCKS_NUM * sizeof(*lock),
struct_size(sprd_hwlock, bank.lock, SPRD_HWLOCKS_NUM),
GFP_KERNEL);
if (!sprd_hwlock)
return -ENOMEM;
Expand Down

0 comments on commit 9a41358

Please sign in to comment.