Skip to contentSkip to conversation

usb: avoid PM error messages during resume if a device was disconnected

PATCH Superseded Frans Pop 3 participants 22 messages Mar 23, 2009 – Jun 3, 2009 USB

lore
Share & tools
lore

Frans Pop

author
#0 lore raw

PATCH 1/1 usb: avoid PM error messages during resume if a device was disconnected

Currently if a laptop is suspended e.g. while docked and then resumed after undocking it, the following errors get generated because the USB hub in the docking station and the devices connected to it are no longer available:
pm_op(): usb_dev_resume+0x0/0x10 returns -19
PM: Device 1-2 failed to resume: error -19
pm_op(): usb_dev_resume+0x0/0x10 returns -19
PM: Device 1-2.2 failed to resume: error -19
pm_op(): usb_dev_resume+0x0/0x10 returns -19
PM: Device 1-2.3 failed to resume: error -19

As the removal of USB devices while a system is suspended is a relatively common use case and in most cases not an error, just return success on -ENODEV. The user gets informed anyway as the USB subsystem generates regular disconnect messages for the devices shortly afterwards:
usb 1-2: USB disconnect, address 3
usb 1-2.2: USB disconnect, address 4
usblp0: removed
usb 1-2.3: USB disconnect, address 5

Cc Alan Stern <[email protected]>
Cc Rafael J. Wysocki <[email protected]>

---

I've walked through the code and AFAICT just returning 0 does not make any difference for the PM core code.

In a first version of this patch I had the following included just before the 'return 0':

	pr_info("usb %s: failed to resume: no longer connected\n",
						dev_name(&udev->dev));

Problem with that was that the message got printed twice for each device, once for .resume and once for .complete. Given that the disconnects are reported shortly after anyway, I decided the simpler patch might do just as well.

Cheers,
FJP

drivers/usb/core/driver.c +4 -0
index d0a21a5..97ea69b 100644
@@ -1727,6 +1727,10 @@ int usb_external_resume_device(struct usb_device *udev, pm_message_t msg)
 	status = usb_resume_both(udev, msg);
 	udev->last_busy = jiffies;
 	usb_pm_unlock(udev);
+
+	if (status == -ENODEV)
+		return 0;
+
 	if (status == 0)
 		do_unbind_rebind(udev, DO_REBIND);
 
author
#1 lore raw
Quoted 21 lines · Frans Pop

Currently if a laptop is suspended e.g. while docked and then resumed after undocking it, the following errors get generated because the USB hub in the docking station and the devices connected to it are no longer available:
pm_op(): usb_dev_resume+0x0/0x10 returns -19
PM: Device 1-2 failed to resume: error -19
pm_op(): usb_dev_resume+0x0/0x10 returns -19
PM: Device 1-2.2 failed to resume: error -19
pm_op(): usb_dev_resume+0x0/0x10 returns -19
PM: Device 1-2.3 failed to resume: error -19

As the removal of USB devices while a system is suspended is a relatively common use case and in most cases not an error, just return success on -ENODEV. The user gets informed anyway as the USB subsystem generates regular disconnect messages for the devices shortly afterwards:
usb 1-2: USB disconnect, address 3
usb 1-2.2: USB disconnect, address 4
usblp0: removed
usb 1-2.3: USB disconnect, address 5

Quoted 3 lines
Cc Alan Stern <[email protected]>
Cc Rafael J. Wysocki <[email protected]>

Forgot to mention that the patch is intended on top of Rafael's "Rework disabling of interrupts during suspend-resume" series.

author
#2 lore raw
In reply to Frans Pop
Quoted 21 lines · Frans Pop

Currently if a laptop is suspended e.g. while docked and then resumed after undocking it, the following errors get generated because the USB hub in the docking station and the devices connected to it are no longer available:
pm_op(): usb_dev_resume+0x0/0x10 returns -19
PM: Device 1-2 failed to resume: error -19
pm_op(): usb_dev_resume+0x0/0x10 returns -19
PM: Device 1-2.2 failed to resume: error -19
pm_op(): usb_dev_resume+0x0/0x10 returns -19
PM: Device 1-2.3 failed to resume: error -19

As the removal of USB devices while a system is suspended is a relatively common use case and in most cases not an error, just return success on -ENODEV. The user gets informed anyway as the USB subsystem generates regular disconnect messages for the devices shortly afterwards:
usb 1-2: USB disconnect, address 3
usb 1-2.2: USB disconnect, address 4
usblp0: removed
usb 1-2.3: USB disconnect, address 5

