mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hugo Villeneuve <hugo@hugovil.com>
To: gregkh@linuxfoundation.org, jirislaby@kernel.org,
	jringle@gridpoint.com, kubakici@wp.pl, phil@raspberrypi.org,
	bo.svangard@embeddedart.se
Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org,
	hugo@hugovil.com, Hugo Villeneuve <hvilleneuve@dimonoff.com>,
	stable@vger.kernel.org
Subject: [PATCH 01/18] serial: sc16is7xx: fix segfault when removing driver
Date: Tue, 19 Dec 2023 12:18:45 -0500	[thread overview]
Message-ID: <20231219171903.3530985-2-hugo@hugovil.com> (raw)
In-Reply-To: <20231219171903.3530985-1-hugo@hugovil.com>

From: Hugo Villeneuve <hvilleneuve@dimonoff.com>

If a problem with a device occurs during probing, and we subsequently
try to remove the driver, we get the following error:

$ rmmod sc16is7xx
[   62.783166] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000040
[   62.994226] Call trace:
[   62.996672]  serial_core_unregister_port+0x58/0x2b0
[   63.001558]  serial_ctrl_unregister_port+0x18/0x30
[   63.006354]  uart_remove_one_port+0x18/0x30
[   63.010542]  sc16is7xx_spi_remove+0xc0/0x190 [sc16is7xx]
Segmentation fault

Tested on a custom board with two SC16IS742 ICs, and by simulating a fault
when probing channel (port) B of the second device.

The reason is that uart_remove_one_port() has already been called during
probe in the out_ports: error path, and is called again in
sc16is7xx_remove().

Fix the problem by clearing the device drvdata in probe error path to
indicate that all resources have been deallocated. And only deallocate
resources in sc16is7xx_remove() if device drvdata is non-null.

Fixes: dfeae619d781 ("serial: sc16is7xx")
Cc: stable@vger.kernel.org
Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
---
 drivers/tty/serial/sc16is7xx.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/tty/serial/sc16is7xx.c b/drivers/tty/serial/sc16is7xx.c
index e40e4a99277e..b585663c1e6e 100644
--- a/drivers/tty/serial/sc16is7xx.c
+++ b/drivers/tty/serial/sc16is7xx.c
@@ -1663,6 +1663,8 @@ static int sc16is7xx_probe(struct device *dev,
 out_clk:
 	clk_disable_unprepare(s->clk);
 
+	dev_set_drvdata(dev, NULL);
+
 	return ret;
 }
 
@@ -1671,6 +1673,9 @@ static void sc16is7xx_remove(struct device *dev)
 	struct sc16is7xx_port *s = dev_get_drvdata(dev);
 	int i;
 
+	if (!s)
+		return;
+
 #ifdef CONFIG_GPIOLIB
 	if (s->gpio_valid_mask)
 		gpiochip_remove(&s->gpio);
