Skip to content

Commit 2cf8383

Browse files
geliangtangJiri Kosina
authored andcommitted
HID: use kobj_to_dev()
Use kobj_to_dev() instead of open-coding it. Signed-off-by: Geliang Tang <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent d98ba98 commit 2cf8383

10 files changed

+28
-51
lines changed

drivers/hid/hid-core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1571,7 +1571,7 @@ read_report_descriptor(struct file *filp, struct kobject *kobj,
15711571
struct bin_attribute *attr,
15721572
char *buf, loff_t off, size_t count)
15731573
{
1574-
struct device *dev = container_of(kobj, struct device, kobj);
1574+
struct device *dev = kobj_to_dev(kobj);
15751575
struct hid_device *hdev = to_hid_device(dev);
15761576

15771577
if (off >= hdev->rsize)

drivers/hid/hid-roccat-arvo.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,7 @@ static ssize_t arvo_sysfs_write(struct file *fp,
191191
struct kobject *kobj, void const *buf,
192192
loff_t off, size_t count, size_t real_size, uint command)
193193
{
194-
struct device *dev =
195-
container_of(kobj, struct device, kobj)->parent->parent;
194+
struct device *dev = kobj_to_dev(kobj)->parent->parent;
196195
struct arvo_device *arvo = hid_get_drvdata(dev_get_drvdata(dev));
197196
struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
198197
int retval;
@@ -211,8 +210,7 @@ static ssize_t arvo_sysfs_read(struct file *fp,
211210
struct kobject *kobj, void *buf, loff_t off,
212211
size_t count, size_t real_size, uint command)
213212
{
214-
struct device *dev =
215-
container_of(kobj, struct device, kobj)->parent->parent;
213+
struct device *dev = kobj_to_dev(kobj)->parent->parent;
216214
struct arvo_device *arvo = hid_get_drvdata(dev_get_drvdata(dev));
217215
struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
218216
int retval;

drivers/hid/hid-roccat-common.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@ ssize_t roccat_common2_sysfs_read(struct file *fp, struct kobject *kobj,
134134
char *buf, loff_t off, size_t count,
135135
size_t real_size, uint command)
136136
{
137-
struct device *dev =
138-
container_of(kobj, struct device, kobj)->parent->parent;
137+
struct device *dev = kobj_to_dev(kobj)->parent->parent;
139138
struct roccat_common2_device *roccat_dev = hid_get_drvdata(dev_get_drvdata(dev));
140139
struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
141140
int retval;
@@ -158,8 +157,7 @@ ssize_t roccat_common2_sysfs_write(struct file *fp, struct kobject *kobj,
158157
void const *buf, loff_t off, size_t count,
159158
size_t real_size, uint command)
160159
{
161-
struct device *dev =
162-
container_of(kobj, struct device, kobj)->parent->parent;
160+
struct device *dev = kobj_to_dev(kobj)->parent->parent;
163161
struct roccat_common2_device *roccat_dev = hid_get_drvdata(dev_get_drvdata(dev));
164162
struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
165163
int retval;

drivers/hid/hid-roccat-isku.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,7 @@ static ssize_t isku_sysfs_read(struct file *fp, struct kobject *kobj,
121121
char *buf, loff_t off, size_t count,
122122
size_t real_size, uint command)
123123
{
124-
struct device *dev =
125-
container_of(kobj, struct device, kobj)->parent->parent;
124+
struct device *dev = kobj_to_dev(kobj)->parent->parent;
126125
struct isku_device *isku = hid_get_drvdata(dev_get_drvdata(dev));
127126
struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
128127
int retval;
@@ -144,8 +143,7 @@ static ssize_t isku_sysfs_write(struct file *fp, struct kobject *kobj,
144143
void const *buf, loff_t off, size_t count,
145144
size_t real_size, uint command)
146145
{
147-
struct device *dev =
148-
container_of(kobj, struct device, kobj)->parent->parent;
146+
struct device *dev = kobj_to_dev(kobj)->parent->parent;
149147
struct isku_device *isku = hid_get_drvdata(dev_get_drvdata(dev));
150148
struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
151149
int retval;

drivers/hid/hid-roccat-kone.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,7 @@ static int kone_get_firmware_version(struct usb_device *usb_dev, int *result)
269269
static ssize_t kone_sysfs_read_settings(struct file *fp, struct kobject *kobj,
270270
struct bin_attribute *attr, char *buf,
271271
loff_t off, size_t count) {
272-
struct device *dev =
273-
container_of(kobj, struct device, kobj)->parent->parent;
272+
struct device *dev = kobj_to_dev(kobj)->parent->parent;
274273
struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev));
275274

276275
if (off >= sizeof(struct kone_settings))
@@ -294,8 +293,7 @@ static ssize_t kone_sysfs_read_settings(struct file *fp, struct kobject *kobj,
294293
static ssize_t kone_sysfs_write_settings(struct file *fp, struct kobject *kobj,
295294
struct bin_attribute *attr, char *buf,
296295
loff_t off, size_t count) {
297-
struct device *dev =
298-
container_of(kobj, struct device, kobj)->parent->parent;
296+
struct device *dev = kobj_to_dev(kobj)->parent->parent;
299297
struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev));
300298
struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
301299
int retval = 0, difference, old_profile;
@@ -332,8 +330,7 @@ static BIN_ATTR(settings, 0660, kone_sysfs_read_settings,
332330
static ssize_t kone_sysfs_read_profilex(struct file *fp,
333331
struct kobject *kobj, struct bin_attribute *attr,
334332
char *buf, loff_t off, size_t count) {
335-
struct device *dev =
336-
container_of(kobj, struct device, kobj)->parent->parent;
333+
struct device *dev = kobj_to_dev(kobj)->parent->parent;
337334
struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev));
338335

339336
if (off >= sizeof(struct kone_profile))
@@ -353,8 +350,7 @@ static ssize_t kone_sysfs_read_profilex(struct file *fp,
353350
static ssize_t kone_sysfs_write_profilex(struct file *fp,
354351
struct kobject *kobj, struct bin_attribute *attr,
355352
char *buf, loff_t off, size_t count) {
356-
struct device *dev =
357-
container_of(kobj, struct device, kobj)->parent->parent;
353+
struct device *dev = kobj_to_dev(kobj)->parent->parent;
358354
struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev));
359355
struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
360356
struct kone_profile *profile;

drivers/hid/hid-roccat-koneplus.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ static ssize_t koneplus_sysfs_read(struct file *fp, struct kobject *kobj,
8787
char *buf, loff_t off, size_t count,
8888
size_t real_size, uint command)
8989
{
90-
struct device *dev =
91-
container_of(kobj, struct device, kobj)->parent->parent;
90+
struct device *dev = kobj_to_dev(kobj)->parent->parent;
9291
struct koneplus_device *koneplus = hid_get_drvdata(dev_get_drvdata(dev));
9392
struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
9493
int retval;
@@ -113,8 +112,7 @@ static ssize_t koneplus_sysfs_write(struct file *fp, struct kobject *kobj,
113112
void const *buf, loff_t off, size_t count,
114113
size_t real_size, uint command)
115114
{
116-
struct device *dev =
117-
container_of(kobj, struct device, kobj)->parent->parent;
115+
struct device *dev = kobj_to_dev(kobj)->parent->parent;
118116
struct koneplus_device *koneplus = hid_get_drvdata(dev_get_drvdata(dev));
119117
struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
120118
int retval;
@@ -193,8 +191,7 @@ static ssize_t koneplus_sysfs_read_profilex_settings(struct file *fp,
193191
struct kobject *kobj, struct bin_attribute *attr, char *buf,
194192
loff_t off, size_t count)
195193
{
196-
struct device *dev =
197-
container_of(kobj, struct device, kobj)->parent->parent;
194+
struct device *dev = kobj_to_dev(kobj)->parent->parent;
198195
struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
199196
ssize_t retval;
200197

@@ -212,8 +209,7 @@ static ssize_t koneplus_sysfs_read_profilex_buttons(struct file *fp,
212209
struct kobject *kobj, struct bin_attribute *attr, char *buf,
213210
loff_t off, size_t count)
214211
{
215-
struct device *dev =
216-
container_of(kobj, struct device, kobj)->parent->parent;
212+
struct device *dev = kobj_to_dev(kobj)->parent->parent;
217213
struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
218214
ssize_t retval;
219215

drivers/hid/hid-roccat-kovaplus.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ static ssize_t kovaplus_sysfs_read(struct file *fp, struct kobject *kobj,
128128
char *buf, loff_t off, size_t count,
129129
size_t real_size, uint command)
130130
{
131-
struct device *dev =
132-
container_of(kobj, struct device, kobj)->parent->parent;
131+
struct device *dev = kobj_to_dev(kobj)->parent->parent;
133132
struct kovaplus_device *kovaplus = hid_get_drvdata(dev_get_drvdata(dev));
134133
struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
135134
int retval;
@@ -154,8 +153,7 @@ static ssize_t kovaplus_sysfs_write(struct file *fp, struct kobject *kobj,
154153
void const *buf, loff_t off, size_t count,
155154
size_t real_size, uint command)
156155
{
157-
struct device *dev =
158-
container_of(kobj, struct device, kobj)->parent->parent;
156+
struct device *dev = kobj_to_dev(kobj)->parent->parent;
159157
struct kovaplus_device *kovaplus = hid_get_drvdata(dev_get_drvdata(dev));
160158
struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
161159
int retval;
@@ -221,8 +219,7 @@ static ssize_t kovaplus_sysfs_read_profilex_settings(struct file *fp,
221219
struct kobject *kobj, struct bin_attribute *attr, char *buf,
222220
loff_t off, size_t count)
223221
{
224-
struct device *dev =
225-
container_of(kobj, struct device, kobj)->parent->parent;
222+
struct device *dev = kobj_to_dev(kobj)->parent->parent;
226223
struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
227224
ssize_t retval;
228225

@@ -240,8 +237,7 @@ static ssize_t kovaplus_sysfs_read_profilex_buttons(struct file *fp,
240237
struct kobject *kobj, struct bin_attribute *attr, char *buf,
241238
loff_t off, size_t count)
242239
{
243-
struct device *dev =
244-
container_of(kobj, struct device, kobj)->parent->parent;
240+
struct device *dev = kobj_to_dev(kobj)->parent->parent;
245241
struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
246242
ssize_t retval;
247243

drivers/hid/hid-roccat-lua.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static ssize_t lua_sysfs_read(struct file *fp, struct kobject *kobj,
3030
char *buf, loff_t off, size_t count,
3131
size_t real_size, uint command)
3232
{
33-
struct device *dev = container_of(kobj, struct device, kobj);
33+
struct device *dev = kobj_to_dev(kobj);
3434
struct lua_device *lua = hid_get_drvdata(dev_get_drvdata(dev));
3535
struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
3636
int retval;
@@ -52,7 +52,7 @@ static ssize_t lua_sysfs_write(struct file *fp, struct kobject *kobj,
5252
void const *buf, loff_t off, size_t count,
5353
size_t real_size, uint command)
5454
{
55-
struct device *dev = container_of(kobj, struct device, kobj);
55+
struct device *dev = kobj_to_dev(kobj);
5656
struct lua_device *lua = hid_get_drvdata(dev_get_drvdata(dev));
5757
struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
5858
int retval;

drivers/hid/hid-roccat-pyra.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ static ssize_t pyra_sysfs_read(struct file *fp, struct kobject *kobj,
9090
char *buf, loff_t off, size_t count,
9191
size_t real_size, uint command)
9292
{
93-
struct device *dev =
94-
container_of(kobj, struct device, kobj)->parent->parent;
93+
struct device *dev = kobj_to_dev(kobj)->parent->parent;
9594
struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev));
9695
struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
9796
int retval;
@@ -116,8 +115,7 @@ static ssize_t pyra_sysfs_write(struct file *fp, struct kobject *kobj,
116115
void const *buf, loff_t off, size_t count,
117116
size_t real_size, uint command)
118117
{
119-
struct device *dev =
120-
container_of(kobj, struct device, kobj)->parent->parent;
118+
struct device *dev = kobj_to_dev(kobj)->parent->parent;
121119
struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev));
122120
struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
123121
int retval;
@@ -191,8 +189,7 @@ static ssize_t pyra_sysfs_read_profilex_settings(struct file *fp,
191189
struct kobject *kobj, struct bin_attribute *attr, char *buf,
192190
loff_t off, size_t count)
193191
{
194-
struct device *dev =
195-
container_of(kobj, struct device, kobj)->parent->parent;
192+
struct device *dev = kobj_to_dev(kobj)->parent->parent;
196193
struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
197194
ssize_t retval;
198195

@@ -210,8 +207,7 @@ static ssize_t pyra_sysfs_read_profilex_buttons(struct file *fp,
210207
struct kobject *kobj, struct bin_attribute *attr, char *buf,
211208
loff_t off, size_t count)
212209
{
213-
struct device *dev =
214-
container_of(kobj, struct device, kobj)->parent->parent;
210+
struct device *dev = kobj_to_dev(kobj)->parent->parent;
215211
struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
216212
ssize_t retval;
217213

@@ -248,8 +244,7 @@ static ssize_t pyra_sysfs_write_settings(struct file *fp,
248244
struct kobject *kobj, struct bin_attribute *attr, char *buf,
249245
loff_t off, size_t count)
250246
{
251-
struct device *dev =
252-
container_of(kobj, struct device, kobj)->parent->parent;
247+
struct device *dev = kobj_to_dev(kobj)->parent->parent;
253248
struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev));
254249
struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
255250
int retval = 0;

drivers/hid/wacom_sys.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,7 @@ static ssize_t wacom_show_remote_mode(struct kobject *kobj,
11301130
struct kobj_attribute *kattr,
11311131
char *buf, int index)
11321132
{
1133-
struct device *dev = container_of(kobj->parent, struct device, kobj);
1133+
struct device *dev = kobj_to_dev(kobj->parent);
11341134
struct hid_device *hdev = to_hid_device(dev);
11351135
struct wacom *wacom = hid_get_drvdata(hdev);
11361136
u8 mode;
@@ -1241,7 +1241,7 @@ static ssize_t wacom_store_unpair_remote(struct kobject *kobj,
12411241
const char *buf, size_t count)
12421242
{
12431243
unsigned char selector = 0;
1244-
struct device *dev = container_of(kobj->parent, struct device, kobj);
1244+
struct device *dev = kobj_to_dev(kobj->parent);
12451245
struct hid_device *hdev = to_hid_device(dev);
12461246
struct wacom *wacom = hid_get_drvdata(hdev);
12471247
int err;

0 commit comments

Comments
 (0)