usb: typec: anx7411: Fix an array out of bounds
Subsystems (3)
PATCH 1/3 usb: typec: anx7411: Fix an array out of bounds
This should be ARRAY_SIZE() instead of sizeof(). ARRAY_SIZE is 4 and sizeof is 8.
--- drivers/usb/typec/anx7411.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/typec/anx7411.c +1 -1
@@ -992,7 +992,7 @@ static int anx7411_register_i2c_dummy_clients(struct anx7411_data *ctx,int i;u8 spi_addr; -for (i =0 ; i <sizeof (anx7411_i2c_addr); i++) { +for (i =0 ; i <ARRAY_SIZE (anx7411_i2c_addr); i++) {if (client->addr == (anx7411_i2c_addr[i].tcpc_address >>1 )) { spi_addr = anx7411_i2c_addr[i].spi_address >>1 ; ctx->spi_client = i2c_new_dummy_device(client->adapter,
Signature · 1 line
2.35.1
PATCH 2/3 usb: typec: anx7411: fix error checking in anx7411_get_gpio_irq()
This is a minor bug which means that certain error messages are not printed.
The devm_gpiod_get_optional() function can return either error pointers or NULL. It returns error pointers if there is an allocation failure, or a similar issue. It returns NULL if no GPIO was assigned to the requested function. Print an error in either case.
The gpiod_to_irq() function never returns zero. It either returns a positive IRQ number or a negative error code.
--- drivers/usb/typec/anx7411.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/typec/anx7411.c +2 -2
@@ -1326,13 +1326,13 @@ static void anx7411_get_gpio_irq(struct anx7411_data *ctx)struct device *dev = &ctx->tcpc_client->dev; ctx->intp_gpiod =devm_gpiod_get_optional (dev,"interrupt" ,GPIOD_IN ); -if (!ctx->intp_gpiod) { +if (IS_ERR_OR_NULL (ctx->intp_gpiod)) {dev_err (dev,"no interrupt gpio property\n" );return ; } ctx->intp_irq =gpiod_to_irq (ctx->intp_gpiod); -if (!ctx->intp_irq) +if (ctx->intp_irq <0 )dev_err (dev,"failed to get GPIO IRQ\n" ); }
Signature · 1 line
2.35.1
Re: [PATCH 2/3] usb: typec: anx7411: fix error checking in anx7411_get_gpio_irq()
Quoted 10 lines · Dan Carpenter
This is a minor bug which means that certain error messages are not printed.
The
devm_gpiod_get_optional()function can return either error pointers or NULL. It returns error pointers if there is an allocation failure, or a similar issue. It returns NULL if no GPIO was assigned to the requested function. Print an error in either case.The
gpiod_to_irq()function never returns zero. It either returns a positive IRQ number or a negative error code.
Hi Dan Carpenter, thanks for your patch.
Thanks,
Xin
Quoted 29 lines
Fixes fe6d8a9c8e64 ("usb: typec: anx7411: Add Analogix PD ANX7411 support")Signed-off-by Dan Carpenter <[email protected]>--- drivers/usb/typec/anx7411.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/usb/typec/anx7411.c +2
-2@@ -1326,13 +1326,13 @@ static void anx7411_get_gpio_irq(struct anx7411_data *ctx)struct device *dev = &ctx->tcpc_client->dev; ctx->intp_gpiod =devm_gpiod_get_optional (dev,"interrupt" ,GPIOD_IN ); -if (!ctx->intp_gpiod) { +if (IS_ERR_OR_NULL (ctx->intp_gpiod)) {dev_err (dev,"no interrupt gpio property\n" );return ; } ctx->intp_irq =gpiod_to_irq (ctx->intp_gpiod); -if (!ctx->intp_irq) +if (ctx->intp_irq <0 )dev_err (dev,"failed to get GPIO IRQ\n" ); }Signature · 1 line
2.35.1
PATCH 3/3 usb: typec: anx7411: use semi-colons instead of commas
In reply to Dan CarpenterSemi colons and commas are equivalent in this context but semi-colons are better style.
--- drivers/usb/typec/anx7411.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/usb/typec/anx7411.c +5 -5
@@ -1421,12 +1421,12 @@ static int anx7411_psy_register(struct anx7411_data *ctx) psy_desc->type =POWER_SUPPLY_TYPE_USB ; psy_desc->usb_types = anx7411_psy_usb_types; psy_desc->num_usb_types =ARRAY_SIZE (anx7411_psy_usb_types); - psy_desc->properties = anx7411_psy_props, - psy_desc->num_properties =ARRAY_SIZE (anx7411_psy_props), + psy_desc->properties = anx7411_psy_props; + psy_desc->num_properties =ARRAY_SIZE (anx7411_psy_props); - psy_desc->get_property = anx7411_psy_get_prop, - psy_desc->set_property = anx7411_psy_set_prop, - psy_desc->property_is_writeable = anx7411_psy_prop_writeable, + psy_desc->get_property = anx7411_psy_get_prop; + psy_desc->set_property = anx7411_psy_set_prop; + psy_desc->property_is_writeable = anx7411_psy_prop_writeable; ctx->usb_type =POWER_SUPPLY_USB_TYPE_C ; ctx->psy =devm_power_supply_register (ctx->dev, psy_desc, &psy_cfg);
Signature · 1 line
2.35.1
Re: [PATCH 3/3] usb: typec: anx7411: use semi-colons instead of commas
Quoted 2 lines · Dan Carpenter
Semi colons and commas are equivalent in this context but semi-colons are better style.
Hi Dan Carpenter, thanks for your patch.
Thanks,
Xin
Quoted 30 lines
Signed-off-by Dan Carpenter <[email protected]>--- drivers/usb/typec/anx7411.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)drivers/usb/typec/anx7411.c +5
-5@@ -1421,12 +1421,12 @@ static int anx7411_psy_register(struct anx7411_data *ctx) psy_desc->type =POWER_SUPPLY_TYPE_USB ; psy_desc->usb_types = anx7411_psy_usb_types; psy_desc->num_usb_types =ARRAY_SIZE (anx7411_psy_usb_types); - psy_desc->properties = anx7411_psy_props, - psy_desc->num_properties =ARRAY_SIZE (anx7411_psy_props), + psy_desc->properties = anx7411_psy_props; + psy_desc->num_properties =ARRAY_SIZE (anx7411_psy_props); - psy_desc->get_property = anx7411_psy_get_prop, - psy_desc->set_property = anx7411_psy_set_prop, - psy_desc->property_is_writeable = anx7411_psy_prop_writeable, + psy_desc->get_property = anx7411_psy_get_prop; + psy_desc->set_property = anx7411_psy_set_prop; + psy_desc->property_is_writeable = anx7411_psy_prop_writeable; ctx->usb_type =POWER_SUPPLY_USB_TYPE_C ; ctx->psy =devm_power_supply_register (ctx->dev, psy_desc, &psy_cfg);Signature · 1 line
2.35.1
Quoted 2 lines · Dan Carpenter
This should be
ARRAY_SIZE()instead ofsizeof().ARRAY_SIZEis 4 and sizeof is 8.
Hi Dan Carpenter, thanks for your patch.
Thanks,
Xi
Quoted 22 lines
Fixes fe6d8a9c8e64 ("usb: typec: anx7411: Add Analogix PD ANX7411 support")Signed-off-by Dan Carpenter <[email protected]>--- drivers/usb/typec/anx7411.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/usb/typec/anx7411.c +1
-1@@ -992,7 +992,7 @@ static int anx7411_register_i2c_dummy_clients(struct anx7411_data *ctx,int i;u8 spi_addr; -for (i =0 ; i <sizeof (anx7411_i2c_addr); i++) { +for (i =0 ; i <ARRAY_SIZE (anx7411_i2c_addr); i++) {if (client->addr == (anx7411_i2c_addr[i].tcpc_address >>1 )) { spi_addr = anx7411_i2c_addr[i].spi_address >>1 ; ctx->spi_client = i2c_new_dummy_device(client->adapter,Signature · 1 line
2.35.1