mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: parthiban.veerasooran@microchip.com, christian.gromm@microchip.com
Cc: linux-kernel@vger.kernel.org, Josef Bacik <josef@toxicpanda.com>,
	stable <stable@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: [PATCH] most: usb: don't use a NULL device on disconnect
Date: Tue, 27 Oct 2026 17:33:08 +0100	[thread overview]
Message-ID: <2026102707-diploma-clubbed-ea4f@gregkh> (raw)

From: Josef Bacik <josef@toxicpanda.com>

hdm_disconnect() clears mdev->usb_device before it stops the link status
timer and the work which that timer schedules.  wq_netinfo() does not
expect a NULL pointer: it hands it to drci_rd_reg(), which dereferences
it.  Stop the timer and the work first.

The interface stays registered until the end of hdm_disconnect(), so
hdm_request_netinfo() can still be called and arm the timer.  Shut the
timer down, rather than delete it, so that this has no effect.

wq_clear_halt() has the same problem.  It is only cancelled when the
channels are poisoned, by most_deregister_interface(), and cannot be
cancelled earlier since the URB handlers schedule it.  It takes io_mutex,
like the code which clears the pointer, so test the pointer there.

Fixes: a4198cdf0c34 ("Staging: most: add MOST driver's hdm-usb module")
Cc: stable <stable@kernel.org>
Cc: Parthiban Veerasooran <parthiban.veerasooran@microchip.com>
Cc: Christian Gromm <christian.gromm@microchip.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/most/most_usb.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/most/most_usb.c b/drivers/most/most_usb.c
index 6437733afee0..9485f5a51f5f 100644
--- a/drivers/most/most_usb.c
+++ b/drivers/most/most_usb.c
@@ -735,6 +735,10 @@ static void wq_clear_halt(struct work_struct *wq_obj)
 	int peer;
 
 	mutex_lock(&mdev->io_mutex);
+	if (!mdev->usb_device) {
+		mutex_unlock(&mdev->io_mutex);
+		return;
+	}
 	most_stop_enqueue(&mdev->iface, channel);
 	usb_kill_anchored_urbs(&mdev->busy_urbs[channel]);
 	if (usb_clear_halt(mdev->usb_device, pipe))
@@ -1108,14 +1112,15 @@ static void hdm_disconnect(struct usb_interface *interface)
 {
 	struct most_dev *mdev = usb_get_intfdata(interface);
 
+	/* hdm_request_netinfo() can still be called, and arms the timer */
+	timer_shutdown_sync(&mdev->link_stat_timer);
+	cancel_work_sync(&mdev->poll_work_obj);
+
 	mutex_lock(&mdev->io_mutex);
 	usb_set_intfdata(interface, NULL);
 	mdev->usb_device = NULL;
 	mutex_unlock(&mdev->io_mutex);
 
-	timer_delete_sync(&mdev->link_stat_timer);
-	cancel_work_sync(&mdev->poll_work_obj);
-
 	if (mdev->dci)
 		device_unregister(&mdev->dci->dev);
 	most_deregister_interface(&mdev->iface);
-- 
2.56.0


                 reply	other threads:[~2026-10-27 16:33 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=2026102707-diploma-clubbed-ea4f@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=christian.gromm@microchip.com \
    --cc=josef@toxicpanda.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=parthiban.veerasooran@microchip.com \
    --cc=stable@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®