Skip to contentSkip to conversation

USB: imon: avoid needless atomic allocations in resume

PATCH New Oliver Neukum 1 participant 3 messages Apr 28, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 USB: imon: avoid needless atomic allocations in resume

GFP_NOIO is fine here.

---
 drivers/media/rc/imon.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/rc/imon.c +2 -2
index 54da6f60079b..761b7fa57378 100644
@@ -2578,7 +2578,7 @@ static int imon_resume(struct usb_interface *intf)
 			usb_rx_callback_intf0, ictx,
 			ictx->rx_endpoint_intf0->bInterval);
 
-		rc = usb_submit_urb(ictx->rx_urb_intf0, GFP_ATOMIC);
+		rc = usb_submit_urb(ictx->rx_urb_intf0, GFP_NOIO);
 
 	} else {
 		usb_fill_int_urb(ictx->rx_urb_intf1, ictx->usbdev_intf1,
@@ -2588,7 +2588,7 @@ static int imon_resume(struct usb_interface *intf)
 			usb_rx_callback_intf1, ictx,
 			ictx->rx_endpoint_intf1->bInterval);
 
-		rc = usb_submit_urb(ictx->rx_urb_intf1, GFP_ATOMIC);
+		rc = usb_submit_urb(ictx->rx_urb_intf1, GFP_NOIO);
 	}
 
 	return rc;
Signature · 1 line
2.34.1
#1 lore raw

PATCH 2/3 USB: imon: fix timer racing disconnect

The timer will report events for an input device. Reporting events for an unregistered device is bad. Hence the timer must be killed first.

---
 drivers/media/rc/imon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/rc/imon.c +1 -1
index 761b7fa57378..8dbeab48ed3c 100644
@@ -2537,8 +2537,8 @@ static void imon_disconnect(struct usb_interface *interface)
 		usb_kill_urb(ictx->rx_urb_intf1);
 		usb_put_dev(ictx->usbdev_intf1);
 		if (ictx->display_type == IMON_DISPLAY_TYPE_VGA) {
-			input_unregister_device(ictx->touch);
 			del_timer_sync(&ictx->ttimer);
+			input_unregister_device(ictx->touch);
 		}
 	}
 
Signature · 1 line
2.34.1
#2 lore raw

PATCH 3/3 USB: imon: drop references only after device is no longer used

In reply to Oliver Neukum

The point of using get/put_device() is to keep references for as long as the device may be in use. That means dropping them must be the penultimate action right before freeing the memory.

---
 drivers/media/rc/imon.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/rc/imon.c +2 -2
index 8dbeab48ed3c..ad8bca8a8abd 100644
@@ -2523,7 +2523,6 @@ static void imon_disconnect(struct usb_interface *interface)
 	if (ifnum == 0) {
 		ictx->dev_present_intf0 = false;
 		usb_kill_urb(ictx->rx_urb_intf0);
-		usb_put_dev(ictx->usbdev_intf0);
 		input_unregister_device(ictx->idev);
 		rc_unregister_device(ictx->rdev);
 		if (ictx->display_supported) {
@@ -2532,14 +2531,15 @@ static void imon_disconnect(struct usb_interface *interface)
 			else if (ictx->display_type == IMON_DISPLAY_TYPE_VFD)
 				usb_deregister_dev(interface, &imon_vfd_class);
 		}
+		usb_put_dev(ictx->usbdev_intf0);
 	} else {
 		ictx->dev_present_intf1 = false;
 		usb_kill_urb(ictx->rx_urb_intf1);
-		usb_put_dev(ictx->usbdev_intf1);
 		if (ictx->display_type == IMON_DISPLAY_TYPE_VGA) {
 			del_timer_sync(&ictx->ttimer);
 			input_unregister_device(ictx->touch);
 		}
+		usb_put_dev(ictx->usbdev_intf1);
 	}
 
 	if (!ictx->dev_present_intf0 && !ictx->dev_present_intf1)
Signature · 1 line
2.34.1