@@ -2587,64 +2587,71 @@ bool hid_compare_device_paths(struct hid_device *hdev_a,
2587
2587
}
2588
2588
EXPORT_SYMBOL_GPL (hid_compare_device_paths );
2589
2589
2590
+ static bool hid_check_device_match (struct hid_device * hdev ,
2591
+ struct hid_driver * hdrv ,
2592
+ const struct hid_device_id * * id )
2593
+ {
2594
+ * id = hid_match_device (hdev , hdrv );
2595
+ if (!* id )
2596
+ return - ENODEV ;
2597
+
2598
+ if (hdrv -> match )
2599
+ return hdrv -> match (hdev , hid_ignore_special_drivers );
2600
+
2601
+ /*
2602
+ * hid-generic implements .match(), so we must be dealing with a
2603
+ * different HID driver here, and can simply check if
2604
+ * hid_ignore_special_drivers is set or not.
2605
+ */
2606
+ return !hid_ignore_special_drivers ;
2607
+ }
2608
+
2609
+ static int __hid_device_probe (struct hid_device * hdev , struct hid_driver * hdrv )
2610
+ {
2611
+ const struct hid_device_id * id ;
2612
+ int ret ;
2613
+
2614
+ if (!hid_check_device_match (hdev , hdrv , & id ))
2615
+ return - ENODEV ;
2616
+
2617
+ /* reset the quirks that has been previously set */
2618
+ hdev -> quirks = hid_lookup_quirk (hdev );
2619
+ hdev -> driver = hdrv ;
2620
+
2621
+ if (hdrv -> probe ) {
2622
+ ret = hdrv -> probe (hdev , id );
2623
+ } else { /* default probe */
2624
+ ret = hid_open_report (hdev );
2625
+ if (!ret )
2626
+ ret = hid_hw_start (hdev , HID_CONNECT_DEFAULT );
2627
+ }
2628
+
2629
+ if (ret ) {
2630
+ hid_close_report (hdev );
2631
+ hdev -> driver = NULL ;
2632
+ }
2633
+
2634
+ return ret ;
2635
+ }
2636
+
2590
2637
static int hid_device_probe (struct device * dev )
2591
2638
{
2592
- struct hid_driver * hdrv = to_hid_driver (dev -> driver );
2593
2639
struct hid_device * hdev = to_hid_device (dev );
2594
- const struct hid_device_id * id ;
2640
+ struct hid_driver * hdrv = to_hid_driver ( dev -> driver ) ;
2595
2641
int ret = 0 ;
2596
2642
2597
- if (down_interruptible (& hdev -> driver_input_lock )) {
2598
- ret = - EINTR ;
2599
- goto end ;
2600
- }
2601
- hdev -> io_started = false;
2643
+ if (down_interruptible (& hdev -> driver_input_lock ))
2644
+ return - EINTR ;
2602
2645
2646
+ hdev -> io_started = false;
2603
2647
clear_bit (ffs (HID_STAT_REPROBED ), & hdev -> status );
2604
2648
2605
- if (!hdev -> driver ) {
2606
- id = hid_match_device (hdev , hdrv );
2607
- if (id == NULL ) {
2608
- ret = - ENODEV ;
2609
- goto unlock ;
2610
- }
2649
+ if (!hdev -> driver )
2650
+ ret = __hid_device_probe (hdev , hdrv );
2611
2651
2612
- if (hdrv -> match ) {
2613
- if (!hdrv -> match (hdev , hid_ignore_special_drivers )) {
2614
- ret = - ENODEV ;
2615
- goto unlock ;
2616
- }
2617
- } else {
2618
- /*
2619
- * hid-generic implements .match(), so if
2620
- * hid_ignore_special_drivers is set, we can safely
2621
- * return.
2622
- */
2623
- if (hid_ignore_special_drivers ) {
2624
- ret = - ENODEV ;
2625
- goto unlock ;
2626
- }
2627
- }
2628
-
2629
- /* reset the quirks that has been previously set */
2630
- hdev -> quirks = hid_lookup_quirk (hdev );
2631
- hdev -> driver = hdrv ;
2632
- if (hdrv -> probe ) {
2633
- ret = hdrv -> probe (hdev , id );
2634
- } else { /* default probe */
2635
- ret = hid_open_report (hdev );
2636
- if (!ret )
2637
- ret = hid_hw_start (hdev , HID_CONNECT_DEFAULT );
2638
- }
2639
- if (ret ) {
2640
- hid_close_report (hdev );
2641
- hdev -> driver = NULL ;
2642
- }
2643
- }
2644
- unlock :
2645
2652
if (!hdev -> io_started )
2646
2653
up (& hdev -> driver_input_lock );
2647
- end :
2654
+
2648
2655
return ret ;
2649
2656
}
2650
2657
0 commit comments