All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] serial: 8250_exar: check IS_ERR() on __xr17v35x_register_gpio()
@ 2026-11-20 19:21 Elkin Cruz
  2026-11-20 19:40 ` sashiko-bot
  0 siblings, 1 reply; 3+ messages in thread
From: Elkin Cruz @ 2026-11-20 19:21 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby
  Cc: linux-kernel, linux-serial, llvm, irogers, Elkin Cruz

__xr17v35x_register_gpio() calls platform_device_register_full(), which
returns an ERR_PTR() on failure rather than NULL. Both
xr17v35x_register_gpio() and iot2040_register_gpio() store the return
value directly into priv->gpio without checking IS_ERR() and return 0;
xr17v35x_unregister_gpio() later tests only if (priv->gpio) and
dereferences the error pointer via __xr17v35x_unregister_gpio().

Check IS_ERR(pdev) and propagate PTR_ERR(pdev) in both callers.

Fixes: 1145d1a0703f ("serial: 8250_exar: use platform_device_register_full()")
Signed-off-by: Elkin Cruz <elkin@google.com>
---
I am trying out a new Clang static analysis linter for ERR_PTR/NULL
handling, and it flagged this code as possibly buggy. The findings were triaged
and fixed with an AI coding assistant, then checked against linux-next (not
runtime-tested on hardware).

Thanks,
Elkin

 drivers/tty/serial/8250/8250_exar.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_exar.c b/drivers/tty/serial/8250/8250_exar.c
index 42e55a8f8c69..66858e383afc 100644
--- a/drivers/tty/serial/8250/8250_exar.c
+++ b/drivers/tty/serial/8250/8250_exar.c
@@ -1173,8 +1173,14 @@ static const struct software_node exar_gpio_node = {
 static int xr17v35x_register_gpio(struct exar8250 *priv, struct pci_dev *pcidev,
 				  struct uart_8250_port *port)
 {
-	if (pcidev->vendor == PCI_VENDOR_ID_EXAR)
-		priv->gpio = __xr17v35x_register_gpio(pcidev, &exar_gpio_node);
+	if (pcidev->vendor == PCI_VENDOR_ID_EXAR) {
+		struct platform_device *pdev;
+
+		pdev = __xr17v35x_register_gpio(pcidev, &exar_gpio_node);
+		if (IS_ERR(pdev))
+			return PTR_ERR(pdev);
+		priv->gpio = pdev;
+	}
 
 	return 0;
 }
@@ -1286,13 +1292,17 @@ static int iot2040_register_gpio(struct exar8250 *priv,
 				 struct uart_8250_port *port)
 {
 	u8 __iomem *p = port->port.membase;
+	struct platform_device *pdev;
 
 	writeb(IOT2040_UARTS_DEFAULT_MODE, p + UART_EXAR_MPIOLVL_7_0);
 	writeb(IOT2040_UARTS_GPIO_LO_MODE, p + UART_EXAR_MPIOSEL_7_0);
 	writeb(IOT2040_UARTS_ENABLE, p + UART_EXAR_MPIOLVL_15_8);
 	writeb(IOT2040_UARTS_GPIO_HI_MODE, p + UART_EXAR_MPIOSEL_15_8);
 
-	priv->gpio = __xr17v35x_register_gpio(pcidev, &iot2040_gpio_node);
+	pdev = __xr17v35x_register_gpio(pcidev, &iot2040_gpio_node);
+	if (IS_ERR(pdev))
+		return PTR_ERR(pdev);
+	priv->gpio = pdev;
 
 	return 0;
 }
-- 
2.56.1.750.gf70dc682cf-goog


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

* Re: [PATCH] serial: 8250_exar: check IS_ERR() on __xr17v35x_register_gpio()
  2026-11-20 19:21 [PATCH] serial: 8250_exar: check IS_ERR() on __xr17v35x_register_gpio() Elkin Cruz
@ 2026-11-20 19:40 ` sashiko-bot
  2026-11-20 20:00   ` Elkin Cruz
  0 siblings, 1 reply; 3+ messages in thread
From: sashiko-bot @ 2026-11-20 19:40 UTC (permalink / raw)
  To: Elkin Cruz; +Cc: linux-serial

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] serial: 8250_exar: redundant fix aborts all UART ports in
  exar_pci_probe()
--

commit b311185ae98aa3c07a0e01dce285dd1024817852
Author: Elkin Cruz <elkin@google.com>

serial: 8250_exar: check IS_ERR() on __xr17v35x_register_gpio()

This commit checks IS_ERR() on the platform_device pointer returned by
__xr17v35x_register_gpio() in xr17v35x_register_gpio() and
iot2040_register_gpio(), propagating PTR_ERR(pdev) on failure.

> diff --git a/drivers/tty/serial/8250/8250_exar.c b/drivers/tty/serial/8250/8250_exar.c
> index 42e55a8f8c69b..66858e383afcd 100644
> --- a/drivers/tty/serial/8250/8250_exar.c
> +++ b/drivers/tty/serial/8250/8250_exar.c
> @@ -1173,8 +1173,14 @@ static const struct software_node exar_gpio_node = {
>  static int xr17v35x_register_gpio(struct exar8250 *priv, struct pci_dev *pcidev,
>  				  struct uart_8250_port *port)
>  {
> -	if (pcidev->vendor == PCI_VENDOR_ID_EXAR)
> -		priv->gpio = __xr17v35x_register_gpio(pcidev, &exar_gpio_node);
> +	if (pcidev->vendor == PCI_VENDOR_ID_EXAR) {
> +		struct platform_device *pdev;
> +
> +		pdev = __xr17v35x_register_gpio(pcidev, &exar_gpio_node);
> +		if (IS_ERR(pdev))
> +			return PTR_ERR(pdev);
> +		priv->gpio = pdev;
> +	}
>  
>  	return 0;
>  }
> @@ -1286,13 +1292,17 @@ static int iot2040_register_gpio(struct exar8250 *priv,
>  				 struct uart_8250_port *port)
>  {
>  	u8 __iomem *p = port->port.membase;
> +	struct platform_device *pdev;
>  
>  	writeb(IOT2040_UARTS_DEFAULT_MODE, p + UART_EXAR_MPIOLVL_7_0);
>  	writeb(IOT2040_UARTS_GPIO_LO_MODE, p + UART_EXAR_MPIOSEL_7_0);
>  	writeb(IOT2040_UARTS_ENABLE, p + UART_EXAR_MPIOLVL_15_8);
>  	writeb(IOT2040_UARTS_GPIO_HI_MODE, p + UART_EXAR_MPIOSEL_15_8);
>  
> -	priv->gpio = __xr17v35x_register_gpio(pcidev, &iot2040_gpio_node);
> +	pdev = __xr17v35x_register_gpio(pcidev, &iot2040_gpio_node);
> +	if (IS_ERR(pdev))
> +		return PTR_ERR(pdev);
> +	priv->gpio = pdev;
>  
>  	return 0;
>  }

[Severity: Medium]
Should a failure in __xr17v35x_register_gpio() abort UART port registration
in exar_pci_probe()?

The error-pointer dereference in xr17v35x_unregister_gpio() mentioned in
the commit message was already fixed by 0353b5196588 ("serial: 8250_exar:
check priv->gpio properly"), which checks !IS_ERR_OR_NULL(priv->gpio).

Previously, GPIO platform-device registration failure was non-fatal so the
card's UART ports would still be registered.  Propagating PTR_ERR(pdev) from
xr17v35x_register_gpio() and iot2040_register_gpio() causes
pci_xr17v35x_setup() to fail on port 0, which breaks out of the port setup
loop in exar_pci_probe() at i == 0 and leaves the card with zero UART ports
registered while exar_pci_probe() still returns 0:

drivers/tty/serial/8250/8250_exar.c:exar_pci_probe() {
    ...
	for (i = 0; i < nr_ports && i < maxnr; i++) {
		rc = board->setup(priv, pcidev, &uart, i);
		if (rc) {
			dev_err_probe(&pcidev->dev, rc, "Failed to setup port %u\n", i);
			break;
		}
    ...
}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261120192147.2869595-1-elkin@google.com?part=1

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

* Re: [PATCH] serial: 8250_exar: check IS_ERR() on __xr17v35x_register_gpio()
  2026-11-20 19:40 ` sashiko-bot