Quoted 3 lines
Cc Alan Stern <[email protected]>
Cc Rafael J. Wysocki <[email protected]>

Forgot to mention that the patch is intended on top of Rafael's "Rework disabling of interrupts during suspend-resume" series.

#3 lore raw
In reply to Frans Pop
Quoted 19 lines · Frans Pop

Currently if a laptop is suspended e.g. while docked and then resumed after undocking it, the following errors get generated because the USB hub in the docking station and the devices connected to it are no longer available:
pm_op(): usb_dev_resume+0x0/0x10 returns -19
PM: Device 1-2 failed to resume: error -19
pm_op(): usb_dev_resume+0x0/0x10 returns -19
PM: Device 1-2.2 failed to resume: error -19
pm_op(): usb_dev_resume+0x0/0x10 returns -19
PM: Device 1-2.3 failed to resume: error -19

As the removal of USB devices while a system is suspended is a relatively common use case and in most cases not an error, just return success on -ENODEV. The user gets informed anyway as the USB subsystem generates regular disconnect messages for the devices shortly afterwards:
usb 1-2: USB disconnect, address 3
usb 1-2.2: USB disconnect, address 4
usblp0: removed
usb 1-2.3: USB disconnect, address 5

Quoted 7 lines
Cc Alan Stern <[email protected]>
Cc Rafael J. Wysocki <[email protected]>

---

I've walked through the code and AFAICT just returning 0 does not make any difference for the PM core code.

That's right. After all, there isn't much the PM core can do when an error occurs.

Quoted 18 lines

In a first version of this patch I had the following included just before the 'return 0':

	pr_info("usb %s: failed to resume: no longer connected\n",
						dev_name(&udev->dev));

Problem with that was that the message got printed twice for each device, once for .resume and once for .complete. Given that the disconnects are reported shortly after anyway, I decided the simpler patch might do just as well.

Cheers,
FJP

drivers/usb/core/driver.c +0 -0
index d0a21a5..97ea69b 100644

drivers/usb/core/driver.c int usb_external_resume_device(struct usb_device *udev, pm_message_t msg) · line 1735

Quoted 9 lines
drivers/usb/core/driver.c +4 -0
@@ -1727,6 +1727,10 @@ int usb_external_resume_device(struct usb_device *udev, pm_message_t msg)
 	status = usb_resume_both(udev, msg);
 	udev->last_busy = jiffies;
 	usb_pm_unlock(udev);
+
+	if (status == -ENODEV)
+		return 0;
+
 	if (status == 0)
 		do_unbind_rebind(udev, DO_REBIND);

