Skip to content

Commit

Permalink
platform/x86: i2c-multi-instantiate: Use struct_size() helper
Browse files Browse the repository at this point in the history
One of the more common cases of allocation size calculations is finding
the size of a structure that has a zero-sized array at the end, along
with memory for some number of elements for that array.

Make use of the struct_size() helper instead of an open-coded version
in order to avoid any potential type mistakes.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
  • Loading branch information
Andy Shevchenko committed Jul 30, 2019
1 parent aaed5c9 commit c03f282
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions drivers/platform/x86/i2c-multi-instantiate.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ static int i2c_multi_inst_probe(struct platform_device *pdev)
if (ret < 0)
return ret;

multi = devm_kmalloc(dev,
offsetof(struct i2c_multi_inst_data, clients[ret]),
GFP_KERNEL);
multi = devm_kmalloc(dev, struct_size(multi, clients, ret), GFP_KERNEL);
if (!multi)
return -ENOMEM;

Expand Down

0 comments on commit c03f282

Please sign in to comment.