Re: [PATCH v5 2/2] gpio: add gpio-line-mux driver
From: Linus Walleij
Date: Mon Nov 10 2025 - 17:52:52 EST
Hi Jonas,
overall I'm really happy of how this has turned out!
Sorry for not reviewing very intensely the last two weeks :(
One review comment left:
On Wed, Nov 5, 2025 at 5:36 PM Jonas Jelonek <jelonek.jonas@xxxxxxxxx> wrote:
> +struct gpio_lmux {
> + struct gpio_chip gc;
> + struct mux_control *mux;
> +
> + struct gpio_desc *muxed_gpio;
> + /* dynamically sized, must be last */
> + unsigned int gpio_mux_states[];
> +};
Dynamic arrays at the end of struct is a bit of a security pain
and we probably want to avoid them if we can.
The typical idiom should be:
...
u32 num_gpio_mux_states;
unsigned int gpio_mux_states[] __counted_by(num_gpio_mux_states);
};
> +static int gpio_lmux_probe(struct platform_device *pdev)
> +{
(...)
> + ngpio = device_property_count_u32(dev, "gpio-line-mux-states");
> + if (!ngpio)
> + return -EINVAL;
> +
> + size = struct_size(glm, gpio_mux_states, ngpio);
> + glm = devm_kzalloc(dev, size, GFP_KERNEL);
> + if (!glm)
> + return -ENOMEM;
(...)
glm->num_gpio_mux_states = ngpio;
> + ret = device_property_read_u32_array(dev, "gpio-line-mux-states",
> + &glm->gpio_mux_states[0], ngpio);
> + if (ret)
> + return dev_err_probe(dev, ret, "could not get mux states\n");
We use this pattern in the core gpiolib for example.
With this addressed:
Reviewed-by: Linus Walleij <linus.walleij@xxxxxxxxxx>
Yours,
Linus Walleij