Please include a short comment explaining the reason for this test (i.e., that there's no advantage in producing an error message since the regular disconnect messages will be generated shortly).

Or do you think maybe it would be better to move this test up into the PM core? After all, other subsystems will face the same issue. I think that would be the best approach. Yes?

Alan STern

#4 lore raw
In reply to Frans Pop
Quoted 19 lines · Frans Pop

Currently if a laptop is suspended e.g. while docked and then resumed after undocking it, the following errors get generated because the USB hub in the docking station and the devices connected to it are no longer available:
pm_op(): usb_dev_resume+0x0/0x10 returns -19
PM: Device 1-2 failed to resume: error -19
pm_op(): usb_dev_resume+0x0/0x10 returns -19
PM: Device 1-2.2 failed to resume: error -19
pm_op(): usb_dev_resume+0x0/0x10 returns -19
PM: Device 1-2.3 failed to resume: error -19

As the removal of USB devices while a system is suspended is a relatively common use case and in most cases not an error, just return success on -ENODEV. The user gets informed anyway as the USB subsystem generates regular disconnect messages for the devices shortly afterwards:
usb 1-2: USB disconnect, address 3
usb 1-2.2: USB disconnect, address 4
usblp0: removed
usb 1-2.3: USB disconnect, address 5

Quoted 7 lines
Cc Alan Stern <[email protected]>
Cc Rafael J. Wysocki <[email protected]>

---

I've walked through the code and AFAICT just returning 0 does not make any difference for the PM core code.

That's right. After all, there isn't much the PM core can do when an error occurs.

Quoted 18 lines

In a first version of this patch I had the following included just before the 'return 0':

	pr_info("usb %s: failed to resume: no longer connected\n",
						dev_name(&udev->dev));

Problem with that was that the message got printed twice for each device, once for .resume and once for .complete. Given that the disconnects are reported shortly after anyway, I decided the simpler patch might do just as well.

Cheers,
FJP

drivers/usb/core/driver.c +0 -0
index d0a21a5..97ea69b 100644

drivers/usb/core/driver.c int usb_external_resume_device(struct usb_device *udev, pm_message_t msg) · line 1735

Quoted 9 lines
drivers/usb/core/driver.c +4 -0
@@ -1727,6 +1727,10 @@ int usb_external_resume_device(struct usb_device *udev, pm_message_t msg)
 	status = usb_resume_both(udev, msg);
 	udev->last_busy = jiffies;
 	usb_pm_unlock(udev);
+
+	if (status == -ENODEV)
+		return 0;
+
 	if (status == 0)
 		do_unbind_rebind(udev, DO_REBIND);

Please include a short comment explaining the reason for this test (i.e., that there's no advantage in producing an error message since the regular disconnect messages will be generated shortly).

Or do you think maybe it would be better to move this test up into the PM core? After all, other subsystems will face the same issue. I think that would be the best approach. Yes?

Alan STern

author
#5 lore raw
Quoted 10 lines · Alan Stern
Quoted 10 lines
drivers/usb/core/driver.c +2 -0
index d0a21a5..97ea69b 100644
@@ -1727,6 +1727,10 @@ int usb_external_resume_device(struct usb_device *udev, pm_message_t msg)
    status = usb_resume_both(udev, msg);
 	udev->last_busy = jiffies;
 	usb_pm_unlock(udev);
+
+	if (status == -ENODEV)
Quoted 8 lines

drivers/usb/core/driver.c int usb_external_resume_device(struct usb_device *udev, pm_message_t msg) · line 1735

Quoted 4 lines
drivers/usb/core/driver.c +2 -0
+		return 0;
+
 	if (status == 0)
 		do_unbind_rebind(udev, DO_REBIND);

Please include a short comment explaining the reason for this test (i.e., that there's no advantage in producing an error message since the regular disconnect messages will be generated shortly).

Will do if there are no other comments.

Quoted 3 lines

Or do you think maybe it would be better to move this test up into the PM core? After all, other subsystems will face the same issue. I think that would be the best approach. Yes?

I did look at that option, but implementing it in the USB subsystem seemed more logical to me, for example as other subsystems possibly would want to display an info message.

And is -ENODEV safe to ignore in all cases? Would there be other errors that should be ignored too?

if Rafael would be happy with a generic test for -ENODEV, it could be done. If not, maybe some other special error code would need to be used but then you'd still need to test in the subsystem to set that error. Disadvantage is also that it would make resume_device() and related PM driver core functions quite a bit less clean than they currently are.

Implementing the test in USB was quite a bit simpler (for me at least ;-)

Thanks,
FJP

author
#6 lore raw
In reply to Alan Stern
Quoted 10 lines · Alan Stern
Quoted 10 lines
drivers/usb/core/driver.c +2 -0
index d0a21a5..97ea69b 100644
@@ -1727,6 +1727,10 @@ int usb_external_resume_device(struct usb_device *udev, pm_message_t msg)
    status = usb_resume_both(udev, msg);
 	udev->last_busy = jiffies;
 	usb_pm_unlock(udev);
+
+	if (status == -ENODEV)
Quoted 8 lines

drivers/usb/core/driver.c int usb_external_resume_device(struct usb_device *udev, pm_message_t msg) · line 1735

Quoted 4 lines
drivers/usb/core/driver.c +2 -0
+		return 0;
+
 	if (status == 0)
 		do_unbind_rebind(udev, DO_REBIND);

Please include a short comment explaining the reason for this test (i.e., that there's no advantage in producing an error message since the regular disconnect messages will be generated shortly).

Will do if there are no other comments.

Quoted 3 lines

Or do you think maybe it would be better to move this test up into the PM core? After all, other subsystems will face the same issue. I think that would be the best approach. Yes?

I did look at that option, but implementing it in the USB subsystem seemed more logical to me, for example as other subsystems possibly would want to display an info message.

And is -ENODEV safe to ignore in all cases? Would there be other errors that should be ignored too?

if Rafael would be happy with a generic test for -ENODEV, it could be done. If not, maybe some other special error code would need to be used but then you'd still need to test in the subsystem to set that error. Disadvantage is also that it would make resume_device() and related PM driver core functions quite a bit less clean than they currently are.

Implementing the test in USB was quite a bit simpler (for me at least ;-)

Thanks,
FJP

#7 lore raw
Quoted 7 lines · Frans Pop
Quoted 3 lines

Or do you think maybe it would be better to move this test up into the PM core? After all, other subsystems will face the same issue. I think that would be the best approach. Yes?

I did look at that option, but implementing it in the USB subsystem seemed more logical to me, for example as other subsystems possibly would want to display an info message.

They still can...

Quoted 2 lines

And is -ENODEV safe to ignore in all cases? Would there be other errors that should be ignored too?

In general, the PM core ignores _all_ errors during resume -- in the sense that it doesn't try to recover from them or do anything to handle them. All it does is put a message in the log.

So your question becomes: For which errors should a message be added to the system log? The most logical answer seems to be that we want an error message whenever something bad or unexpected occurs.

Removal of a hot-unpluggable device isn't really bad or unexpected. Removal of a non-hot-unpluggable device might be bad, but on the other hand the system isn't really "hot" while it is suspended. Besides, the appropriate subsystem can print an error message. Furthermore the kernel can't easily tell which devices are hot-unpluggable and which aren't.

Anything else amounts to failure resuming a device that still exists. As such, it probably deserves an error message.

Quoted 7 lines

if Rafael would be happy with a generic test for -ENODEV, it could be done. If not, maybe some other special error code would need to be used but then you'd still need to test in the subsystem to set that error. Disadvantage is also that it would make resume_device() and related PM driver core functions quite a bit less clean than they currently are.

Implementing the test in USB was quite a bit simpler (for me at least ;-)

We should get Rafael's opinion.

Alan Stern

#8 lore raw
In reply to Frans Pop
Quoted 7 lines · Frans Pop
Quoted 3 lines

Or do you think maybe it would be better to move this test up into the PM core? After all, other subsystems will face the same issue. I think that would be the best approach. Yes?

I did look at that option, but implementing it in the USB subsystem seemed more logical to me, for example as other subsystems possibly would want to display an info message.

They still can...

Quoted 2 lines

And is -ENODEV safe to ignore in all cases? Would there be other errors that should be ignored too?

In general, the PM core ignores _all_ errors during resume -- in the sense that it doesn't try to recover from them or do anything to handle them. All it does is put a message in the log.

So your question becomes: For which errors should a message be added to the system log? The most logical answer seems to be that we want an error message whenever something bad or unexpected occurs.

Removal of a hot-unpluggable device isn't really bad or unexpected. Removal of a non-hot-unpluggable device might be bad, but on the other hand the system isn't really "hot" while it is suspended. Besides, the appropriate subsystem can print an error message. Furthermore the kernel can't easily tell which devices are hot-unpluggable and which aren't.

Anything else amounts to failure resuming a device that still exists. As such, it probably deserves an error message.

Quoted 7 lines

if Rafael would be happy with a generic test for -ENODEV, it could be done. If not, maybe some other special error code would need to be used but then you'd still need to test in the subsystem to set that error. Disadvantage is also that it would make resume_device() and related PM driver core functions quite a bit less clean than they currently are.

Implementing the test in USB was quite a bit simpler (for me at least ;-)

We should get Rafael's opinion.

Alan Stern

#9 lore raw

First, sorry for the delayed response. Frans has just reminded me about this thread.

Quoted 30 lines · Alan Stern
Quoted 7 lines · Frans Pop
Quoted 3 lines

Or do you think maybe it would be better to move this test up into the PM core? After all, other subsystems will face the same issue. I think that would be the best approach. Yes?

I did look at that option, but implementing it in the USB subsystem seemed more logical to me, for example as other subsystems possibly would want to display an info message.

They still can...

Quoted 2 lines

And is -ENODEV safe to ignore in all cases? Would there be other errors that should be ignored too?

In general, the PM core ignores _all_ errors during resume -- in the sense that it doesn't try to recover from them or do anything to handle them. All it does is put a message in the log.

So your question becomes: For which errors should a message be added to the system log? The most logical answer seems to be that we want an error message whenever something bad or unexpected occurs.

Removal of a hot-unpluggable device isn't really bad or unexpected. Removal of a non-hot-unpluggable device might be bad, but on the other hand the system isn't really "hot" while it is suspended. Besides, the appropriate subsystem can print an error message. Furthermore the kernel can't easily tell which devices are hot-unpluggable and which aren't.

Quoted 2 lines

Anything else amounts to failure resuming a device that still exists. As such, it probably deserves an error message.

Returning 0 from usb_external_resume_device() if the device is not present any more doesn't seem wrong. It's not really an error condition, IMO, because it's rather normal that the devices may be removed while suspended.

OTOH, I don't think we can ignore -ENODEV universally in the core, because its meaning may depend on the bus type. For example, for PCI it sometimes means a hardware problem has occured (other than the device being not present any more).

Quoted 9 lines
Quoted 7 lines

if Rafael would be happy with a generic test for -ENODEV, it could be done. If not, maybe some other special error code would need to be used but then you'd still need to test in the subsystem to set that error. Disadvantage is also that it would make resume_device() and related PM driver core functions quite a bit less clean than they currently are.

Implementing the test in USB was quite a bit simpler (for me at least ;-)

We should get Rafael's opinion.

I'd vote in favor of the Frans' patch, at least for now.

So, Frans, please resubmit with the changelog modified as requested by Alan.

Best,
Rafael

#10 lore raw
In reply to Alan Stern

First, sorry for the delayed response. Frans has just reminded me about this thread.

Quoted 30 lines · Alan Stern
Quoted 7 lines · Frans Pop
Quoted 3 lines

Or do you think maybe it would be better to move this test up into the PM core? After all, other subsystems will face the same issue. I think that would be the best approach. Yes?

I did look at that option, but implementing it in the USB subsystem seemed more logical to me, for example as other subsystems possibly would want to display an info message.

They still can...

Quoted 2 lines

And is -ENODEV safe to ignore in all cases? Would there be other errors that should be ignored too?

In general, the PM core ignores _all_ errors during resume -- in the sense that it doesn't try to recover from them or do anything to handle them. All it does is put a message in the log.

So your question becomes: For which errors should a message be added to the system log? The most logical answer seems to be that we want an error message whenever something bad or unexpected occurs.

Removal of a hot-unpluggable device isn't really bad or unexpected. Removal of a non-hot-unpluggable device might be bad, but on the other hand the system isn't really "hot" while it is suspended. Besides, the appropriate subsystem can print an error message. Furthermore the kernel can't easily tell which devices are hot-unpluggable and which aren't.

Quoted 2 lines

Anything else amounts to failure resuming a device that still exists. As such, it probably deserves an error message.

Returning 0 from usb_external_resume_device() if the device is not present any more doesn't seem wrong. It's not really an error condition, IMO, because it's rather normal that the devices may be removed while suspended.

OTOH, I don't think we can ignore -ENODEV universally in the core, because its meaning may depend on the bus type. For example, for PCI it sometimes means a hardware problem has occured (other than the device being not present any more).

Quoted 9 lines
Quoted 7 lines

if Rafael would be happy with a generic test for -ENODEV, it could be done. If not, maybe some other special error code would need to be used but then you'd still need to test in the subsystem to set that error. Disadvantage is also that it would make resume_device() and related PM driver core functions quite a bit less clean than they currently are.

Implementing the test in USB was quite a bit simpler (for me at least ;-)

We should get Rafael's opinion.

I'd vote in favor of the Frans' patch, at least for now.

So, Frans, please resubmit with the changelog modified as requested by Alan.

Best,
Rafael

#11 lore raw
Quoted 4 lines · Rafael J. Wysocki

Returning 0 from usb_external_resume_device() if the device is not present any more doesn't seem wrong. It's not really an error condition, IMO, because it's rather normal that the devices may be removed while suspended.

Quoted 8 lines

OTOH, I don't think we can ignore -ENODEV universally in the core, because its meaning may depend on the bus type. For example, for PCI it sometimes means a hardware problem has occured (other than the device being not present any more).

I'd vote in favor of the Frans' patch, at least for now.

So, Frans, please resubmit with the changelog modified as requested by Alan.

If we change -ENODEV to 0, the change should be made in usb_resume() rather than usb_external_resume_device().

Alan Stern

#12 lore raw
In reply to Rafael J. Wysocki
Quoted 4 lines · Rafael J. Wysocki

Returning 0 from usb_external_resume_device() if the device is not present any more doesn't seem wrong. It's not really an error condition, IMO, because it's rather normal that the devices may be removed while suspended.

Quoted 8 lines

OTOH, I don't think we can ignore -ENODEV universally in the core, because its meaning may depend on the bus type. For example, for PCI it sometimes means a hardware problem has occured (other than the device being not present any more).

I'd vote in favor of the Frans' patch, at least for now.

So, Frans, please resubmit with the changelog modified as requested by Alan.

If we change -ENODEV to 0, the change should be made in usb_resume() rather than usb_external_resume_device().

Alan Stern

#13 lore raw
In reply to Rafael J. Wysocki
Quoted 4 lines · Rafael J. Wysocki

Returning 0 from usb_external_resume_device() if the device is not present any more doesn't seem wrong. It's not really an error condition, IMO, because it's rather normal that the devices may be removed while suspended.

Quoted 8 lines

OTOH, I don't think we can ignore -ENODEV universally in the core, because its meaning may depend on the bus type. For example, for PCI it sometimes means a hardware problem has occured (other than the device being not present any more).

I'd vote in favor of the Frans' patch, at least for now.

So, Frans, please resubmit with the changelog modified as requested by Alan.

If we change -ENODEV to 0, the change should be made in usb_resume() rather than usb_external_resume_device().

Alan Stern

author
#14 lore raw

PATCH v2 1/1 usb: avoid PM error messages during resume if a device was disconnected

Currently if a laptop is suspended e.g. while docked and then resumed after undocking it, the following errors get generated because the USB hub in the docking station and the devices connected to it are no longer available:
pm_op(): usb_dev_resume+0x0/0x10 returns -19
PM: Device 1-2 failed to resume: error -19
pm_op(): usb_dev_resume+0x0/0x10 returns -19
PM: Device 1-2.2 failed to resume: error -19
pm_op(): usb_dev_resume+0x0/0x10 returns -19
PM: Device 1-2.3 failed to resume: error -19

As the removal of USB devices while a system is suspended is a relatively common use case and in most cases not an error, just return success on -ENODEV. The user gets informed anyway as the USB subsystem generates regular disconnect messages for the devices shortly afterwards:
usb 1-2: USB disconnect, address 3
usb 1-2.2: USB disconnect, address 4
usblp0: removed
usb 1-2.3: USB disconnect, address 5

Cc Alan Stern <[email protected]>
Cc Rafael J. Wysocki <[email protected]>

---

Quoted 2 lines · Alan Stern

If we change -ENODEV to 0, the change should be made in usb_resume() rather than usb_external_resume_device().

Like so?
Agreed that it's cleaner and tested that it works just as well :-)

Cheers,
FJP

drivers/usb/core/driver.c +9 -1
index d0a21a5..0aaf26e 100644
@@ -1762,6 +1762,7 @@ int usb_suspend(struct device *dev, pm_message_t msg)
 int usb_resume(struct device *dev, pm_message_t msg)
 {
 	struct usb_device	*udev;
+	int			status;
 
 	udev = to_usb_device(dev);
 
@@ -1771,7 +1772,14 @@ int usb_resume(struct device *dev, pm_message_t msg)
 	 */
 	if (udev->skip_sys_resume)
 		return 0;
-	return usb_external_resume_device(udev, msg);
+	status = usb_external_resume_device(udev, msg);
+
+	/* Avoid PM error messages for devices disconnected while suspended
+	 * as we'll display regular disconnect messages just a bit later.
+	 */
+	if (status == -ENODEV)
+		return 0;
+	return status;
 }
 
 #endif /* CONFIG_PM */
author
#15 lore raw

PATCH v2 1/1 usb: avoid PM error messages during resume if a device was disconnected

In reply to Alan Stern

Currently if a laptop is suspended e.g. while docked and then resumed after undocking it, the following errors get generated because the USB hub in the docking station and the devices connected to it are no longer available:
pm_op(): usb_dev_resume+0x0/0x10 returns -19
PM: Device 1-2 failed to resume: error -19
pm_op(): usb_dev_resume+0x0/0x10 returns -19
PM: Device 1-2.2 failed to resume: error -19
pm_op(): usb_dev_resume+0x0/0x10 returns -19
PM: Device 1-2.3 failed to resume: error -19

As the removal of USB devices while a system is suspended is a relatively common use case and in most cases not an error, just return success on -ENODEV. The user gets informed anyway as the USB subsystem generates regular disconnect messages for the devices shortly afterwards:
usb 1-2: USB disconnect, address 3
usb 1-2.2: USB disconnect, address 4
usblp0: removed
usb 1-2.3: USB disconnect, address 5

Cc Alan Stern <[email protected]>
Cc Rafael J. Wysocki <[email protected]>

---

Quoted 2 lines · Alan Stern

If we change -ENODEV to 0, the change should be made in usb_resume() rather than usb_external_resume_device().

Like so?
Agreed that it's cleaner and tested that it works just as well :-)

Cheers,
FJP

drivers/usb/core/driver.c +9 -1
index d0a21a5..0aaf26e 100644
@@ -1762,6 +1762,7 @@ int usb_suspend(struct device *dev, pm_message_t msg)
 int usb_resume(struct device *dev, pm_message_t msg)
 {
 	struct usb_device	*udev;
+	int			status;
 
 	udev = to_usb_device(dev);
 
@@ -1771,7 +1772,14 @@ int usb_resume(struct device *dev, pm_message_t msg)
 	 */
 	if (udev->skip_sys_resume)
 		return 0;
-	return usb_external_resume_device(udev, msg);
+	status = usb_external_resume_device(udev, msg);
+
+	/* Avoid PM error messages for devices disconnected while suspended
+	 * as we'll display regular disconnect messages just a bit later.
+	 */
+	if (status == -ENODEV)
+		return 0;
+	return status;
 }
 
 #endif /* CONFIG_PM */
#16 lore raw
Quoted 49 lines · Frans Pop

Currently if a laptop is suspended e.g. while docked and then resumed after undocking it, the following errors get generated because the USB hub in the docking station and the devices connected to it are no longer available:
pm_op(): usb_dev_resume+0x0/0x10 returns -19
PM: Device 1-2 failed to resume: error -19
pm_op(): usb_dev_resume+0x0/0x10 returns -19
PM: Device 1-2.2 failed to resume: error -19
pm_op(): usb_dev_resume+0x0/0x10 returns -19
PM: Device 1-2.3 failed to resume: error -19

As the removal of USB devices while a system is suspended is a relatively common use case and in most cases not an error, just return success on -ENODEV. The user gets informed anyway as the USB subsystem generates regular disconnect messages for the devices shortly afterwards:
usb 1-2: USB disconnect, address 3
usb 1-2.2: USB disconnect, address 4
usblp0: removed
usb 1-2.3: USB disconnect, address 5

Cc Alan Stern <[email protected]>
Cc Rafael J. Wysocki <[email protected]>

---

Quoted 2 lines · Alan Stern

If we change -ENODEV to 0, the change should be made in usb_resume() rather than usb_external_resume_device().

Like so?
Agreed that it's cleaner and tested that it works just as well :-)

Cheers,
FJP

drivers/usb/core/driver.c +1 -0
index d0a21a5..0aaf26e 100644
@@ -1762,6 +1762,7 @@ int usb_suspend(struct device *dev, pm_message_t msg)
 int usb_resume(struct device *dev, pm_message_t msg)
 {
 	struct usb_device	*udev;
+	int			status;
 
 	udev = to_usb_device(dev);
 
@@ -1771,7 +1772,14 @@ int usb_resume(struct device *dev, pm_message_t msg)
 	 */
 	if (udev->skip_sys_resume)

drivers/usb/core/driver.c int usb_resume(struct device *dev, pm_message_t msg) · line 1782

Quoted 10 lines
drivers/usb/core/driver.c +8 -1
 		return 0;
-	return usb_external_resume_device(udev, msg);
+	status = usb_external_resume_device(udev, msg);
+
+	/* Avoid PM error messages for devices disconnected while suspended
+	 * as we'll display regular disconnect messages just a bit later.
+	 */
+	if (status == -ENODEV)
+		return 0;
+	return status;

+ return status == -ENODEV ? 0 : status;

maybe?

drivers/usb/core/driver.c int usb_resume(struct device *dev, pm_message_t msg) · line 1785

Quoted 3 lines
drivers/usb/core/driver.c +0 -0
 }
 
 #endif /* CONFIG_PM */

Best,
Rafael

#17 lore raw
In reply to Frans Pop
Quoted 49 lines · Frans Pop

Currently if a laptop is suspended e.g. while docked and then resumed after undocking it, the following errors get generated because the USB hub in the docking station and the devices connected to it are no longer available:
pm_op(): usb_dev_resume+0x0/0x10 returns -19
PM: Device 1-2 failed to resume: error -19
pm_op(): usb_dev_resume+0x0/0x10 returns -19
PM: Device 1-2.2 failed to resume: error -19
pm_op(): usb_dev_resume+0x0/0x10 returns -19
PM: Device 1-2.3 failed to resume: error -19

As the removal of USB devices while a system is suspended is a relatively common use case and in most cases not an error, just return success on -ENODEV. The user gets informed anyway as the USB subsystem generates regular disconnect messages for the devices shortly afterwards:
usb 1-2: USB disconnect, address 3
usb 1-2.2: USB disconnect, address 4
usblp0: removed
usb 1-2.3: USB disconnect, address 5

Cc Alan Stern <[email protected]>
Cc Rafael J. Wysocki <[email protected]>

---

Quoted 2 lines · Alan Stern

If we change -ENODEV to 0, the change should be made in usb_resume() rather than usb_external_resume_device().

Like so?
Agreed that it's cleaner and tested that it works just as well :-)

Cheers,
FJP

drivers/usb/core/driver.c +1 -0
index d0a21a5..0aaf26e 100644
@@ -1762,6 +1762,7 @@ int usb_suspend(struct device *dev, pm_message_t msg)
 int usb_resume(struct device *dev, pm_message_t msg)
 {
 	struct usb_device	*udev;
+	int			status;
 
 	udev = to_usb_device(dev);
 
@@ -1771,7 +1772,14 @@ int usb_resume(struct device *dev, pm_message_t msg)
 	 */
 	if (udev->skip_sys_resume)

drivers/usb/core/driver.c int usb_resume(struct device *dev, pm_message_t msg) · line 1782

Quoted 10 lines
drivers/usb/core/driver.c +8 -1
 		return 0;
-	return usb_external_resume_device(udev, msg);
+	status = usb_external_resume_device(udev, msg);
+
+	/* Avoid PM error messages for devices disconnected while suspended
+	 * as we'll display regular disconnect messages just a bit later.
+	 */
+	if (status == -ENODEV)
+		return 0;
+	return status;

+ return status == -ENODEV ? 0 : status;

maybe?

drivers/usb/core/driver.c int usb_resume(struct device *dev, pm_message_t msg) · line 1785

Quoted 3 lines
drivers/usb/core/driver.c +0 -0
 }
 
 #endif /* CONFIG_PM */

Best,
Rafael

Acked-by
#18 lore raw
Quoted 9 lines · Rafael J. Wysocki

drivers/usb/core/driver.c int usb_resume(struct device *dev, pm_message_t msg) · line 1782

Quoted 6 lines
drivers/usb/core/driver.c +6 -0
+	/* Avoid PM error messages for devices disconnected while suspended
+	 * as we'll display regular disconnect messages just a bit later.
+	 */
+	if (status == -ENODEV)
+		return 0;
+	return status;

+ return status == -ENODEV ? 0 : status;

Quoted 5 lines

maybe?

Quoted 3 lines

}

#endif /* CONFIG_PM */

Personally, I would do:

	if (status == -ENODEV)
		status = 0;
	return status;

It doesn't make any difference; they are all equally good.

Acked-by
#19 lore raw
In reply to Rafael J. Wysocki
Quoted 9 lines · Rafael J. Wysocki

drivers/usb/core/driver.c int usb_resume(struct device *dev, pm_message_t msg) · line 1782

Quoted 6 lines
drivers/usb/core/driver.c +6 -0
+	/* Avoid PM error messages for devices disconnected while suspended
+	 * as we'll display regular disconnect messages just a bit later.
+	 */
+	if (status == -ENODEV)
+		return 0;
+	return status;

+ return status == -ENODEV ? 0 : status;

Quoted 5 lines

maybe?

Quoted 3 lines

}

#endif /* CONFIG_PM */

Personally, I would do:

	if (status == -ENODEV)
		status = 0;
	return status;

It doesn't make any difference; they are all equally good.

#20 lore raw
Quoted 19 lines · Alan Stern
Quoted 9 lines · Rafael J. Wysocki

drivers/usb/core/driver.c int usb_resume(struct device *dev, pm_message_t msg) · line 1782

Quoted 6 lines
drivers/usb/core/driver.c +6 -0
+	/* Avoid PM error messages for devices disconnected while suspended
+	 * as we'll display regular disconnect messages just a bit later.
+	 */
+	if (status == -ENODEV)
+		return 0;
+	return status;

+ return status == -ENODEV ? 0 : status;

Quoted 5 lines

maybe?

Quoted 3 lines

}

#endif /* CONFIG_PM */

Personally, I would do:

Quoted 7 lines
	if (status == -ENODEV)
		status = 0;
	return status;

It doesn't make any difference; they are all equally good.

OK

Am I supposed to take this patch directly or push it to Greg?

Rafael

#21 lore raw
In reply to Alan Stern
Quoted 19 lines · Alan Stern
Quoted 9 lines · Rafael J. Wysocki

drivers/usb/core/driver.c int usb_resume(struct device *dev, pm_message_t msg) · line 1782

Quoted 6 lines
drivers/usb/core/driver.c +6 -0
+	/* Avoid PM error messages for devices disconnected while suspended
+	 * as we'll display regular disconnect messages just a bit later.
+	 */
+	if (status == -ENODEV)
+		return 0;
+	return status;

+ return status == -ENODEV ? 0 : status;

Quoted 5 lines

maybe?

Quoted 3 lines

}

#endif /* CONFIG_PM */

Personally, I would do:

Quoted 7 lines
	if (status == -ENODEV)
		status = 0;
	return status;

It doesn't make any difference; they are all equally good.

OK

Am I supposed to take this patch directly or push it to Greg?

Rafael