Skip to content

Commit 86f8a1e

Browse files
keeswsakernel
authored andcommitted
i2c: mux: demux-pinctrl: Annotate struct i2c_demux_pinctrl_priv with __counted_by
Prepare for the coming implementation by GCC and Clang of the __counted_by attribute. Flexible array members annotated with __counted_by can have their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions). As found with Coccinelle[1], add __counted_by for struct i2c_demux_pinctrl_priv. Additionally, since the element count member must be set before accessing the annotated flexible array member, move its initialization earlier. [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci Signed-off-by: Kees Cook <keescook@chromium.org> Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org> [wsa: improved blank lines] Signed-off-by: Wolfram Sang <wsa@kernel.org>
1 parent 6591771 commit 86f8a1e

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct i2c_demux_pinctrl_priv {
3232
const char *bus_name;
3333
struct i2c_adapter cur_adap;
3434
struct i2c_algorithm algo;
35-
struct i2c_demux_pinctrl_chan chan[];
35+
struct i2c_demux_pinctrl_chan chan[] __counted_by(num_chan);
3636
};
3737

3838
static int i2c_demux_master_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
@@ -226,6 +226,8 @@ static int i2c_demux_pinctrl_probe(struct platform_device *pdev)
226226
if (!priv || !props)
227227
return -ENOMEM;
228228

229+
priv->num_chan = num_chan;
230+
229231
err = of_property_read_string(np, "i2c-bus-name", &priv->bus_name);
230232
if (err)
231233
return err;
@@ -249,9 +251,7 @@ static int i2c_demux_pinctrl_probe(struct platform_device *pdev)
249251
of_changeset_update_property(&priv->chan[i].chgset, adap_np, &props[i]);
250252
}
251253

252-
priv->num_chan = num_chan;
253254
priv->dev = &pdev->dev;
254-
255255
platform_set_drvdata(pdev, priv);
256256

257257
pm_runtime_no_callbacks(&pdev->dev);

0 commit comments

Comments
 (0)