Building the Linux kernel with Clang and LLVM
 help / color / mirror / Atom feed
From: Elkin Cruz <elkin@google.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jiri Slaby <jirislaby@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org,
	 llvm@lists.linux.dev, irogers@google.com,
	Elkin Cruz <elkin@google.com>
Subject: [PATCH] serial: 8250_exar: check IS_ERR() on __xr17v35x_register_gpio()
Date: Fri, 20 Nov 2026 19:21:47 +0000	[thread overview]
Message-ID: <20261120192147.2869595-1-elkin@google.com> (raw)

__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


             reply	other threads:[~2026-11-20 19:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 19:21 Elkin Cruz [this message]
     [not found] <sashiko-outbox-225939@kernel.org>
2026-11-20 20:00 ` [PATCH] serial: 8250_exar: check IS_ERR() on __xr17v35x_register_gpio() Elkin Cruz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261120192147.2869595-1-elkin@google.com \
    --to=elkin@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=irogers@google.com \
    --cc=jirislaby@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox