Skip to contentSkip to conversation

How to learn a device is open

DISCUSSION Oliver Neukum 2 participants 2 messages Nov 25, 2009 HID

lore
Share & tools
lore
#0 lore raw

Hi,

I need a way to determine whether an input device has been opened. A private flag seems wasteful. Is this an acceptable method?

Regards
Oliver

+static int usbtouch_resume(struct usb_interface *intf) +{

+       struct usbtouch_usb *usbtouch = usb_get_intfdata(intf);
+       struct input_dev *input = usbtouch->input;
+       int result = 0;

+
+ mutex_lock(&input->mutex);
+ if (input->users)
+ result = usb_submit_urb(usbtouch->irq, GFP_NOIO);
+ mutex_unlock(&input->mutex);
+ return result;
+}

#1 lore raw

Hi Oliver,

Quoted 5 lines · Oliver Neukum

Hi,

I need a way to determine whether an input device has been opened. A private flag seems wasteful. Is this an acceptable method?

Yes, I thhink it is reasonable. I really don't think that adding a wrapper for input->mutex worth it but I would not oppose adding one either.

Quoted 16 lines

Regards
Oliver

(quoted diff) +12 -0
+static int usbtouch_resume(struct usb_interface *intf)
+{
+       struct usbtouch_usb *usbtouch = usb_get_intfdata(intf);
+       struct input_dev *input = usbtouch->input;
+       int result = 0;
+
+       mutex_lock(&input->mutex);
+       if (input->users)
+               result = usb_submit_urb(usbtouch->irq, GFP_NOIO);
+       mutex_unlock(&input->mutex);
+       return result;
+}
Signature · 1 line
Dmitry