Skip to content

Commit 3053256

Browse files
GustavoARSilvajonmason
authored andcommitted
NTB/msi: 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 or integer overflows that, in the worst scenario, could lead to heap overflows. Also, address the following sparse warnings: drivers/ntb/msi.c:46:23: warning: using sizeof on a flexible structure Link: KSPP/linux#174 Signed-off-by: Gustavo A. R. Silva <[email protected]> Reviewed-by: Kees Cook <[email protected]> Reviewed-by: Logan Gunthorpe <[email protected]> Signed-off-by: Jon Mason <[email protected]>
1 parent e783362 commit 3053256

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

drivers/ntb/msi.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ int ntb_msi_init(struct ntb_dev *ntb,
3333
{
3434
phys_addr_t mw_phys_addr;
3535
resource_size_t mw_size;
36-
size_t struct_size;
3736
int peer_widx;
3837
int peers;
3938
int ret;
@@ -43,9 +42,8 @@ int ntb_msi_init(struct ntb_dev *ntb,
4342
if (peers <= 0)
4443
return -EINVAL;
4544

46-
struct_size = sizeof(*ntb->msi) + sizeof(*ntb->msi->peer_mws) * peers;
47-
48-
ntb->msi = devm_kzalloc(&ntb->dev, struct_size, GFP_KERNEL);
45+
ntb->msi = devm_kzalloc(&ntb->dev, struct_size(ntb->msi, peer_mws, peers),
46+
GFP_KERNEL);
4947
if (!ntb->msi)
5048
return -ENOMEM;
5149

0 commit comments

Comments
 (0)