Skip to content

Commit ee79a8f

Browse files
geliangtangJiri Kosina
authored andcommitted
HID: use to_hid_device()
Use to_hid_device() instead of container_of(). Signed-off-by: Geliang Tang <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent d8ce9bf commit ee79a8f

13 files changed

+76
-79
lines changed

drivers/hid/hid-core.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ static void hid_close_report(struct hid_device *device)
625625

626626
static void hid_device_release(struct device *dev)
627627
{
628-
struct hid_device *hid = container_of(dev, struct hid_device, dev);
628+
struct hid_device *hid = to_hid_device(dev);
629629

630630
hid_close_report(hid);
631631
kfree(hid->dev_rdesc);
@@ -1572,7 +1572,7 @@ read_report_descriptor(struct file *filp, struct kobject *kobj,
15721572
char *buf, loff_t off, size_t count)
15731573
{
15741574
struct device *dev = container_of(kobj, struct device, kobj);
1575-
struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1575+
struct hid_device *hdev = to_hid_device(dev);
15761576

15771577
if (off >= hdev->rsize)
15781578
return 0;
@@ -1589,7 +1589,7 @@ static ssize_t
15891589
show_country(struct device *dev, struct device_attribute *attr,
15901590
char *buf)
15911591
{
1592-
struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1592+
struct hid_device *hdev = to_hid_device(dev);
15931593

15941594
return sprintf(buf, "%02x\n", hdev->country & 0xff);
15951595
}
@@ -2140,7 +2140,7 @@ static const struct hid_device_id *hid_match_device(struct hid_device *hdev,
21402140
static int hid_bus_match(struct device *dev, struct device_driver *drv)
21412141
{
21422142
struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver);
2143-
struct hid_device *hdev = container_of(dev, struct hid_device, dev);
2143+
struct hid_device *hdev = to_hid_device(dev);
21442144

21452145
return hid_match_device(hdev, hdrv) != NULL;
21462146
}
@@ -2149,7 +2149,7 @@ static int hid_device_probe(struct device *dev)
21492149
{
21502150
struct hid_driver *hdrv = container_of(dev->driver,
21512151
struct hid_driver, driver);
2152-
struct hid_device *hdev = container_of(dev, struct hid_device, dev);
2152+
struct hid_device *hdev = to_hid_device(dev);
21532153
const struct hid_device_id *id;
21542154
int ret = 0;
21552155

@@ -2191,7 +2191,7 @@ static int hid_device_probe(struct device *dev)
21912191

21922192
static int hid_device_remove(struct device *dev)
21932193
{
2194-
struct hid_device *hdev = container_of(dev, struct hid_device, dev);
2194+
struct hid_device *hdev = to_hid_device(dev);
21952195
struct hid_driver *hdrv;
21962196
int ret = 0;
21972197

@@ -2241,7 +2241,7 @@ ATTRIBUTE_GROUPS(hid_dev);
22412241

22422242
static int hid_uevent(struct device *dev, struct kobj_uevent_env *env)
22432243
{
2244-
struct hid_device *hdev = container_of(dev, struct hid_device, dev);
2244+
struct hid_device *hdev = to_hid_device(dev);
22452245

22462246
if (add_uevent_var(env, "HID_ID=%04X:%08X:%08X",
22472247
hdev->bus, hdev->vendor, hdev->product))

drivers/hid/hid-cp2112.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ static ssize_t name##_store(struct device *kdev, \
807807
struct device_attribute *attr, const char *buf, \
808808
size_t count) \
809809
{ \
810-
struct hid_device *hdev = container_of(kdev, struct hid_device, dev); \
810+
struct hid_device *hdev = to_hid_device(kdev); \
811811
struct cp2112_usb_config_report cfg; \
812812
int ret = cp2112_get_usb_config(hdev, &cfg); \
813813
if (ret) \
@@ -822,7 +822,7 @@ static ssize_t name##_store(struct device *kdev, \
822822
static ssize_t name##_show(struct device *kdev, \
823823
struct device_attribute *attr, char *buf) \
824824
{ \
825-
struct hid_device *hdev = container_of(kdev, struct hid_device, dev); \
825+
struct hid_device *hdev = to_hid_device(kdev); \
826826
struct cp2112_usb_config_report cfg; \
827827
int ret = cp2112_get_usb_config(hdev, &cfg); \
828828
if (ret) \
@@ -887,7 +887,7 @@ static ssize_t pstr_store(struct device *kdev,
887887
struct device_attribute *kattr, const char *buf,
888888
size_t count)
889889
{
890-
struct hid_device *hdev = container_of(kdev, struct hid_device, dev);
890+
struct hid_device *hdev = to_hid_device(kdev);
891891
struct cp2112_pstring_attribute *attr =
892892
container_of(kattr, struct cp2112_pstring_attribute, attr);
893893
struct cp2112_string_report report;
@@ -918,7 +918,7 @@ static ssize_t pstr_store(struct device *kdev,
918918
static ssize_t pstr_show(struct device *kdev,
919919
struct device_attribute *kattr, char *buf)
920920
{
921-
struct hid_device *hdev = container_of(kdev, struct hid_device, dev);
921+
struct hid_device *hdev = to_hid_device(kdev);
922922
struct cp2112_pstring_attribute *attr =
923923
container_of(kattr, struct cp2112_pstring_attribute, attr);
924924
struct cp2112_string_report report;

drivers/hid/hid-gt683r.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static void gt683r_brightness_set(struct led_classdev *led_cdev,
7070
{
7171
int i;
7272
struct device *dev = led_cdev->dev->parent;
73-
struct hid_device *hdev = container_of(dev, struct hid_device, dev);
73+
struct hid_device *hdev = to_hid_device(dev);
7474
struct gt683r_led *led = hid_get_drvdata(hdev);
7575

7676
for (i = 0; i < GT683R_LED_COUNT; i++) {
@@ -89,8 +89,7 @@ static ssize_t mode_show(struct device *dev,
8989
char *buf)
9090
{
9191
u8 sysfs_mode;
92-
struct hid_device *hdev = container_of(dev->parent,
93-
struct hid_device, dev);
92+
struct hid_device *hdev = to_hid_device(dev->parent);
9493
struct gt683r_led *led = hid_get_drvdata(hdev);
9594

9695
if (led->mode == GT683R_LED_NORMAL)
@@ -108,8 +107,7 @@ static ssize_t mode_store(struct device *dev,
108107
const char *buf, size_t count)
109108
{
110109
u8 sysfs_mode;
111-
struct hid_device *hdev = container_of(dev->parent,
112-
struct hid_device, dev);
110+
struct hid_device *hdev = to_hid_device(dev->parent);
113111
struct gt683r_led *led = hid_get_drvdata(hdev);
114112

115113

drivers/hid/hid-lenovo.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ static ssize_t attr_fn_lock_show_cptkbd(struct device *dev,
220220
struct device_attribute *attr,
221221
char *buf)
222222
{
223-
struct hid_device *hdev = container_of(dev, struct hid_device, dev);
223+
struct hid_device *hdev = to_hid_device(dev);
224224
struct lenovo_drvdata_cptkbd *cptkbd_data = hid_get_drvdata(hdev);
225225

226226
return snprintf(buf, PAGE_SIZE, "%u\n", cptkbd_data->fn_lock);
@@ -231,7 +231,7 @@ static ssize_t attr_fn_lock_store_cptkbd(struct device *dev,
231231
const char *buf,
232232
size_t count)
233233
{
234-
struct hid_device *hdev = container_of(dev, struct hid_device, dev);
234+
struct hid_device *hdev = to_hid_device(dev);
235235
struct lenovo_drvdata_cptkbd *cptkbd_data = hid_get_drvdata(hdev);
236236
int value;
237237

@@ -250,7 +250,7 @@ static ssize_t attr_sensitivity_show_cptkbd(struct device *dev,
250250
struct device_attribute *attr,
251251
char *buf)
252252
{
253-
struct hid_device *hdev = container_of(dev, struct hid_device, dev);
253+
struct hid_device *hdev = to_hid_device(dev);
254254
struct lenovo_drvdata_cptkbd *cptkbd_data = hid_get_drvdata(hdev);
255255

256256
return snprintf(buf, PAGE_SIZE, "%u\n",
@@ -262,7 +262,7 @@ static ssize_t attr_sensitivity_store_cptkbd(struct device *dev,
262262
const char *buf,
263263
size_t count)
264264
{
265-
struct hid_device *hdev = container_of(dev, struct hid_device, dev);
265+
struct hid_device *hdev = to_hid_device(dev);
266266
struct lenovo_drvdata_cptkbd *cptkbd_data = hid_get_drvdata(hdev);
267267
int value;
268268

@@ -387,7 +387,7 @@ static ssize_t attr_press_to_select_show_tpkbd(struct device *dev,
387387
struct device_attribute *attr,
388388
char *buf)
389389
{
390-
struct hid_device *hdev = container_of(dev, struct hid_device, dev);
390+
struct hid_device *hdev = to_hid_device(dev);
391391
struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
392392

393393
return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->press_to_select);
@@ -398,7 +398,7 @@ static ssize_t attr_press_to_select_store_tpkbd(struct device *dev,
398398
const char *buf,
399399
size_t count)
400400
{
401-
struct hid_device *hdev = container_of(dev, struct hid_device, dev);
401+
struct hid_device *hdev = to_hid_device(dev);
402402
struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
403403
int value;
404404

@@ -417,7 +417,7 @@ static ssize_t attr_dragging_show_tpkbd(struct device *dev,
417417
struct device_attribute *attr,
418418
char *buf)
419419
{
420-
struct hid_device *hdev = container_of(dev, struct hid_device, dev);
420+
struct hid_device *hdev = to_hid_device(dev);
421421
struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
422422

423423
return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->dragging);
@@ -428,7 +428,7 @@ static ssize_t attr_dragging_store_tpkbd(struct device *dev,
428428
const char *buf,
429429
size_t count)
430430
{
431-
struct hid_device *hdev = container_of(dev, struct hid_device, dev);
431+
struct hid_device *hdev = to_hid_device(dev);
432432
struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
433433
int value;
434434

@@ -447,7 +447,7 @@ static ssize_t attr_release_to_select_show_tpkbd(struct device *dev,
447447
struct device_attribute *attr,
448448
char *buf)
449449
{
450-
struct hid_device *hdev = container_of(dev, struct hid_device, dev);
450+
struct hid_device *hdev = to_hid_device(dev);
451451
struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
452452

453453
return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->release_to_select);
@@ -458,7 +458,7 @@ static ssize_t attr_release_to_select_store_tpkbd(struct device *dev,
458458
const char *buf,
459459
size_t count)
460460
{
461-
struct hid_device *hdev = container_of(dev, struct hid_device, dev);
461+
struct hid_device *hdev = to_hid_device(dev);
462462
struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
463463
int value;
464464

@@ -477,7 +477,7 @@ static ssize_t attr_select_right_show_tpkbd(struct device *dev,
477477
struct device_attribute *attr,
478478
char *buf)
479479
{
480-
struct hid_device *hdev = container_of(dev, struct hid_device, dev);
480+
struct hid_device *hdev = to_hid_device(dev);
481481
struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
482482

483483
return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->select_right);
@@ -488,7 +488,7 @@ static ssize_t attr_select_right_store_tpkbd(struct device *dev,
488488
const char *buf,
489489
size_t count)
490490
{
491-
struct hid_device *hdev = container_of(dev, struct hid_device, dev);
491+
struct hid_device *hdev = to_hid_device(dev);
492492
struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
493493
int value;
494494

@@ -507,7 +507,7 @@ static ssize_t attr_sensitivity_show_tpkbd(struct device *dev,
507507
struct device_attribute *attr,
508508
char *buf)
509509
{
510-
struct hid_device *hdev = container_of(dev, struct hid_device, dev);
510+
struct hid_device *hdev = to_hid_device(dev);
511511
struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
512512

513513
return snprintf(buf, PAGE_SIZE, "%u\n",
@@ -519,7 +519,7 @@ static ssize_t attr_sensitivity_store_tpkbd(struct device *dev,
519519
const char *buf,
520520
size_t count)
521521
{
522-
struct hid_device *hdev = container_of(dev, struct hid_device, dev);
522+
struct hid_device *hdev = to_hid_device(dev);
523523
struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
524524
int value;
525525

@@ -536,7 +536,7 @@ static ssize_t attr_press_speed_show_tpkbd(struct device *dev,
536536
struct device_attribute *attr,
537537
char *buf)
538538
{
539-
struct hid_device *hdev = container_of(dev, struct hid_device, dev);
539+
struct hid_device *hdev = to_hid_device(dev);
540540
struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
541541

542542
return snprintf(buf, PAGE_SIZE, "%u\n",
@@ -548,7 +548,7 @@ static ssize_t attr_press_speed_store_tpkbd(struct device *dev,
548548
const char *buf,
549549
size_t count)
550550
{
551-
struct hid_device *hdev = container_of(dev, struct hid_device, dev);
551+
struct hid_device *hdev = to_hid_device(dev);
552552
struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
553553
int value;
554554

@@ -609,7 +609,7 @@ static enum led_brightness lenovo_led_brightness_get_tpkbd(
609609
struct led_classdev *led_cdev)
610610
{
611611
struct device *dev = led_cdev->dev->parent;
612-
struct hid_device *hdev = container_of(dev, struct hid_device, dev);
612+
struct hid_device *hdev = to_hid_device(dev);
613613
struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
614614
int led_nr = 0;
615615

@@ -625,7 +625,7 @@ static void lenovo_led_brightness_set_tpkbd(struct led_classdev *led_cdev,
625625
enum led_brightness value)
626626
{
627627
struct device *dev = led_cdev->dev->parent;
628-
struct hid_device *hdev = container_of(dev, struct hid_device, dev);
628+
struct hid_device *hdev = to_hid_device(dev);
629629
struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
630630
struct hid_report *report;
631631
int led_nr = 0;

drivers/hid/hid-lg4ff.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,7 @@ static void lg4ff_led_set_brightness(struct led_classdev *led_cdev,
10181018
enum led_brightness value)
10191019
{
10201020
struct device *dev = led_cdev->dev->parent;
1021-
struct hid_device *hid = container_of(dev, struct hid_device, dev);
1021+
struct hid_device *hid = to_hid_device(dev);
10221022
struct lg_drv_data *drv_data = hid_get_drvdata(hid);
10231023
struct lg4ff_device_entry *entry;
10241024
int i, state = 0;
@@ -1053,7 +1053,7 @@ static void lg4ff_led_set_brightness(struct led_classdev *led_cdev,
10531053
static enum led_brightness lg4ff_led_get_brightness(struct led_classdev *led_cdev)
10541054
{
10551055
struct device *dev = led_cdev->dev->parent;
1056-
struct hid_device *hid = container_of(dev, struct hid_device, dev);
1056+
struct hid_device *hid = to_hid_device(dev);
10571057
struct lg_drv_data *drv_data = hid_get_drvdata(hid);
10581058
struct lg4ff_device_entry *entry;
10591059
int i, value = 0;

drivers/hid/hid-multitouch.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ static ssize_t mt_show_quirks(struct device *dev,
272272
struct device_attribute *attr,
273273
char *buf)
274274
{
275-
struct hid_device *hdev = container_of(dev, struct hid_device, dev);
275+
struct hid_device *hdev = to_hid_device(dev);
276276
struct mt_device *td = hid_get_drvdata(hdev);
277277

278278
return sprintf(buf, "%u\n", td->mtclass.quirks);
@@ -282,7 +282,7 @@ static ssize_t mt_set_quirks(struct device *dev,
282282
struct device_attribute *attr,
283283
const char *buf, size_t count)
284284
{
285-
struct hid_device *hdev = container_of(dev, struct hid_device, dev);
285+
struct hid_device *hdev = to_hid_device(dev);
286286
struct mt_device *td = hid_get_drvdata(hdev);
287287

288288
unsigned long val;

0 commit comments

Comments
 (0)