Skip to content

Commit 6168f71

Browse files
Sandeep C SJiri Kosina
authored andcommitted
HID: samsung: Rewrite rdesc checking code using memcmp()
Resolved warnings found by checkpatch.pl script. Signed-off-by: Sandeep C S <[email protected]> Signed-off-by: Junwan Cho <[email protected]> Signed-off-by: Jitender Sajwan <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent ac203cd commit 6168f71

File tree

1 file changed

+47
-33
lines changed

1 file changed

+47
-33
lines changed

drivers/hid/hid-samsung.c

Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -58,33 +58,25 @@ static inline void samsung_irda_dev_trace(struct hid_device *hdev,
5858
static __u8 *samsung_irda_report_fixup(struct hid_device *hdev, __u8 *rdesc,
5959
unsigned int *rsize)
6060
{
61-
if (*rsize == 184 && rdesc[175] == 0x25 && rdesc[176] == 0x40 &&
62-
rdesc[177] == 0x75 && rdesc[178] == 0x30 &&
63-
rdesc[179] == 0x95 && rdesc[180] == 0x01 &&
61+
if (*rsize == 184 && !memcmp(&rdesc[175], "\x25\x40\x75\x30\x95\x01", 6) &&
6462
rdesc[182] == 0x40) {
6563
samsung_irda_dev_trace(hdev, 184);
6664
rdesc[176] = 0xff;
6765
rdesc[178] = 0x08;
6866
rdesc[180] = 0x06;
6967
rdesc[182] = 0x42;
70-
} else
71-
if (*rsize == 203 && rdesc[192] == 0x15 && rdesc[193] == 0x0 &&
72-
rdesc[194] == 0x25 && rdesc[195] == 0x12) {
68+
} else if (*rsize == 203 && !memcmp(&rdesc[192], "\x15\x00\x25\x12", 4)) {
7369
samsung_irda_dev_trace(hdev, 203);
74-
rdesc[193] = 0x1;
75-
rdesc[195] = 0xf;
76-
} else
77-
if (*rsize == 135 && rdesc[124] == 0x15 && rdesc[125] == 0x0 &&
78-
rdesc[126] == 0x25 && rdesc[127] == 0x11) {
70+
rdesc[193] = 0x01;
71+
rdesc[195] = 0x0f;
72+
} else if (*rsize == 135 && !memcmp(&rdesc[124], "\x15\x00\x25\x11", 4)) {
7973
samsung_irda_dev_trace(hdev, 135);
80-
rdesc[125] = 0x1;
81-
rdesc[127] = 0xe;
82-
} else
83-
if (*rsize == 171 && rdesc[160] == 0x15 && rdesc[161] == 0x0 &&
84-
rdesc[162] == 0x25 && rdesc[163] == 0x01) {
74+
rdesc[125] = 0x01;
75+
rdesc[127] = 0x0e;
76+
} else if (*rsize == 171 && !memcmp(&rdesc[160], "\x15\x00\x25\x01", 4)) {
8577
samsung_irda_dev_trace(hdev, 171);
86-
rdesc[161] = 0x1;
87-
rdesc[163] = 0x3;
78+
rdesc[161] = 0x01;
79+
rdesc[163] = 0x03;
8880
}
8981
return rdesc;
9082
}
@@ -99,25 +91,47 @@ static int samsung_kbd_mouse_input_mapping(struct hid_device *hdev,
9991
struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
10092
unsigned short ifnum = intf->cur_altsetting->desc.bInterfaceNumber;
10193

102-
if (1 != ifnum || HID_UP_CONSUMER != (usage->hid & HID_USAGE_PAGE))
94+
if (ifnum != 1 || HID_UP_CONSUMER != (usage->hid & HID_USAGE_PAGE))
10395
return 0;
10496

10597
dbg_hid("samsung wireless keyboard/mouse input mapping event [0x%x]\n",
10698
usage->hid & HID_USAGE);
10799

108100
switch (usage->hid & HID_USAGE) {
109101
/* report 2 */
110-
case 0x183: samsung_kbd_mouse_map_key_clear(KEY_MEDIA); break;
111-
case 0x195: samsung_kbd_mouse_map_key_clear(KEY_EMAIL); break;
112-
case 0x196: samsung_kbd_mouse_map_key_clear(KEY_CALC); break;
113-
case 0x197: samsung_kbd_mouse_map_key_clear(KEY_COMPUTER); break;
114-
case 0x22b: samsung_kbd_mouse_map_key_clear(KEY_SEARCH); break;
115-
case 0x22c: samsung_kbd_mouse_map_key_clear(KEY_WWW); break;
116-
case 0x22d: samsung_kbd_mouse_map_key_clear(KEY_BACK); break;
117-
case 0x22e: samsung_kbd_mouse_map_key_clear(KEY_FORWARD); break;
118-
case 0x22f: samsung_kbd_mouse_map_key_clear(KEY_FAVORITES); break;
119-
case 0x230: samsung_kbd_mouse_map_key_clear(KEY_REFRESH); break;
120-
case 0x231: samsung_kbd_mouse_map_key_clear(KEY_STOP); break;
102+
case 0x183:
103+
samsung_kbd_mouse_map_key_clear(KEY_MEDIA);
104+
break;
105+
case 0x195:
106+
samsung_kbd_mouse_map_key_clear(KEY_EMAIL);
107+
break;
108+
case 0x196:
109+
samsung_kbd_mouse_map_key_clear(KEY_CALC);
110+
break;
111+
case 0x197:
112+
samsung_kbd_mouse_map_key_clear(KEY_COMPUTER);
113+
break;
114+
case 0x22b:
115+
samsung_kbd_mouse_map_key_clear(KEY_SEARCH);
116+
break;
117+
case 0x22c:
118+
samsung_kbd_mouse_map_key_clear(KEY_WWW);
119+
break;
120+
case 0x22d:
121+
samsung_kbd_mouse_map_key_clear(KEY_BACK);
122+
break;
123+
case 0x22e:
124+
samsung_kbd_mouse_map_key_clear(KEY_FORWARD);
125+
break;
126+
case 0x22f:
127+
samsung_kbd_mouse_map_key_clear(KEY_FAVORITES);
128+
break;
129+
case 0x230:
130+
samsung_kbd_mouse_map_key_clear(KEY_REFRESH);
131+
break;
132+
case 0x231:
133+
samsung_kbd_mouse_map_key_clear(KEY_STOP);
134+
break;
121135
default:
122136
return 0;
123137
}
@@ -128,7 +142,7 @@ static int samsung_kbd_mouse_input_mapping(struct hid_device *hdev,
128142
static __u8 *samsung_report_fixup(struct hid_device *hdev, __u8 *rdesc,
129143
unsigned int *rsize)
130144
{
131-
if (USB_DEVICE_ID_SAMSUNG_IR_REMOTE == hdev->product && hid_is_usb(hdev))
145+
if (hdev->product == USB_DEVICE_ID_SAMSUNG_IR_REMOTE && hid_is_usb(hdev))
132146
rdesc = samsung_irda_report_fixup(hdev, rdesc, rsize);
133147
return rdesc;
134148
}
@@ -139,7 +153,7 @@ static int samsung_input_mapping(struct hid_device *hdev, struct hid_input *hi,
139153
{
140154
int ret = 0;
141155

142-
if (USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD_MOUSE == hdev->product && hid_is_usb(hdev))
156+
if (hdev->product == USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD_MOUSE && hid_is_usb(hdev))
143157
ret = samsung_kbd_mouse_input_mapping(hdev,
144158
hi, field, usage, bit, max);
145159

@@ -158,7 +172,7 @@ static int samsung_probe(struct hid_device *hdev,
158172
goto err_free;
159173
}
160174

161-
if (USB_DEVICE_ID_SAMSUNG_IR_REMOTE == hdev->product) {
175+
if (hdev->product == USB_DEVICE_ID_SAMSUNG_IR_REMOTE) {
162176
if (!hid_is_usb(hdev)) {
163177
ret = -EINVAL;
164178
goto err_free;

0 commit comments

Comments
 (0)