Skip to content

Commit b8e2c8b

Browse files
GustavoARSilvajonmason
authored andcommitted
NTB: Use struct_size() helper in devm_kzalloc()
Make use of the struct_size() helper instead of an open-coded version in order to avoid any potential type mistakes. Also, remove unnecessary variable _struct_size_. This code was detected with the help of Coccinelle and, audited and fixed manually. Addresses-KSPP-ID: KSPP#83 Signed-off-by: Gustavo A. R. Silva <[email protected]> Reviewed-by: Logan Gunthorpe <[email protected]> Signed-off-by: Jon Mason <[email protected]>
1 parent dbb8df5 commit b8e2c8b

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

drivers/ntb/test/ntb_msi_test.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,6 @@ static void ntb_msit_remove_dbgfs(struct ntb_msit_ctx *nm)
319319
static int ntb_msit_probe(struct ntb_client *client, struct ntb_dev *ntb)
320320
{
321321
struct ntb_msit_ctx *nm;
322-
size_t struct_size;
323322
int peers;
324323
int ret;
325324

@@ -352,9 +351,7 @@ static int ntb_msit_probe(struct ntb_client *client, struct ntb_dev *ntb)
352351
return ret;
353352
}
354353

355-
struct_size = sizeof(*nm) + sizeof(*nm->peers) * peers;
356-
357-
nm = devm_kzalloc(&ntb->dev, struct_size, GFP_KERNEL);
354+
nm = devm_kzalloc(&ntb->dev, struct_size(nm, peers, peers), GFP_KERNEL);
358355
if (!nm)
359356
return -ENOMEM;
360357

0 commit comments

Comments
 (0)