Skip to contentSkip to conversation

staging: usbip: stub_dev: Fixed oops during removal of usbip_host

PATCH In review navin patidar 2 participants 6 messages Sep 18, 2012 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: usbip: stub_dev: Fixed oops during removal of usbip_host

stub_device_reset should set kernel thread pointers to NULL. so that at the time of usbip_host removal stub_shoutdown_connection doesn't try to kill kernel threads which are already killed.

---
 drivers/staging/usbip/stub_dev.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/staging/usbip/stub_dev.c +4 -3
index 92ced35..447a98c 100644
@@ -198,10 +198,8 @@ static void stub_shutdown_connection(struct usbip_device *ud)
 	 * tcp_socket is freed after threads are killed so that usbip_xmit does
 	 * not touch NULL socket.
 	 */
-	if (ud->tcp_socket) {
+	if (ud->tcp_socket)
 		sock_release(ud->tcp_socket);
-		ud->tcp_socket = NULL;
-	}
 
 	/* 3. free used data */
 	stub_device_cleanup_urbs(sdev);
@@ -233,6 +231,9 @@ static void stub_device_reset(struct usbip_device *ud)
 
 	dev_dbg(&udev->dev, "device reset");
 
+	ud->tcp_socket = NULL;
+	ud->tcp_rx = NULL;
+	ud->tcp_tx = NULL;
 	ret = usb_lock_device_for_reset(udev, sdev->interface);
 	if (ret < 0) {
 		dev_err(&udev->dev, "lock for reset\n");
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 4 lines · navin patidar

stub_device_reset should set kernel thread pointers to NULL. so that at the time of usbip_host removal stub_shoutdown_connection doesn't try to kill kernel threads which are already killed.

If you have the Oops output, that's always nice to put in the commit message.

Why don't you set the pointers to NULL in stub_shutdown_connection() since that's where you actually kill the threads. Setting them to NULL in stub_device_reset() will (sometimes) solve the problem but it gives you a new problem of a resource leak.

regards,
dan carpenter

#2 lore raw
Quoted 8 lines · Dan Carpenter
Quoted 4 lines · navin patidar

stub_device_reset should set kernel thread pointers to NULL. so that at the time of usbip_host removal stub_shoutdown_connection doesn't try to kill kernel threads which are already killed.

If you have the Oops output, that's always nice to put in the commit message.

i'll surely keep this in mind before submitting further patches.

Quoted 4 lines

Why don't you set the pointers to NULL in stub_shutdown_connection() since that's where you actually kill the threads. Setting them to NULL in stub_device_reset() will (sometimes) solve the problem but it gives you a new problem of a resource leak.

stub_device_reset() always gets executed after
stub_shutdown_connection() , never before.

Quoted 4 lines

regards,
dan carpenter

--navin-patidar

#3 lore raw
Quoted 12 lines · navin patidar
Quoted 8 lines · Dan Carpenter
Quoted 4 lines · navin patidar

stub_device_reset should set kernel thread pointers to NULL. so that at the time of usbip_host removal stub_shoutdown_connection doesn't try to kill kernel threads which are already killed.

If you have the Oops output, that's always nice to put in the commit message.

i'll surely keep this in mind before submitting further patches.

Quoted 8 lines
Quoted 4 lines

Why don't you set the pointers to NULL in stub_shutdown_connection() since that's where you actually kill the threads. Setting them to NULL in stub_device_reset() will (sometimes) solve the problem but it gives you a new problem of a resource leak.

stub_device_reset() always gets executed after
stub_shutdown_connection() , never before.

No it isn't. Read event_handler() more carefully. They can be executed independently.

In other words, stub_shutdown_connection() can be called without calling stub_device_reset() and stub_device_reset() can be called without stub_shutdown_connection(). If either of those happen then it causes a problem with the patch you have just sent.

regards,
dan carpenter

#4 lore raw

for usbip_host event_handler() handles following events. defined
in "usbip_common.h"

1. SDEV_EVENT_REMOVED (USBIP_EH_SHUTDOWN | USBIP_EH_RESET | USBIP_EH_BYE)
2. SDEV_EVENT_DOWN (USBIP_EH_SHUTDOWN | USBIP_EH_RESET)
3. SDEV_EVENT_ERROR_TCP (USBIP_EH_SHUTDOWN | USBIP_EH_RESET)
4. SDEV_EVENT_ERROR_SUBMIT (USBIP_EH_SHUTDOWN | USBIP_EH_RESET)
5. VDEV_EVENT_ERROR_MALLOC (USBIP_EH_SHUTDOWN | USBIP_EH_UNUSABLE)

In case of events(1,2,3,4), stub_shoutdown_connection() gets executed first and than stub_device_reset() .

In case of event 5, stub_shoutdown_connection() kills kernel threads
and stub_device_unusable() changes devices status to
"SDEV_ST_ERROR"(fatal error).

thus stub_device_reset() can't be called without
stub_shutdown_connection(), so there is no problem of resource leak . you are also right, i could have set pointers to NULL in stub_shutdown_connection() but i used stub_device_reset() which is intended to reset usbip_device stuct member variables.

i'll resend patches, if maintainer ask for that.
thanks

--navin-patidar

Quoted 33 lines · Dan Carpenter
Quoted 12 lines · navin patidar
Quoted 8 lines · Dan Carpenter
Quoted 4 lines · navin patidar

stub_device_reset should set kernel thread pointers to NULL. so that at the time of usbip_host removal stub_shoutdown_connection doesn't try to kill kernel threads which are already killed.

If you have the Oops output, that's always nice to put in the commit message.

i'll surely keep this in mind before submitting further patches.

Quoted 8 lines
Quoted 4 lines

Why don't you set the pointers to NULL in stub_shutdown_connection() since that's where you actually kill the threads. Setting them to NULL in stub_device_reset() will (sometimes) solve the problem but it gives you a new problem of a resource leak.

stub_device_reset() always gets executed after
stub_shutdown_connection() , never before.

No it isn't. Read event_handler() more carefully. They can be executed independently.

In other words, stub_shutdown_connection() can be called without calling stub_device_reset() and stub_device_reset() can be called without stub_shutdown_connection(). If either of those happen then it causes a problem with the patch you have just sent.

regards,
dan carpenter

#5 lore raw
Quoted 9 lines · navin patidar

for usbip_host event_handler() handles following events. defined
in "usbip_common.h"

1. SDEV_EVENT_REMOVED (USBIP_EH_SHUTDOWN | USBIP_EH_RESET | USBIP_EH_BYE)
2. SDEV_EVENT_DOWN (USBIP_EH_SHUTDOWN | USBIP_EH_RESET)
3. SDEV_EVENT_ERROR_TCP (USBIP_EH_SHUTDOWN | USBIP_EH_RESET)
4. SDEV_EVENT_ERROR_SUBMIT (USBIP_EH_SHUTDOWN | USBIP_EH_RESET)
5. VDEV_EVENT_ERROR_MALLOC (USBIP_EH_SHUTDOWN | USBIP_EH_UNUSABLE)

Quoted 7 lines

In case of events(1,2,3,4), stub_shoutdown_connection() gets executed first and than stub_device_reset() .

In case of event 5, stub_shoutdown_connection() kills kernel threads
and stub_device_unusable() changes devices status to
"SDEV_ST_ERROR"(fatal error).

It's case #5 which I would be worried about. Where did the original Oops happen? I feel like it really would be helpful to see it. I don't see which check for ->status != SDEV_ST_AVAILABLE you're talking about here which prevents the pointers from being reused...

Quoted 2 lines

thus stub_device_reset() can't be called without
stub_shutdown_connection(), so there is no problem of resource leak .

Except in the case of #5 obviously.

Quoted 7 lines

you are also right, i could have set pointers to NULL in stub_shutdown_connection() but i used stub_device_reset() which is intended to reset usbip_device stuct member variables.

i'll resend patches, if maintainer ask for that.
thanks

Generally, that's normal. If you want to ensure that a pointer isn't used again then you clear it immediately.

I'm honestly just trying to figure this out. When I saw that the patch, I immediately thought *resource leak*. I'm sorry that to take your time up, but it shouldn't be that complicated that I have to go tracking through the whole driver to understand this.

regards,
dan carpenter