Skip to content

Commit

Permalink
HID: Add and use hid_<level>: dev_<level> equivalents
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Jiri Kosina <[email protected]>
  • Loading branch information
JoePerches authored and Jiri Kosina committed Dec 10, 2010
1 parent 5bea766 commit 4291ee3
Show file tree
Hide file tree
Showing 51 changed files with 398 additions and 399 deletions.
2 changes: 1 addition & 1 deletion drivers/hid/hid-3m-pct.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ static int mmm_probe(struct hid_device *hdev, const struct hid_device_id *id)

md = kzalloc(sizeof(struct mmm_data), GFP_KERNEL);
if (!md) {
dev_err(&hdev->dev, "cannot allocate 3M data\n");
hid_err(hdev, "cannot allocate 3M data\n");
return -ENOMEM;
}
hid_set_drvdata(hdev, md);
Expand Down
6 changes: 3 additions & 3 deletions drivers/hid/hid-a4tech.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ static int a4_probe(struct hid_device *hdev, const struct hid_device_id *id)

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

ret = hid_parse(hdev);
if (ret) {
dev_err(&hdev->dev, "parse failed\n");
hid_err(hdev, "parse failed\n");
goto err_free;
}

ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
if (ret) {
dev_err(&hdev->dev, "hw start failed\n");
hid_err(hdev, "hw start failed\n");
goto err_free;
}

Expand Down
14 changes: 8 additions & 6 deletions drivers/hid/hid-apple.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* any later version.
*/

#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

#include <linux/device.h>
#include <linux/hid.h>
#include <linux/module.h>
Expand Down Expand Up @@ -280,8 +282,8 @@ static __u8 *apple_report_fixup(struct hid_device *hdev, __u8 *rdesc,

if ((asc->quirks & APPLE_RDESC_JIS) && *rsize >= 60 &&
rdesc[53] == 0x65 && rdesc[59] == 0x65) {
dev_info(&hdev->dev, "fixing up MacBook JIS keyboard report "
"descriptor\n");
hid_info(hdev,
"fixing up MacBook JIS keyboard report descriptor\n");
rdesc[53] = rdesc[59] = 0xe7;
}
return rdesc;
Expand Down Expand Up @@ -351,7 +353,7 @@ static int apple_probe(struct hid_device *hdev,

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

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

ret = hid_parse(hdev);
if (ret) {
dev_err(&hdev->dev, "parse failed\n");
hid_err(hdev, "parse failed\n");
goto err_free;
}

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

ret = hid_hw_start(hdev, connect_mask);
if (ret) {
dev_err(&hdev->dev, "hw start failed\n");
hid_err(hdev, "hw start failed\n");
goto err_free;
}

Expand Down Expand Up @@ -512,7 +514,7 @@ static int __init apple_init(void)

ret = hid_register_driver(&apple_driver);
if (ret)
printk(KERN_ERR "can't register apple driver\n");
pr_err("can't register apple driver\n");

return ret;
}
Expand Down
14 changes: 7 additions & 7 deletions drivers/hid/hid-axff.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ static int axff_init(struct hid_device *hid)
int error;

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

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

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

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

dev_info(&hid->dev, "Force Feedback for ACRUX game controllers by Sergei Kolzun<[email protected]>\n");
hid_info(hid, "Force Feedback for ACRUX game controllers by Sergei Kolzun<[email protected]>\n");

return 0;

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

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

error = hid_parse(hdev);
if (error) {
dev_err(&hdev->dev, "parse failed\n");
hid_err(hdev, "parse failed\n");
return error;
}

error = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
if (error) {
dev_err(&hdev->dev, "hw start failed\n");
hid_err(hdev, "hw start failed\n");
return error;
}

Expand All @@ -134,7 +134,7 @@ static int ax_probe(struct hid_device *hdev, const struct hid_device_id *id)
* Do not fail device initialization completely as device
* may still be partially operable, just warn.
*/
dev_warn(&hdev->dev,
hid_warn(hdev,
"Failed to enable force feedback support, error: %d\n",
error);
}
Expand Down
4 changes: 2 additions & 2 deletions drivers/hid/hid-belkin.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ static int belkin_probe(struct hid_device *hdev, const struct hid_device_id *id)

ret = hid_parse(hdev);
if (ret) {
dev_err(&hdev->dev, "parse failed\n");
hid_err(hdev, "parse failed\n");
goto err_free;
}

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

Expand Down
2 changes: 1 addition & 1 deletion drivers/hid/hid-cando.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ static int cando_probe(struct hid_device *hdev, const struct hid_device_id *id)

td = kmalloc(sizeof(struct cando_data), GFP_KERNEL);
if (!td) {
dev_err(&hdev->dev, "cannot allocate Cando Touch data\n");
hid_err(hdev, "cannot allocate Cando Touch data\n");
return -ENOMEM;
}
hid_set_drvdata(hdev, td);
Expand Down
3 changes: 1 addition & 2 deletions drivers/hid/hid-cherry.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ static __u8 *ch_report_fixup(struct hid_device *hdev, __u8 *rdesc,
unsigned int *rsize)
{
if (*rsize >= 17 && rdesc[11] == 0x3c && rdesc[12] == 0x02) {
dev_info(&hdev->dev, "fixing up Cherry Cymotion report "
"descriptor\n");
hid_info(hdev, "fixing up Cherry Cymotion report descriptor\n");
rdesc[11] = rdesc[16] = 0xff;
rdesc[12] = rdesc[17] = 0x03;
}
Expand Down
64 changes: 37 additions & 27 deletions drivers/hid/hid-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* any later version.
*/

#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

#include <linux/module.h>
#include <linux/slab.h>
#include <linux/init.h>
Expand Down Expand Up @@ -672,7 +674,8 @@ int hid_parse_report(struct hid_device *device, __u8 *start,

if (dispatch_type[item.type](parser, &item)) {
dbg_hid("item %u %u %u %u parsing failed\n",
item.format, (unsigned)item.size, (unsigned)item.type, (unsigned)item.tag);
item.format, (unsigned)item.size,
(unsigned)item.type, (unsigned)item.tag);
goto err;
}

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

static __inline__ __u32 extract(__u8 *report, unsigned offset, unsigned n)
static __inline__ __u32 extract(const struct hid_device *hid, __u8 *report,
unsigned offset, unsigned n)
{
u64 x;

if (n > 32)
printk(KERN_WARNING "HID: extract() called with n (%d) > 32! (%s)\n",
n, current->comm);
hid_warn(hid, "extract() called with n (%d) > 32! (%s)\n",
n, current->comm);

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

if (n > 32)
printk(KERN_WARNING "HID: implement() called with n (%d) > 32! (%s)\n",
n, current->comm);
hid_warn(hid, "%s() called with n (%d) > 32! (%s)\n",
__func__, n, current->comm);

if (value > m)
printk(KERN_WARNING "HID: implement() called with too large value %d! (%s)\n",
value, current->comm);
hid_warn(hid, "%s() called with too large value %d! (%s)\n",
__func__, value, current->comm);
WARN_ON(value > m);
value &= m;

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

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

value[n] = min < 0 ? snto32(extract(data, offset + n * size, size), size) :
extract(data, offset + n * size, size);
value[n] = min < 0 ?
snto32(extract(hid, data, offset + n * size, size),
size) :
extract(hid, data, offset + n * size, size);

if (!(field->flags & HID_MAIN_ITEM_VARIABLE) /* Ignore report if ErrorRollOver */
&& value[n] >= min && value[n] <= max
&& field->usage[value[n] - min].hid == HID_UP_KEYBOARD + 1)
goto exit;
/* Ignore report if ErrorRollOver */
if (!(field->flags & HID_MAIN_ITEM_VARIABLE) &&
value[n] >= min && value[n] <= max &&
field->usage[value[n] - min].hid == HID_UP_KEYBOARD + 1)
goto exit;
}

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

static void hid_output_field(struct hid_field *field, __u8 *data)
static void hid_output_field(const struct hid_device *hid,
struct hid_field *field, __u8 *data)
{
unsigned count = field->report_count;
unsigned offset = field->report_offset;
Expand All @@ -937,9 +946,11 @@ static void hid_output_field(struct hid_field *field, __u8 *data)

for (n = 0; n < count; n++) {
if (field->logical_minimum < 0) /* signed values */
implement(data, offset + n * size, size, s32ton(field->value[n], size));
implement(hid, data, offset + n * size, size,
s32ton(field->value[n], size));
else /* unsigned values */
implement(data, offset + n * size, size, field->value[n]);
implement(hid, data, offset + n * size, size,
field->value[n]);
}
}

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

memset(data, 0, ((report->size - 1) >> 3) + 1);
for (n = 0; n < report->maxfield; n++)
hid_output_field(report->field[n], data);
hid_output_field(report->device, report->field[n], data);
}
EXPORT_SYMBOL_GPL(hid_output_report);

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

if (!hdev->claimed) {
dev_err(&hdev->dev, "claimed by neither input, hiddev nor "
"hidraw\n");
hid_err(hdev, "claimed by neither input, hiddev nor hidraw\n");
return -ENODEV;
}

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

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

return 0;
}
Expand Down Expand Up @@ -1956,12 +1966,12 @@ static int __init hid_init(void)
int ret;

