Skip to content

Commit c17a747

Browse files
bentissJiri Kosina
authored andcommitted
HID: core: rewrite the hid-generic automatic unbind
We actually can have the unbind/rebind logic in hid-core.c, leaving only the match function in hid-generic. This makes hid-generic simpler and the whole logic simpler too. Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
1 parent 001fab4 commit c17a747

File tree

3 files changed

+24
-48
lines changed

3 files changed

+24
-48
lines changed

drivers/hid/hid-core.c

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2197,31 +2197,40 @@ void hid_destroy_device(struct hid_device *hdev)
21972197
EXPORT_SYMBOL_GPL(hid_destroy_device);
21982198

21992199

2200-
static int __bus_add_driver(struct device_driver *drv, void *data)
2200+
static int __hid_bus_reprobe_drivers(struct device *dev, void *data)
22012201
{
2202-
struct hid_driver *added_hdrv = data;
2203-
struct hid_driver *hdrv = to_hid_driver(drv);
2202+
struct hid_driver *hdrv = data;
2203+
struct hid_device *hdev = to_hid_device(dev);
22042204

2205-
if (hdrv->bus_add_driver)
2206-
hdrv->bus_add_driver(added_hdrv);
2205+
if (hdev->driver == hdrv &&
2206+
!hdrv->match(hdev, hid_ignore_special_drivers))
2207+
return device_reprobe(dev);
22072208

22082209
return 0;
22092210
}
22102211

2211-
static int __bus_removed_driver(struct device_driver *drv, void *data)
2212+
static int __hid_bus_driver_added(struct device_driver *drv, void *data)
22122213
{
2213-
struct hid_driver *removed_hdrv = data;
22142214
struct hid_driver *hdrv = to_hid_driver(drv);
22152215

2216-
if (hdrv->bus_removed_driver)
2217-
hdrv->bus_removed_driver(removed_hdrv);
2216+
if (hdrv->match) {
2217+
bus_for_each_dev(&hid_bus_type, NULL, hdrv,
2218+
__hid_bus_reprobe_drivers);
2219+
}
22182220

22192221
return 0;
22202222
}
22212223

2224+
static int __bus_removed_driver(struct device_driver *drv, void *data)
2225+
{
2226+
return bus_rescan_devices(&hid_bus_type);
2227+
}
2228+
22222229
int __hid_register_driver(struct hid_driver *hdrv, struct module *owner,
22232230
const char *mod_name)
22242231
{
2232+
int ret;
2233+
22252234
hdrv->driver.name = hdrv->name;
22262235
hdrv->driver.bus = &hid_bus_type;
22272236
hdrv->driver.owner = owner;
@@ -2230,9 +2239,13 @@ int __hid_register_driver(struct hid_driver *hdrv, struct module *owner,
22302239
INIT_LIST_HEAD(&hdrv->dyn_list);
22312240
spin_lock_init(&hdrv->dyn_lock);
22322241

2233-
bus_for_each_drv(&hid_bus_type, NULL, hdrv, __bus_add_driver);
2242+
ret = driver_register(&hdrv->driver);
2243+
2244+
if (ret == 0)
2245+
bus_for_each_drv(&hid_bus_type, NULL, NULL,
2246+
__hid_bus_driver_added);
22342247

2235-
return driver_register(&hdrv->driver);
2248+
return ret;
22362249
}
22372250
EXPORT_SYMBOL_GPL(__hid_register_driver);
22382251

drivers/hid/hid-generic.c

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -26,37 +26,6 @@
2626

2727
static struct hid_driver hid_generic;
2828

29-
static int __unmap_hid_generic(struct device *dev, void *data)
30-
{
31-
struct hid_driver *hdrv = data;
32-
struct hid_device *hdev = to_hid_device(dev);
33-
34-
/* only unbind matching devices already bound to hid-generic */
35-
if (hdev->driver != &hid_generic ||
36-
hid_match_device(hdev, hdrv) == NULL)
37-
return 0;
38-
39-
if (dev->parent) /* Needed for USB */
40-
device_lock(dev->parent);
41-
device_release_driver(dev);
42-
if (dev->parent)
43-
device_unlock(dev->parent);
44-
45-
return 0;
46-
}
47-
48-
static void hid_generic_add_driver(struct hid_driver *hdrv)
49-
{
50-
bus_for_each_dev(&hid_bus_type, NULL, hdrv, __unmap_hid_generic);
51-
}
52-
53-
static void hid_generic_removed_driver(struct hid_driver *hdrv)
54-
{
55-
int ret;
56-
57-
ret = driver_attach(&hid_generic.driver);
58-
}
59-
6029
static int __check_hid_generic(struct device_driver *drv, void *data)
6130
{
6231
struct hid_driver *hdrv = to_hid_driver(drv);
@@ -97,8 +66,6 @@ static struct hid_driver hid_generic = {
9766
.name = "hid-generic",
9867
.id_table = hid_table,
9968
.match = hid_generic_match,
100-
.bus_add_driver = hid_generic_add_driver,
101-
.bus_removed_driver = hid_generic_removed_driver,
10269
};
10370
module_hid_driver(hid_generic);
10471

include/linux/hid.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -686,8 +686,6 @@ struct hid_usage_id {
686686
* @input_mapped: invoked on input registering after mapping an usage
687687
* @input_configured: invoked just before the device is registered
688688
* @feature_mapping: invoked on feature registering
689-
* @bus_add_driver: invoked when a HID driver is about to be added
690-
* @bus_removed_driver: invoked when a HID driver has been removed
691689
* @suspend: invoked on suspend (NULL means nop)
692690
* @resume: invoked on resume if device was not reset (NULL means nop)
693691
* @reset_resume: invoked on resume if device was reset (NULL means nop)
@@ -742,8 +740,6 @@ struct hid_driver {
742740
void (*feature_mapping)(struct hid_device *hdev,
743741
struct hid_field *field,
744742
struct hid_usage *usage);
745-
void (*bus_add_driver)(struct hid_driver *driver);
746-
void (*bus_removed_driver)(struct hid_driver *driver);
747743
#ifdef CONFIG_PM
748744
int (*suspend)(struct hid_device *hdev, pm_message_t message);
749745
int (*resume)(struct hid_device *hdev);

0 commit comments

Comments
 (0)