Skip to contentSkip to conversation

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

PATCH Applied Hans de Goede 5 participants 5 messages Dec 21, 2020 – Jan 4, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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

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 <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Mika Westerberg <[email protected]>
Fixes d308dfbf62ef ("i2c: mux/i801: Switch to use descriptor passing")
---
 drivers/i2c/busses/i2c-i801.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-i801.c +1 -1
index ae90713443fa..877fe3733a42 100644
@@ -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;
Signature · 1 line
2.28.0
Acked-by on v1 1/1
#2 lore raw
In reply to Hans de Goede

Hi Hans,

Quoted 20 lines · Hans de Goede

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 <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Mika Westerberg <[email protected]>
Fixes d308dfbf62ef ("i2c: mux/i801: Switch to use descriptor passing")
---
 drivers/i2c/busses/i2c-i801.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-i801.c +0 -0
index ae90713443fa..877fe3733a42 100644

drivers/i2c/busses/i2c-i801.c static int i801_add_mux(struct i801_priv *priv) · line 1455

Quoted 8 lines
drivers/i2c/busses/i2c-i801.c +1 -1
@@ -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.

Signature · 2 lines
Jean Delvare
SUSE L3 Support
Reviewed-by on v1 1/1
#3 lore raw
In reply to Hans de Goede
Quoted 11 lines · Hans de Goede

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 <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Mika Westerberg <[email protected]>
Fixes d308dfbf62ef ("i2c: mux/i801: Switch to use descriptor passing")

Yours,
Linus Walleij

Applied
#4 lore raw
In reply to Hans de Goede
Quoted 11 lines · Hans de Goede

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 <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Mika Westerberg <[email protected]>
Fixes d308dfbf62ef ("i2c: mux/i801: Switch to use descriptor passing")

Applied to for-current, thanks!