Skip to content

Commit 4291ee3

Browse files
JoePerchesJiri Kosina
authored andcommitted
HID: Add and use hid_<level>: dev_<level> equivalents
Neaten current uses of dev_<level> by adding and using hid specific hid_<level> macros. Convert existing uses of dev_<level> uses to hid_<level>. Convert hid-pidff printk uses to hid_<level>. Remove err_hid and use hid_err instead. Add missing newlines to logging messages where necessary. Coalesce format strings. Add and use pr_fmt(fmt) KBUILD_MODNAME ": " fmt Other miscellaneous changes: Add const struct hid_device * argument to hid-core functions extract() and implement() so hid_<level> can be used by them. Fix bad indentation in hid-core hid_input_field function that calls extract() function above. Signed-off-by: Joe Perches <joe@perches.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
1 parent 5bea766 commit 4291ee3

51 files changed

Lines changed: 398 additions & 399 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎drivers/hid/hid-3m-pct.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ static int mmm_probe(struct hid_device *hdev, const struct hid_device_id *id)
274274

275275
md = kzalloc(sizeof(struct mmm_data), GFP_KERNEL);
276276
if (!md) {
277-
dev_err(&hdev->dev, "cannot allocate 3M data\n");
277+
hid_err(hdev, "cannot allocate 3M data\n");
278278
return -ENOMEM;
279279
}
280280
hid_set_drvdata(hdev, md);

‎drivers/hid/hid-a4tech.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ static int a4_probe(struct hid_device *hdev, const struct hid_device_id *id)
9393

9494
a4 = kzalloc(sizeof(*a4), GFP_KERNEL);
9595
if (a4 == NULL) {
96-
dev_err(&hdev->dev, "can't alloc device descriptor\n");
96+
hid_err(hdev, "can't alloc device descriptor\n");
9797
ret = -ENOMEM;
9898
goto err_free;
9999
}
@@ -104,13 +104,13 @@ static int a4_probe(struct hid_device *hdev, const struct hid_device_id *id)
104104

105105
ret = hid_parse(hdev);
106106
if (ret) {
107-
dev_err(&hdev->dev, "parse failed\n");
107+
hid_err(hdev, "parse failed\n");
108108
goto err_free;
109109
}
110110

111111
ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
112112
if (ret) {
113-
dev_err(&hdev->dev, "hw start failed\n");
113+
hid_err(hdev, "hw start failed\n");
114114
goto err_free;
115115
}
116116

‎drivers/hid/hid-apple.c‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
* any later version.
1717
*/
1818

