Skip to content

Commit b7af938

Browse files
Dan Carpenterwsakernel
authored andcommitted
i2c: mux: harden i2c_mux_alloc() against integer overflows
A couple years back we went through the kernel an automatically converted size calculations to use struct_size() instead. The struct_size() calculation is protected against integer overflows. However it does not make sense to use the result from struct_size() for additional math operations as that would negate any safeness. Fixes: 1f3b69b ("i2c: mux: Use struct_size() in devm_kzalloc()") Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Acked-by: Peter Rosin <peda@axentia.se> Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org> Signed-off-by: Wolfram Sang <wsa@kernel.org>
1 parent 37f071e commit b7af938

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

drivers/i2c/i2c-mux.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,10 @@ struct i2c_mux_core *i2c_mux_alloc(struct i2c_adapter *parent,
243243
int (*deselect)(struct i2c_mux_core *, u32))
244244
{
245245
struct i2c_mux_core *muxc;
246+
size_t mux_size;
246247

247-
muxc = devm_kzalloc(dev, struct_size(muxc, adapter, max_adapters)
248-
+ sizeof_priv, GFP_KERNEL);
248+
mux_size = struct_size(muxc, adapter, max_adapters);
249+
muxc = devm_kzalloc(dev, size_add(mux_size, sizeof_priv), GFP_KERNEL);
249250
if (!muxc)
250251
return NULL;
251252
if (sizeof_priv)

0 commit comments

Comments
 (0)