linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] USB: serial: cp210x: fix CP2105 GPIO registration
@ 2021-11-26  9:43 Johan Hovold
  2021-11-26  9:56 ` Greg KH
  2021-11-26 12:37 ` Maarten Brock
  0 siblings, 2 replies; 3+ messages in thread
From: Johan Hovold @ 2021-11-26  9:43 UTC (permalink / raw)
  To: Johan Hovold; +Cc: linux-usb, linux-kernel, Maarten Brock, stable, Karoly Pados

When generalising GPIO support and adding support for CP2102N, the GPIO
registration for some CP2105 devices accidentally broke. Specifically,
when all the pins of a port are in "modem" mode, and thus unavailable
for GPIO use, the GPIO chip would now be registered without having
initialised the number of GPIO lines. This would in turn be rejected by
gpiolib and some errors messages would be printed (but importantly probe
would still succeed).

Fix this by initialising the number of GPIO lines before registering the
GPIO chip.

Note that as for the other device types, and as when all CP2105 pins are
muxed for LED function, the GPIO chip is registered also when no pins
are available for GPIO use.

Reported-by: Maarten Brock <m.brock@vanmierlo.com>
Link: https://lore.kernel.org/r/5eb560c81d2ea1a2b4602a92d9f48a89@vanmierlo.com
Fixes: c8acfe0aadbe ("USB: serial: cp210x: implement GPIO support for CP2102N")
Cc: stable@vger.kernel.org      # 4.19
Cc: Karoly Pados <pados@pados.hu>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/serial/cp210x.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
index 7705328034ca..8a60c0d56863 100644
--- a/drivers/usb/serial/cp210x.c
+++ b/drivers/usb/serial/cp210x.c
@@ -1635,6 +1635,8 @@ static int cp2105_gpioconf_init(struct usb_serial *serial)
 
 	/*  2 banks of GPIO - One for the pins taken from each serial port */
 	if (intf_num == 0) {
+		priv->gc.ngpio = 2;
+
 		if (mode.eci == CP210X_PIN_MODE_MODEM) {
 			/* mark all GPIOs of this interface as reserved */
 			priv->gpio_altfunc = 0xff;
@@ -1645,8 +1647,9 @@ static int cp2105_gpioconf_init(struct usb_serial *serial)
 		priv->gpio_pushpull = (u8)((le16_to_cpu(config.gpio_mode) &
 						CP210X_ECI_GPIO_MODE_MASK) >>
 						CP210X_ECI_GPIO_MODE_OFFSET);
-		priv->gc.ngpio = 2;
 	} else if (intf_num == 1) {
+		priv->gc.ngpio = 3;
+
 		if (mode.sci == CP210X_PIN_MODE_MODEM) {
 			/* mark all GPIOs of this interface as reserved */
 			priv->gpio_altfunc = 0xff;
@@ -1657,7 +1660,6 @@ static int cp2105_gpioconf_init(struct usb_serial *serial)
 		priv->gpio_pushpull = (u8)((le16_to_cpu(config.gpio_mode) &
 						CP210X_SCI_GPIO_MODE_MASK) >>
 						CP210X_SCI_GPIO_MODE_OFFSET);
-		priv->gc.ngpio = 3;
 	} else {
 		return -ENODEV;
 	}
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] USB: serial: cp210x: fix CP2105 GPIO registration
  2021-11-26  9:43 [PATCH] USB: serial: cp210x: fix CP2105 GPIO registration Johan Hovold
@ 2021-11-26  9:56 ` Greg KH
  2021-11-26 12:37 ` Maarten Brock
  1 sibling, 0 replies; 3+ messages in thread
From: Greg KH @ 2021-11-26  9:56 UTC (permalink / raw)
  To: Johan Hovold; +Cc: linux-usb, linux-kernel, Maarten Brock, stable, Karoly Pados

On Fri, Nov 26, 2021 at 10:43:48AM +0100, Johan Hovold wrote:
> When generalising GPIO support and adding support for CP2102N, the GPIO
> registration for some CP2105 devices accidentally broke. Specifically,
> when all the pins of a port are in "modem" mode, and thus unavailable
> for GPIO use, the GPIO chip would now be registered without having
> initialised the number of GPIO lines. This would in turn be rejected by
> gpiolib and some errors messages would be printed (but importantly probe
> would still succeed).
> 
> Fix this by initialising the number of GPIO lines before registering the
> GPIO chip.
> 
> Note that as for the other device types, and as when all CP2105 pins are
> muxed for LED function, the GPIO chip is registered also when no pins
> are available for GPIO use.
> 
> Reported-by: Maarten Brock <m.brock@vanmierlo.com>
> Link: https://lore.kernel.org/r/5eb560c81d2ea1a2b4602a92d9f48a89@vanmierlo.com
> Fixes: c8acfe0aadbe ("USB: serial: cp210x: implement GPIO support for CP2102N")
> Cc: stable@vger.kernel.org      # 4.19
> Cc: Karoly Pados <pados@pados.hu>
> Signed-off-by: Johan Hovold <johan@kernel.org>


Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] USB: serial: cp210x: fix CP2105 GPIO registration
  2021-11-26  9:43 [PATCH] USB: serial: cp210x: fix CP2105 GPIO registration Johan Hovold
  2021-11-26  9:56 ` Greg KH
@ 2021-11-26 12:37 ` Maarten Brock
  1 sibling, 0 replies; 3+ messages in thread
