diff mbox series

i2c: i801: Fix the i2c-mux gpiod_lookup_table not being properly terminated

Message ID 20201221134225.106728-1-hdegoede@redhat.com
State Accepted
Commit 0b3ea2a06de1f52ea30865e227e109a5fd3b6214
Headers show
Series i2c: i801: Fix the i2c-mux gpiod_lookup_table not being properly terminated | expand

Commit Message

Hans de Goede Dec. 21, 2020, 1:42 p.m. UTC
gpiod_add_lookup_table() expects the gpiod_lookup_table->table passed to
it to be terminated with a zero-ed out entry.

So we need to allocate one more entry then we will use.

Cc: Serge Semin <fancer.lancer@gmail.com>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Andy Shevchenko <andy@infradead.org>
Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
Fixes: d308dfbf62ef ("i2c: mux/i801: Switch to use descriptor passing")
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/i2c/busses/i2c-i801.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Jean Delvare Dec. 21, 2020, 3:12 p.m. UTC | #1
Hi Hans,

On Mon, 21 Dec 2020 14:42:25 +0100, Hans de Goede wrote:
> gpiod_add_lookup_table() expects the gpiod_lookup_table->table passed to
> it to be terminated with a zero-ed out entry.
> 
> So we need to allocate one more entry then we will use.
> 
> Cc: Serge Semin <fancer.lancer@gmail.com>
> Cc: Linus Walleij <linus.walleij@linaro.org>
> Cc: Andy Shevchenko <andy@infradead.org>
> Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
> Fixes: d308dfbf62ef ("i2c: mux/i801: Switch to use descriptor passing")
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
>  drivers/i2c/busses/i2c-i801.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
> index ae90713443fa..877fe3733a42 100644
> --- a/drivers/i2c/busses/i2c-i801.c
> +++ b/drivers/i2c/busses/i2c-i801.c
> @@ -1449,7 +1449,7 @@ static int i801_add_mux(struct i801_priv *priv)
>  
>  	/* Register GPIO descriptor lookup table */
>  	lookup = devm_kzalloc(dev,
> -			      struct_size(lookup, table, mux_config->n_gpios),
> +			      struct_size(lookup, table, mux_config->n_gpios + 1),
>  			      GFP_KERNEL);
>  	if (!lookup)
>  		return -ENOMEM;

Good catch.

Acked-by: Jean Delvare <jdelvare@suse.de>
Linus Walleij Dec. 27, 2020, 10:41 p.m. UTC | #2
On Mon, Dec 21, 2020 at 2:42 PM Hans de Goede <hdegoede@redhat.com> wrote:

> gpiod_add_lookup_table() expects the gpiod_lookup_table->table passed to

> it to be terminated with a zero-ed out entry.

>

> So we need to allocate one more entry then we will use.

>

> Cc: Serge Semin <fancer.lancer@gmail.com>

> Cc: Linus Walleij <linus.walleij@linaro.org>

> Cc: Andy Shevchenko <andy@infradead.org>

> Cc: Mika Westerberg <mika.westerberg@linux.intel.com>

> Fixes: d308dfbf62ef ("i2c: mux/i801: Switch to use descriptor passing")

> Signed-off-by: Hans de Goede <hdegoede@redhat.com>


Reviewed-by: Linus Walleij <linus.walleij@linaro.org>


Yours,
Linus Walleij
Wolfram Sang Jan. 4, 2021, 6:26 p.m. UTC | #3
On Mon, Dec 21, 2020 at 02:42:25PM +0100, Hans de Goede wrote:
> gpiod_add_lookup_table() expects the gpiod_lookup_table->table passed to

> it to be terminated with a zero-ed out entry.

> 

> So we need to allocate one more entry then we will use.

> 

> Cc: Serge Semin <fancer.lancer@gmail.com>

> Cc: Linus Walleij <linus.walleij@linaro.org>

> Cc: Andy Shevchenko <andy@infradead.org>

> Cc: Mika Westerberg <mika.westerberg@linux.intel.com>

> Fixes: d308dfbf62ef ("i2c: mux/i801: Switch to use descriptor passing")

> Signed-off-by: Hans de Goede <hdegoede@redhat.com>


Applied to for-current, thanks!
diff mbox series

Patch

diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index ae90713443fa..877fe3733a42 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -1449,7 +1449,7 @@  static int i801_add_mux(struct i801_priv *priv)
 
 	/* Register GPIO descriptor lookup table */
 	lookup = devm_kzalloc(dev,
-			      struct_size(lookup, table, mux_config->n_gpios),
+			      struct_size(lookup, table, mux_config->n_gpios + 1),
 			      GFP_KERNEL);
 	if (!lookup)
 		return -ENOMEM;