@ 2026-11-20 20:00   ` Elkin Cruz
  0 siblings, 0 replies; 3+ messages in thread
From: Elkin Cruz @ 2026-11-20 20:00 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby
  Cc: linux-serial, linux-kernel, sashiko-reviews, llvm, irogers

On Fri, Nov 20, 2026 at 07:40:04PM +0000, sashiko-bot@kernel.org wrote:

Please ignore this patch.

> The error-pointer dereference in xr17v35x_unregister_gpio() mentioned in
> the commit message was already fixed by 0353b5196588 ("serial: 8250_exar:
> check priv->gpio properly"), which checks !IS_ERR_OR_NULL(priv->gpio).
>
> Previously, GPIO platform-device registration failure was non-fatal so the
> card's UART ports would still be registered.  Propagating PTR_ERR(pdev) from
> xr17v35x_register_gpio() and iot2040_register_gpio() causes
> pci_xr17v35x_setup() to fail on port 0, which breaks out of the port setup
> loop in exar_pci_probe() at i == 0 and leaves the card with zero UART ports
> registered while exar_pci_probe() still returns 0:

Sashiko is right here - 0353b5196588 already fixed the unbind bug in
xr17v35x_unregister_gpio(), and returning an error from
register_gpio() would abort UART port setup in exar_pci_probe().

Thanks,
Elkin

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

end of thread, other threads:[~2026-11-20 20:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 19:21 [PATCH] serial: 8250_exar: check IS_ERR() on __xr17v35x_register_gpio() Elkin Cruz
2026-11-20 19:40 ` sashiko-bot
2026-11-20 20:00   ` Elkin Cruz

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.