From: Maarten Brock @ 2021-11-26 12:37 UTC (permalink / raw)
  To: Johan Hovold; +Cc: linux-usb, linux-kernel, stable, Karoly Pados

On 2021-11-26 10:43, Johan Hovold wrote:
> When generalising GPIO support and adding support for CP2102N, the GPIO
> registration for some CP2105 devices accidentally broke. Specifically,
> when all the pins of a port are in "modem" mode, and thus unavailable
> for GPIO use, the GPIO chip would now be registered without having
> initialised the number of GPIO lines. This would in turn be rejected by
> gpiolib and some errors messages would be printed (but importantly 
> probe
> would still succeed).
> 
> Fix this by initialising the number of GPIO lines before registering 
> the
> GPIO chip.
> 
> Note that as for the other device types, and as when all CP2105 pins 
> are
> muxed for LED function, the GPIO chip is registered also when no pins
> are available for GPIO use.
> 
> Reported-by: Maarten Brock <m.brock@vanmierlo.com>
> Link: 
> https://lore.kernel.org/r/5eb560c81d2ea1a2b4602a92d9f48a89@vanmierlo.com
> Fixes: c8acfe0aadbe ("USB: serial: cp210x: implement GPIO support for 
> CP2102N")
> Cc: stable@vger.kernel.org      # 4.19
> Cc: Karoly Pados <pados@pados.hu>
> Signed-off-by: Johan Hovold <johan@kernel.org>
> ---
>  drivers/usb/serial/cp210x.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
> index 7705328034ca..8a60c0d56863 100644
> --- a/drivers/usb/serial/cp210x.c
> +++ b/drivers/usb/serial/cp210x.c
> @@ -1635,6 +1635,8 @@ static int cp2105_gpioconf_init(struct usb_serial 
> *serial)
> 
>  	/*  2 banks of GPIO - One for the pins taken from each serial port */
>  	if (intf_num == 0) {
> +		priv->gc.ngpio = 2;
> +
>  		if (mode.eci == CP210X_PIN_MODE_MODEM) {
>  			/* mark all GPIOs of this interface as reserved */
>  			priv->gpio_altfunc = 0xff;
> @@ -1645,8 +1647,9 @@ static int cp2105_gpioconf_init(struct usb_serial 
> *serial)
>  		priv->gpio_pushpull = (u8)((le16_to_cpu(config.gpio_mode) &
>  						CP210X_ECI_GPIO_MODE_MASK) >>
>  						CP210X_ECI_GPIO_MODE_OFFSET);
> -		priv->gc.ngpio = 2;
>  	} else if (intf_num == 1) {
> +		priv->gc.ngpio = 3;
> +
>  		if (mode.sci == CP210X_PIN_MODE_MODEM) {
>  			/* mark all GPIOs of this interface as reserved */
>  			priv->gpio_altfunc = 0xff;
> @@ -1657,7 +1660,6 @@ static int cp2105_gpioconf_init(struct usb_serial 
> *serial)
>  		priv->gpio_pushpull = (u8)((le16_to_cpu(config.gpio_mode) &
>  						CP210X_SCI_GPIO_MODE_MASK) >>
>  						CP210X_SCI_GPIO_MODE_OFFSET);
> -		priv->gc.ngpio = 3;
>  	} else {
>  		return -ENODEV;
>  	}

Tested-by: Maarten Brock <m.brock@vanmierlo.com>


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-11-26 13:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-26  9:43 [PATCH] USB: serial: cp210x: fix CP2105 GPIO registration Johan Hovold
2021-11-26  9:56 ` Greg KH
2021-11-26 12:37 ` Maarten Brock

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).