Skip to content

Commit

Permalink
i3c: master: Use struct_size() helper
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, in particular in the
context in which this code is being used.

So, replace the following form:

sizeof(*defslvs) + ((ndevs - 1) * sizeof(struct i3c_ccc_dev_desc))

with:

struct_size(defslvs, slaves, ndevs - 1)

This code was detected with the help of Coccinelle.

Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
  • Loading branch information
Gustavo A. R. Silva authored and Boris Brezillon committed Jul 4, 2019
1 parent ea3bfee commit ede2001
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions drivers/i3c/master.c
Original file line number Diff line number Diff line change
Expand Up @@ -950,9 +950,8 @@ int i3c_master_defslvs_locked(struct i3c_master_controller *master)
ndevs++;

defslvs = i3c_ccc_cmd_dest_init(&dest, I3C_BROADCAST_ADDR,
sizeof(*defslvs) +
((ndevs - 1) *
sizeof(struct i3c_ccc_dev_desc)));
struct_size(defslvs, slaves,
ndevs - 1));
if (!defslvs)
return -ENOMEM;

Expand Down

0 comments on commit ede2001

Please sign in to comment.