Skip to content

Commit

Permalink
i2c: mux: pinctrl: use flexible-array member and struct_size() helper
Browse files Browse the repository at this point in the history
Update the code to use a flexible array member instead of a pointer in
structure i2c_mux_pinctrl and use the struct_size() helper.

Also, 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(*mux) + num_names * sizeof(*mux->states)

with:

struct_size(mux, states, num_names)

This code was detected with the help of Coccinelle.

Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Signed-off-by: Peter Rosin <peda@axentia.se>
  • Loading branch information
Gustavo A. R. Silva authored and Peter Rosin committed Jun 10, 2019
1 parent d9a183b commit 90af273
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions drivers/i2c/muxes/i2c-mux-pinctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

struct i2c_mux_pinctrl {
struct pinctrl *pinctrl;
struct pinctrl_state **states;
struct pinctrl_state *states[];
};

static int i2c_mux_pinctrl_select(struct i2c_mux_core *muxc, u32 chan)
Expand Down Expand Up @@ -104,14 +104,13 @@ static int i2c_mux_pinctrl_probe(struct platform_device *pdev)
return PTR_ERR(parent);

muxc = i2c_mux_alloc(parent, dev, num_names,
sizeof(*mux) + num_names * sizeof(*mux->states),
struct_size(mux, states, num_names),
0, i2c_mux_pinctrl_select, NULL);
if (!muxc) {
ret = -ENOMEM;
goto err_put_parent;
}
mux = i2c_mux_priv(muxc);
mux->states = (struct pinctrl_state **)(mux + 1);

platform_set_drvdata(pdev, muxc);

Expand Down

0 comments on commit 90af273

Please sign in to comment.