19+
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
20+
1921
#include <linux/device.h>
2022
#include <linux/hid.h>
2123
#include <linux/module.h>
@@ -280,8 +282,8 @@ static __u8 *apple_report_fixup(struct hid_device *hdev, __u8 *rdesc,
280282

281283
if ((asc->quirks & APPLE_RDESC_JIS) && *rsize >= 60 &&
282284
rdesc[53] == 0x65 && rdesc[59] == 0x65) {
283-
dev_info(&hdev->dev, "fixing up MacBook JIS keyboard report "
284-
"descriptor\n");
285+
hid_info(hdev,
286+
"fixing up MacBook JIS keyboard report descriptor\n");
285287
rdesc[53] = rdesc[59] = 0xe7;
286288
}
287289
return rdesc;
@@ -351,7 +353,7 @@ static int apple_probe(struct hid_device *hdev,
351353

352354
asc = kzalloc(sizeof(*asc), GFP_KERNEL);
353355
if (asc == NULL) {
354-
dev_err(&hdev->dev, "can't alloc apple descriptor\n");
356+
hid_err(hdev, "can't alloc apple descriptor\n");
355357
return -ENOMEM;
356358
}
357359

@@ -361,7 +363,7 @@ static int apple_probe(struct hid_device *hdev,
361363

362364
ret = hid_parse(hdev);
363365
if (ret) {
364-
dev_err(&hdev->dev, "parse failed\n");
366+
hid_err(hdev, "parse failed\n");
365367
goto err_free;
366368
}
367369

@@ -372,7 +374,7 @@ static int apple_probe(struct hid_device *hdev,
372374

373375
ret = hid_hw_start(hdev, connect_mask);
374376
if (ret) {
375-
dev_err(&hdev->dev, "hw start failed\n");
377+
hid_err(hdev, "hw start failed\n");
376378
goto err_free;
377379
}
378380

@@ -512,7 +514,7 @@ static int __init apple_init(void)
512514

513515
ret = hid_register_driver(&apple_driver);
514516
if (ret)
515-
printk(KERN_ERR "can't register apple driver\n");
517+
pr_err("can't register apple driver\n");
516518

517519
return ret;
518520
}

‎drivers/hid/hid-axff.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ static int axff_init(struct hid_device *hid)
7373
int error;
7474

7575
if (list_empty(report_list)) {
76-
dev_err(&hid->dev, "no output reports found\n");
76+
hid_err(hid, "no output reports found\n");
7777
return -ENODEV;
7878
}
7979

8080
report = list_first_entry(report_list, struct hid_report, list);
8181

8282
if (report->maxfield < 4) {
83-
dev_err(&hid->dev, "no fields in the report: %d\n", report->maxfield);
83+
hid_err(hid, "no fields in the report: %d\n", report->maxfield);
8484
return -ENODEV;
8585
}
8686

@@ -101,7 +101,7 @@ static int axff_init(struct hid_device *hid)
101101
axff->report->field[3]->value[0] = 0x00;
102102
usbhid_submit_report(hid, axff->report, USB_DIR_OUT);
103103

104-
dev_info(&hid->dev, "Force Feedback for ACRUX game controllers by Sergei Kolzun<x0r@dv-life.ru>\n");
104+
hid_info(hid, "Force Feedback for ACRUX game controllers by Sergei Kolzun<x0r@dv-life.ru>\n");
105105

106106
return 0;
107107

@@ -114,17 +114,17 @@ static int ax_probe(struct hid_device *hdev, const struct hid_device_id *id)
114114
{
115115
int error;
116116

117-
dev_dbg(&hdev->dev, "ACRUX HID hardware probe...");
117+
dev_dbg(&hdev->dev, "ACRUX HID hardware probe...\n");
118118

119119
error = hid_parse(hdev);
120120
if (error) {
121-
dev_err(&hdev->dev, "parse failed\n");
121+
hid_err(hdev, "parse failed\n");
122122
return error;
123123
}
124124

125125
error = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
126126
if (error) {
127-
dev_err(&hdev->dev, "hw start failed\n");
127+
hid_err(hdev, "hw start failed\n");
128128
return error;
129129
}
130130

@@ -134,7 +134,7 @@ static int ax_probe(struct hid_device *hdev, const struct hid_device_id *id)
134134
* Do not fail device initialization completely as device
135135
* may still be partially operable, just warn.
136136
*/
137-
dev_warn(&hdev->dev,
137+
hid_warn(hdev,
138138
"Failed to enable force feedback support, error: %d\n",
139139
error);
140140
}

‎drivers/hid/hid-belkin.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ static int belkin_probe(struct hid_device *hdev, const struct hid_device_id *id)
5656

5757
ret = hid_parse(hdev);
5858
if (ret) {
59-
dev_err(&hdev->dev, "parse failed\n");
59+
hid_err(hdev, "parse failed\n");
6060
goto err_free;
6161
}
6262

6363
ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT |
6464
((quirks & BELKIN_HIDDEV) ? HID_CONNECT_HIDDEV_FORCE : 0));
6565
if (ret) {
66-
dev_err(&hdev->dev, "hw start failed\n");
66+
hid_err(hdev, "hw start failed\n");
6767
goto err_free;
6868
}
6969

‎drivers/hid/hid-cando.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ static int cando_probe(struct hid_device *hdev, const struct hid_device_id *id)
207207

208208
td = kmalloc(sizeof(struct cando_data), GFP_KERNEL);
209209
if (!td) {
210-
dev_err(&hdev->dev, "cannot allocate Cando Touch data\n");
210+
hid_err(hdev, "cannot allocate Cando Touch data\n");
211211
return -ENOMEM;
212212
}
213213
hid_set_drvdata(hdev, td);

‎drivers/hid/hid-cherry.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ static __u8 *ch_report_fixup(struct hid_device *hdev, __u8 *rdesc,
3030
unsigned int *rsize)
3131
{
3232
if (*rsize >= 17 && rdesc[11] == 0x3c && rdesc[12] == 0x02) {
33-
dev_info(&hdev->dev, "fixing up Cherry Cymotion report "
34-
"descriptor\n");
33+
hid_info(hdev, "fixing up Cherry Cymotion report descriptor\n");
3534
rdesc[11] = rdesc[16] = 0xff;
3635
rdesc[12] = rdesc[17] = 0x03;
3736
}

‎drivers/hid/hid-core.c‎

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* any later version.
1515
*/
1616

17+
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18+
1719
#include <linux/module.h>
1820
#include <linux/slab.h>
1921
#include <linux/init.h>
@@ -672,7 +674,8 @@ int hid_parse_report(struct hid_device *device, __u8 *start,
672674

673675
if (dispatch_type[item.type](parser, &item)) {
674676
dbg_hid("item %u %u %u %u parsing failed\n",
675-
item.format, (unsigned)item.size, (unsigned)item.type, (unsigned)item.tag);
677+
item.format, (unsigned)item.size,
678+
(unsigned)item.type, (unsigned)item.tag);
676679
goto err;
677680
}
678681

@@ -737,13 +740,14 @@ static u32 s32ton(__s32 value, unsigned n)
737740
* Search linux-kernel and linux-usb-devel archives for "hid-core extract".
738741
*/
739742

740-
static __inline__ __u32 extract(__u8 *report, unsigned offset, unsigned n)
743+
static __inline__ __u32 extract(const struct hid_device *hid, __u8 *report,
744+
unsigned offset, unsigned n)
741745
{
742746
u64 x;
743747

744748
if (n > 32)
745-
printk(KERN_WARNING "HID: extract() called with n (%d) > 32! (%s)\n",
746-
n, current->comm);
749+
hid_warn(hid, "extract() called with n (%d) > 32! (%s)\n",
750+
n, current->comm);
747751

748752
report += offset >> 3; /* adjust byte index */
749753
offset &= 7; /* now only need bit offset into one byte */
@@ -760,18 +764,19 @@ static __inline__ __u32 extract(__u8 *report, unsigned offset, unsigned n)
760764
* endianness of register values by considering a register
761765
* a "cached" copy of the little endiad bit stream.
762766
*/
763-
static __inline__ void implement(__u8 *report, unsigned offset, unsigned n, __u32 value)
767+
static __inline__ void implement(const struct hid_device *hid, __u8 *report,
768+
unsigned offset, unsigned n, __u32 value)
764769
{
765770
u64 x;
766771
u64 m = (1ULL << n) - 1;
767772

768773
if (n > 32)
769-
printk(KERN_WARNING "HID: implement() called with n (%d) > 32! (%s)\n",
770-
n, current->comm);
774+
hid_warn(hid, "%s() called with n (%d) > 32! (%s)\n",
775+
__func__, n, current->comm);
771776

772777
if (value > m)
773-
printk(KERN_WARNING "HID: implement() called with too large value %d! (%s)\n",
774-
value, current->comm);
778+
hid_warn(hid, "%s() called with too large value %d! (%s)\n",
779+
__func__, value, current->comm);
775780
WARN_ON(value > m);
776781
value &= m;
777782

@@ -892,13 +897,16 @@ static void hid_input_field(struct hid_device *hid, struct hid_field *field,
892897

893898
for (n = 0; n < count; n++) {
894899

895-
value[n] = min < 0 ? snto32(extract(data, offset + n * size, size), size) :
896-
extract(data, offset + n * size, size);
900+
value[n] = min < 0 ?
901+
snto32(extract(hid, data, offset + n * size, size),
902+
size) :
903+
extract(hid, data, offset + n * size, size);
897904

898-
if (!(field->flags & HID_MAIN_ITEM_VARIABLE) /* Ignore report if ErrorRollOver */
899-
&& value[n] >= min && value[n] <= max
900-
&& field->usage[value[n] - min].hid == HID_UP_KEYBOARD + 1)
901-
goto exit;
905+
/* Ignore report if ErrorRollOver */
906+
if (!(field->flags & HID_MAIN_ITEM_VARIABLE) &&
907+
value[n] >= min && value[n] <= max &&
908+
field->usage[value[n] - min].hid == HID_UP_KEYBOARD + 1)
909+
goto exit;
902910
}
903911

904912
for (n = 0; n < count; n++) {
@@ -928,7 +936,8 @@ static void hid_input_field(struct hid_device *hid, struct hid_field *field,
928936
* Output the field into the report.
929937
*/
930938

931-
static void hid_output_field(struct hid_field *field, __u8 *data)
939+
static void hid_output_field(const struct hid_device *hid,
940+
struct hid_field *field, __u8 *data)
932941
{
933942
unsigned count = field->report_count;
934943
unsigned offset = field->report_offset;
@@ -937,9 +946,11 @@ static void hid_output_field(struct hid_field *field, __u8 *data)
937946

938947
for (n = 0; n < count; n++) {
939948
if (field->logical_minimum < 0) /* signed values */
940-
implement(data, offset + n * size, size, s32ton(field->value[n], size));
949+
implement(hid, data, offset + n * size, size,
950+
s32ton(field->value[n], size));
941951
else /* unsigned values */
942-
implement(data, offset + n * size, size, field->value[n]);
952+
implement(hid, data, offset + n * size, size,
953+
field->value[n]);
943954
}
944955
}
945956

@@ -956,7 +967,7 @@ void hid_output_report(struct hid_report *report, __u8 *data)
956967

957968
memset(data, 0, ((report->size - 1) >> 3) + 1);
958969
for (n = 0; n < report->maxfield; n++)
959-
hid_output_field(report->field[n], data);
970+
hid_output_field(report->device, report->field[n], data);
960971
}
961972
EXPORT_SYMBOL_GPL(hid_output_report);
962973

@@ -1169,8 +1180,7 @@ int hid_connect(struct hid_device *hdev, unsigned int connect_mask)
11691180
hdev->claimed |= HID_CLAIMED_HIDRAW;
11701181

11711182
if (!hdev->claimed) {
1172-
dev_err(&hdev->dev, "claimed by neither input, hiddev nor "
1173-
"hidraw\n");
1183+
hid_err(hdev, "claimed by neither input, hiddev nor hidraw\n");
11741184
return -ENODEV;
11751185
}
11761186

@@ -1210,9 +1220,9 @@ int hid_connect(struct hid_device *hdev, unsigned int connect_mask)
12101220
bus = "<UNKNOWN>";
12111221
}
12121222

1213-
dev_info(&hdev->dev, "%s: %s HID v%x.%02x %s [%s] on %s\n",
1214-
buf, bus, hdev->version >> 8, hdev->version & 0xff,
1215-
type, hdev->name, hdev->phys);
1223+
hid_info(hdev, "%s: %s HID v%x.%02x %s [%s] on %s\n",
1224+
buf, bus, hdev->version >> 8, hdev->version & 0xff,
1225+
type, hdev->name, hdev->phys);
12161226

12171227
return 0;
12181228
}
@@ -1956,12 +1966,12 @@ static int __init hid_init(void)
19561966
int ret;
19571967

19581968
if (hid_debug)
1959-
printk(KERN_WARNING "HID: hid_debug is now used solely for parser and driver debugging.\n"
1960-
"HID: debugfs is now used for inspecting the device (report descriptor, reports)\n");
1969+
pr_warn("hid_debug is now used solely for parser and driver debugging.\n"
1970+
"debugfs is now used for inspecting the device (report descriptor, reports)\n");
19611971

19621972
ret = bus_register(&hid_bus_type);
19631973
if (ret) {
1964-
printk(KERN_ERR "HID: can't register hid bus\n");
1974+
pr_err("can't register hid bus\n");
19651975
goto err;
19661976
}
19671977

‎drivers/hid/hid-cypress.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,13 @@ static int cp_probe(struct hid_device *hdev, const struct hid_device_id *id)
107107

108108
ret = hid_parse(hdev);
109109
if (ret) {
110-
dev_err(&hdev->dev, "parse failed\n");
110+
hid_err(hdev, "parse failed\n");
111111
goto err_free;
112112
}
113113

114114
ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
115115
if (ret) {
116-
dev_err(&hdev->dev, "hw start failed\n");
116+
hid_err(hdev, "hw start failed\n");
117117
goto err_free;
118118
}
119119

‎drivers/hid/hid-debug.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
* Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
2727
*/
2828

29+
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30+
2931
#include <linux/debugfs.h>
3032
#include <linux/seq_file.h>
3133
#include <linux/sched.h>
@@ -393,7 +395,7 @@ char *hid_resolv_usage(unsigned usage, struct seq_file *f) {
393395

394396
buf = resolv_usage_page(usage >> 16, f);
395397
if (IS_ERR(buf)) {
396-
printk(KERN_ERR "error allocating HID debug buffer\n");
398+
pr_err("error allocating HID debug buffer\n");
397399
return NULL;
398400
}
399401

0 commit comments

Comments
 (0)