Re: [PATCH 2/2] USB: serial: cp210x: use new GPIO line value setter callbacks

From: Johan Hovold
Date: Wed Jun 18 2025 - 10:45:38 EST


On Tue, Jun 10, 2025 at 02:43:47PM +0200, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxx>
>
> struct gpio_chip now has callbacks for setting line values that return
> an integer, allowing to indicate failures. Convert the driver to using
> them.
>
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxx>
> ---
> drivers/usb/serial/cp210x.c | 18 +++++++-----------
> 1 file changed, 7 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
> index 9960ac2b10b719192dfbab0a6e81b2cf80f40d36..caeb2873a60451fb7a9a5b5d25071547b5401d52 100644
> --- a/drivers/usb/serial/cp210x.c
> +++ b/drivers/usb/serial/cp210x.c
> @@ -1504,7 +1504,7 @@ static int cp210x_gpio_get(struct gpio_chip *gc, unsigned int gpio)
> return !!(mask & BIT(gpio));
> }
>
> -static void cp210x_gpio_set(struct gpio_chip *gc, unsigned int gpio, int value)
> +static int cp210x_gpio_set(struct gpio_chip *gc, unsigned int gpio, int value)
> {
> struct usb_serial *serial = gpiochip_get_data(gc);
> struct cp210x_serial_private *priv = usb_get_serial_data(serial);
> @@ -1522,8 +1522,8 @@ static void cp210x_gpio_set(struct gpio_chip *gc, unsigned int gpio, int value)
> mask = BIT(gpio);
>
> result = usb_autopm_get_interface(serial->interface);
> - if (result)
> - goto out;
> + if (result < 0)
> + return result;

This is arguably an unrelated change, please keep it as is.

> switch (priv->partnum) {
> case CP210X_PARTNUM_CP2105:
> @@ -1555,11 +1555,8 @@ static void cp210x_gpio_set(struct gpio_chip *gc, unsigned int gpio, int value)
> }
>
> usb_autopm_put_interface(serial->interface);
> -out:
> - if (result < 0) {
> - dev_err(&serial->interface->dev, "failed to set GPIO value: %d\n",
> - result);
> - }

And keep this in place too, and just result if negative.

> +
> + return result < 0 ? result : 0;

And return 0 explicitly here to avoid using the ternary operator.

> }

Johan