-- 
2.39.2


  reply	other threads:[~2023-12-19 17:19 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-19 17:18 [PATCH 00/18] serial: sc16is7xx: fixes, cleanups and improvements Hugo Villeneuve
2023-12-19 17:18 ` Hugo Villeneuve [this message]
2023-12-20 15:34   ` [PATCH 01/18] serial: sc16is7xx: fix segfault when removing driver Andy Shevchenko
2023-12-20 15:38     ` Andy Shevchenko
2023-12-19 17:18 ` [PATCH 02/18] serial: sc16is7xx: fix invalid sc16is7xx_lines bitfield in case of probe error Hugo Villeneuve
2023-12-20 15:40   ` Andy Shevchenko
2023-12-21 15:56     ` Hugo Villeneuve
2023-12-21 16:05       ` Andy Shevchenko
2023-12-21 16:13       ` Hugo Villeneuve
2023-12-21 16:16         ` Andy Shevchenko
2023-12-21 17:13           ` Hugo Villeneuve
2023-12-19 17:18 ` [PATCH 03/18] serial: sc16is7xx: remove obsolete loop in sc16is7xx_port_irq() Hugo Villeneuve
2023-12-20 15:41   ` Andy Shevchenko
2023-12-20 22:09     ` Hugo Villeneuve
2023-12-19 17:18 ` [PATCH 04/18] serial: sc16is7xx: improve do/while loop in sc16is7xx_irq() Hugo Villeneuve
2023-12-20 15:42   ` Andy Shevchenko
2023-12-20 16:00     ` Hugo Villeneuve
2023-12-19 17:18 ` [PATCH 05/18] serial: sc16is7xx: use DECLARE_BITMAP for sc16is7xx_lines bitfield Hugo Villeneuve
2023-12-20 15:45   ` Andy Shevchenko
2023-12-19 17:18 ` [PATCH 06/18] serial: sc16is7xx: use spi_get_device_match_data() Hugo Villeneuve
2023-12-20 15:44   ` Andy Shevchenko
2023-12-20 22:22     ` Hugo Villeneuve
2023-12-19 17:18 ` [PATCH 07/18] serial: sc16is7xx: use i2c_get_match_data() Hugo Villeneuve
2023-12-20 15:45   ` Andy Shevchenko
2023-12-19 17:18 ` [PATCH 08/18] serial: sc16is7xx: add driver name to struct uart_driver Hugo Villeneuve
2023-12-20 15:48   ` Andy Shevchenko
2023-12-20 16:11     ` Hugo Villeneuve
2023-12-20 18:59       ` Andy Shevchenko
2023-12-19 17:18 ` [PATCH 09/18] serial: sc16is7xx: add macro for max number of UART ports Hugo Villeneuve
2023-12-20 15:50   ` Andy Shevchenko
2023-12-21 16:41     ` Hugo Villeneuve
2023-12-21 16:55       ` Andy Shevchenko
2023-12-21 17:00         ` Hugo Villeneuve
2023-12-19 17:18 ` [PATCH 10/18] serial: sc16is7xx: use HZ_PER_MHZ macro to improve readability Hugo Villeneuve
2023-12-20 15:51   ` Andy Shevchenko
2023-12-19 17:18 ` [PATCH 11/18] serial: sc16is7xx: add explicit return for some switch default cases Hugo Villeneuve
2023-12-20 15:52   ` Andy Shevchenko
2023-12-19 17:18 ` [PATCH 12/18] serial: sc16is7xx: replace hardcoded divisor value with BIT() macro Hugo Villeneuve
2023-12-20 15:52   ` Andy Shevchenko
2023-12-19 17:18 ` [PATCH 13/18] serial: sc16is7xx: use in_range() for DT properties bound checks Hugo Villeneuve
2023-12-20 15:54   ` Andy Shevchenko
2023-12-20 16:24     ` Hugo Villeneuve
2023-12-19 17:18 ` [PATCH 14/18] serial: sc16is7xx: drop unneeded MODULE_ALIAS Hugo Villeneuve
2023-12-20 15:54   ` Andy Shevchenko
2023-12-20 16:21     ` Hugo Villeneuve
2023-12-19 17:18 ` [PATCH 15/18] serial: sc16is7xx: pass R/W buffer in FIFO functions Hugo Villeneuve
2023-12-20 15:57   ` Andy Shevchenko
2023-12-21 19:35     ` Hugo Villeneuve
2023-12-19 17:19 ` [PATCH 16/18] serial: sc16is7xx: reorder code to remove prototype declarations Hugo Villeneuve
2023-12-20 15:58   ` Andy Shevchenko
2023-12-20 16:30     ` Hugo Villeneuve
2023-12-20 19:00       ` Andy Shevchenko
2023-12-19 17:19 ` [PATCH 17/18] serial: sc16is7xx: refactor EFR lock Hugo Villeneuve
2023-12-20 16:03   ` Andy Shevchenko
2023-12-20 21:38     ` Hugo Villeneuve
2023-12-19 17:19 ` [PATCH 18/18] serial: sc16is7xx: fix whitespace in sc16is7xx_startup() comments Hugo Villeneuve
2023-12-20 16:04   ` Andy Shevchenko
2023-12-20 20:53     ` Hugo Villeneuve
2023-12-20 16:06 ` [PATCH 00/18] serial: sc16is7xx: fixes, cleanups and improvements Andy Shevchenko
2023-12-20 16:38   ` Hugo Villeneuve

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=20231219171903.3530985-2-hugo@hugovil.com \
    --to=hugo@hugovil.com \
    --cc=bo.svangard@embeddedart.se \
    --cc=gregkh@linuxfoundation.org \
    --cc=hvilleneuve@dimonoff.com \
    --cc=jirislaby@kernel.org \
    --cc=jringle@gridpoint.com \
    --cc=kubakici@wp.pl \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=phil@raspberrypi.org \
    --cc=stable@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®