]> git.itanic.dy.fi Git - linux-stable/blobdiff - drivers/i2c/i2c-mux.c
i2c: mux: harden i2c_mux_alloc() against integer overflows
[linux-stable] / drivers / i2c / i2c-mux.c
index 774507b54b57b7e722ee77fa1e8952fb29b30b1c..313904be5f3bde25990ffb631c248e60aa94bb09 100644 (file)
@@ -243,9 +243,10 @@ struct i2c_mux_core *i2c_mux_alloc(struct i2c_adapter *parent,
                                   int (*deselect)(struct i2c_mux_core *, u32))
 {
        struct i2c_mux_core *muxc;
+       size_t mux_size;
 
-       muxc = devm_kzalloc(dev, struct_size(muxc, adapter, max_adapters)
-                           + sizeof_priv, GFP_KERNEL);
+       mux_size = struct_size(muxc, adapter, max_adapters);
+       muxc = devm_kzalloc(dev, size_add(mux_size, sizeof_priv), GFP_KERNEL);
        if (!muxc)
                return NULL;
        if (sizeof_priv)