Skip to content

Commit 90af273

Browse files
GustavoARSilvapeda-r
authored andcommitted
i2c: mux: pinctrl: use flexible-array member and struct_size() helper
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>
1 parent d9a183b commit 90af273

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

drivers/i2c/muxes/i2c-mux-pinctrl.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
struct i2c_mux_pinctrl {
2929
struct pinctrl *pinctrl;
30-
struct pinctrl_state **states;
30+
struct pinctrl_state *states[];
3131
};
3232

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

106106
muxc = i2c_mux_alloc(parent, dev, num_names,
107-
sizeof(*mux) + num_names * sizeof(*mux->states),
107+
struct_size(mux, states, num_names),
108108
0, i2c_mux_pinctrl_select, NULL);
109109
if (!muxc) {
110110
ret = -ENOMEM;
111111
goto err_put_parent;
112112
}
113113
mux = i2c_mux_priv(muxc);
114-
mux->states = (struct pinctrl_state **)(mux + 1);
115114

116115
platform_set_drvdata(pdev, muxc);
117116

0 commit comments

Comments
 (0)