Skip to content

Commit ba91a96

Browse files
geliangtangJiri Kosina
authored andcommitted
HID: add a new helper to_hid_driver()
Add a new helper to_hid_driver() and use it in hid-core.c. Signed-off-by: Geliang Tang <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent ee79a8f commit ba91a96

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

drivers/hid/hid-core.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2077,7 +2077,7 @@ struct hid_dynid {
20772077
static ssize_t store_new_id(struct device_driver *drv, const char *buf,
20782078
size_t count)
20792079
{
2080-
struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver);
2080+
struct hid_driver *hdrv = to_hid_driver(drv);
20812081
struct hid_dynid *dynid;
20822082
__u32 bus, vendor, product;
20832083
unsigned long driver_data = 0;
@@ -2139,16 +2139,15 @@ static const struct hid_device_id *hid_match_device(struct hid_device *hdev,
21392139

21402140
static int hid_bus_match(struct device *dev, struct device_driver *drv)
21412141
{
2142-
struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver);
2142+
struct hid_driver *hdrv = to_hid_driver(drv);
21432143
struct hid_device *hdev = to_hid_device(dev);
21442144

21452145
return hid_match_device(hdev, hdrv) != NULL;
21462146
}
21472147

21482148
static int hid_device_probe(struct device *dev)
21492149
{
2150-
struct hid_driver *hdrv = container_of(dev->driver,
2151-
struct hid_driver, driver);
2150+
struct hid_driver *hdrv = to_hid_driver(dev->driver);
21522151
struct hid_device *hdev = to_hid_device(dev);
21532152
const struct hid_device_id *id;
21542153
int ret = 0;

include/linux/hid.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,9 @@ struct hid_driver {
717717
struct device_driver driver;
718718
};
719719

720+
#define to_hid_driver(pdrv) \
721+
container_of(pdrv, struct hid_driver, driver)
722+
720723
/**
721724
* hid_ll_driver - low level driver callbacks
722725
* @start: called on probe to start the device

0 commit comments

Comments
 (0)