if (hid_debug)
printk(KERN_WARNING "HID: hid_debug is now used solely for parser and driver debugging.\n"
"HID: debugfs is now used for inspecting the device (report descriptor, reports)\n");
pr_warn("hid_debug is now used solely for parser and driver debugging.\n"
"debugfs is now used for inspecting the device (report descriptor, reports)\n");

ret = bus_register(&hid_bus_type);
if (ret) {
printk(KERN_ERR "HID: can't register hid bus\n");
pr_err("can't register hid bus\n");
goto err;
}

Expand Down
4 changes: 2 additions & 2 deletions drivers/hid/hid-cypress.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ static int cp_probe(struct hid_device *hdev, const struct hid_device_id *id)

ret = hid_parse(hdev);
if (ret) {
dev_err(&hdev->dev, "parse failed\n");
hid_err(hdev, "parse failed\n");
goto err_free;
}

ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
if (ret) {
dev_err(&hdev->dev, "hw start failed\n");
hid_err(hdev, "hw start failed\n");
goto err_free;
}

Expand Down
4 changes: 3 additions & 1 deletion drivers/hid/hid-debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
* Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
*/

#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

#include <linux/debugfs.h>
#include <linux/seq_file.h>
#include <linux/sched.h>
Expand Down Expand Up @@ -393,7 +395,7 @@ char *hid_resolv_usage(unsigned usage, struct seq_file *f) {

buf = resolv_usage_page(usage >> 16, f);
if (IS_ERR(buf)) {
printk(KERN_ERR "error allocating HID debug buffer\n");
pr_err("error allocating HID debug buffer\n");
return NULL;
}

Expand Down
Loading

0 comments on commit 4291ee3

Please sign in to comment.