* [PATCH 2/3] usb: typec: anx7411: fix error checking in anx7411_get_gpio_irq()
2022-07-22 6:25 [PATCH 1/3] usb: typec: anx7411: Fix an array out of bounds Dan Carpenter
@ 2022-07-22 6:29 ` Dan Carpenter
2022-07-22 7:16 ` Xin Ji
2022-07-22 6:29 ` [PATCH 3/3] usb: typec: anx7411: use semi-colons instead of commas Dan Carpenter
2022-07-22 7:15 ` [PATCH 1/3] usb: typec: anx7411: Fix an array out of bounds Xin Ji
2 siblings, 1 reply; 6+ messages in thread
From: Dan Carpenter @ 2022-07-22 6:29 UTC (permalink / raw)
To: Heikki Krogerus, Xin Ji; +Cc: Greg Kroah-Hartman, linux-usb, kernel-janitors
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.
Fixes: fe6d8a9c8e64 ("usb: typec: anx7411: Add Analogix PD ANX7411 support")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
drivers/usb/typec/anx7411.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/typec/anx7411.c b/drivers/usb/typec/anx7411.c
index 4f7a5cc968d0..311b56aaea9f 100644
--- a/drivers/usb/typec/anx7411.c
+++ b/drivers/usb/typec/anx7411.c
@@ -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");
}
--
2.35.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH 2/3] usb: typec: anx7411: fix error checking in anx7411_get_gpio_irq()
2022-07-22 6:29 ` [PATCH 2/3] usb: typec: anx7411: fix error checking in anx7411_get_gpio_irq() Dan Carpenter
@ 2022-07-22 7:16 ` Xin Ji
0 siblings, 0 replies; 6+ messages in thread
From: Xin Ji @ 2022-07-22 7:16 UTC (permalink / raw)
To: Dan Carpenter
Cc: Heikki Krogerus, Greg Kroah-Hartman, linux-usb, kernel-janitors
On Fri, Jul 22, 2022 at 09:29:07AM +0300, Dan Carpenter wrote:
> 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.
Reviewed-by: Xin Ji <xji@analogixsemi.com>
Thanks,
Xin
>
> Fixes: fe6d8a9c8e64 ("usb: typec: anx7411: Add Analogix PD ANX7411 support")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> drivers/usb/typec/anx7411.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/usb/typec/anx7411.c b/drivers/usb/typec/anx7411.c
> index 4f7a5cc968d0..311b56aaea9f 100644
> --- a/drivers/usb/typec/anx7411.c
> +++ b/drivers/usb/typec/anx7411.c
> @@ -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");
> }
>
> --
> 2.35.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 3/3] usb: typec: anx7411: use semi-colons instead of commas
2022-07-22 6:25 [PATCH 1/3] usb: typec: anx7411: Fix an array out of bounds Dan Carpenter
2022-07-22 6:29 ` [PATCH 2/3] usb: typec: anx7411: fix error checking in anx7411_get_gpio_irq() Dan Carpenter
@ 2022-07-22 6:29 ` Dan Carpenter
2022-07-22 7:17 ` Xin Ji
2022-07-22 7:15 ` [PATCH 1/3] usb: typec: anx7411: Fix an array out of bounds Xin Ji
2 siblings, 1 reply; 6+ messages in thread
From: Dan Carpenter @ 2022-07-22 6:29 UTC (permalink / raw)
To: Xin Ji; +Cc: Heikki Krogerus, Greg Kroah-Hartman, linux-usb, kernel-janitors
Semi colons and commas are equivalent in this context but semi-colons
are better style.
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
drivers/usb/typec/anx7411.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/usb/typec/anx7411.c b/drivers/usb/typec/anx7411.c
index 311b56aaea9f..18a6a6a8b9eb 100644
--- a/drivers/usb/typec/anx7411.c
+++ b/drivers/usb/typec/anx7411.c
@@ -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);
--
2.35.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 3/3] usb: typec: anx7411: use semi-colons instead of commas
2022-07-22 6:29 ` [PATCH 3/3] usb: typec: anx7411: use semi-colons instead of commas Dan Carpenter
@ 2022-07-22 7:17 ` Xin Ji
0 siblings, 0 replies; 6+ messages in thread
From: Xin Ji @ 2022-07-22 7:17 UTC (permalink / raw)
To: Dan Carpenter
Cc: Heikki Krogerus, Greg Kroah-Hartman, linux-usb, kernel-janitors
On Fri, Jul 22, 2022 at 09:29:52AM +0300, Dan Carpenter wrote:
> Semi colons and commas are equivalent in this context but semi-colons
> are better style.
Hi Dan Carpenter, thanks for your patch.
Reviewed-by: Xin Ji <xji@analogixsemi.com>
Thanks,
Xin
>
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> drivers/usb/typec/anx7411.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/usb/typec/anx7411.c b/drivers/usb/typec/anx7411.c
> index 311b56aaea9f..18a6a6a8b9eb 100644
> --- a/drivers/usb/typec/anx7411.c
> +++ b/drivers/usb/typec/anx7411.c
> @@ -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);
> --
> 2.35.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/3] usb: typec: anx7411: Fix an array out of bounds
2022-07-22 6:25 [PATCH 1/3] usb: typec: anx7411: Fix an array out of bounds Dan Carpenter
2022-07-22 6:29 ` [PATCH 2/3] usb: typec: anx7411: fix error checking in anx7411_get_gpio_irq() Dan Carpenter
2022-07-22 6:29 ` [PATCH 3/3] usb: typec: anx7411: use semi-colons instead of commas Dan Carpenter
@ 2022-07-22 7:15 ` Xin Ji
2 siblings, 0 replies; 6+ messages in thread
From: Xin Ji @ 2022-07-22 7:15 UTC (permalink / raw)
To: Dan Carpenter
Cc: Heikki Krogerus, Greg Kroah-Hartman, linux-usb, kernel-janitors
On Fri, Jul 22, 2022 at 09:25:42AM +0300, Dan Carpenter wrote:
> This should be ARRAY_SIZE() instead of sizeof(). ARRAY_SIZE is
> 4 and sizeof is 8.
Hi Dan Carpenter, thanks for your patch.
Reviewed-by: Xin Ji <xji@analogixsemi.com>
Thanks,
Xi
>
> Fixes: fe6d8a9c8e64 ("usb: typec: anx7411: Add Analogix PD ANX7411 support")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> drivers/usb/typec/anx7411.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/usb/typec/anx7411.c b/drivers/usb/typec/anx7411.c
> index b990376991f8..4f7a5cc968d0 100644
> --- a/drivers/usb/typec/anx7411.c
> +++ b/drivers/usb/typec/anx7411.c
> @@ -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,
> --
> 2.35.1
^ permalink raw reply [flat|nested] 6+ messages in thread