Skip to content

Commit bdd853b

Browse files
committed
HID: stop exporting hid_snto32()
jira LE-4395 cve CVE-2025-38556 Rebuild_History Non-Buildable kernel-6.12.0-55.39.1.el10_0 commit-author Dmitry Torokhov <dmitry.torokhov@gmail.com> commit c653ffc The only user of hid_snto32() is Logitech HID++ driver, which always calls hid_snto32() with valid size (constant, either 12 or 8) and therefore can simply use sign_extend32(). Make the switch and remove hid_snto32(). Move snto32() and s32ton() to avoid introducing forward declaration. Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> Link: https://patch.msgid.link/20241003144656.3786064-2-dmitry.torokhov@gmail.com [bentiss: fix checkpatch warning] Signed-off-by: Benjamin Tissoires <bentiss@kernel.org> (cherry picked from commit c653ffc) Signed-off-by: Jonathan Maple <jmaple@ciq.com>
1 parent 5b4fd69 commit bdd853b

File tree

3 files changed

+32
-38
lines changed

3 files changed

+32
-38
lines changed

drivers/hid/hid-core.c

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,34 @@ static int hid_ignore_special_drivers = 0;
4545
module_param_named(ignore_special_drivers, hid_ignore_special_drivers, int, 0600);
4646
MODULE_PARM_DESC(ignore_special_drivers, "Ignore any special drivers and handle all devices by generic driver");
4747

48+
/*
49+
* Convert a signed n-bit integer to signed 32-bit integer.
50+
*/
51+
52+
static s32 snto32(__u32 value, unsigned int n)
53+
{
54+
if (!value || !n)
55+
return 0;
56+
57+
if (n > 32)
58+
n = 32;
59+
60+
return sign_extend32(value, n - 1);
61+
}
62+
63+
/*
64+
* Convert a signed 32-bit integer to a signed n-bit integer.
65+
*/
66+
67+
static u32 s32ton(__s32 value, unsigned int n)
68+
{
69+
s32 a = value >> (n - 1);
70+
71+
if (a && a != -1)
72+
return value < 0 ? 1 << (n - 1) : (1 << (n - 1)) - 1;
73+
return value & ((1 << n) - 1);
74+
}
75+
4876
/*
4977
* Register a new report for a device.
5078
*/
@@ -425,7 +453,7 @@ static int hid_parser_global(struct hid_parser *parser, struct hid_item *item)
425453
* both this and the standard encoding. */
426454
raw_value = item_sdata(item);
427455
if (!(raw_value & 0xfffffff0))
428-
parser->global.unit_exponent = hid_snto32(raw_value, 4);
456+
parser->global.unit_exponent = snto32(raw_value, 4);
429457
else
430458
parser->global.unit_exponent = raw_value;
431459
return 0;
@@ -1315,39 +1343,6 @@ int hid_open_report(struct hid_device *device)
13151343
}
13161344
EXPORT_SYMBOL_GPL(hid_open_report);
13171345

1318-
/*
1319-
* Convert a signed n-bit integer to signed 32-bit integer.
1320-
*/
1321-
1322-
static s32 snto32(__u32 value, unsigned n)
1323-
{
1324-
if (!value || !n)
1325-
return 0;
1326-
1327-
if (n > 32)
1328-
n = 32;
1329-
1330-
return sign_extend32(value, n - 1);
1331-
}
1332-
1333-
s32 hid_snto32(__u32 value, unsigned n)
1334-
{
1335-
return snto32(value, n);
1336-
}
1337-
EXPORT_SYMBOL_GPL(hid_snto32);
1338-
1339-
/*
1340-
* Convert a signed 32-bit integer to a signed n-bit integer.
1341-
*/
1342-
1343-
static u32 s32ton(__s32 value, unsigned n)
1344-
{
1345-
s32 a = value >> (n - 1);
1346-
if (a && a != -1)
1347-
return value < 0 ? 1 << (n - 1) : (1 << (n - 1)) - 1;
1348-
return value & ((1 << n) - 1);
1349-
}
1350-
13511346
/*
13521347
* Extract/implement a data field from/to a little endian report (bit array).
13531348
*

drivers/hid/hid-logitech-hidpp.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3296,13 +3296,13 @@ static int m560_raw_event(struct hid_device *hdev, u8 *data, int size)
32963296
120);
32973297
}
32983298

3299-
v = hid_snto32(hid_field_extract(hdev, data+3, 0, 12), 12);
3299+
v = sign_extend32(hid_field_extract(hdev, data + 3, 0, 12), 11);
33003300
input_report_rel(hidpp->input, REL_X, v);
33013301

3302-
v = hid_snto32(hid_field_extract(hdev, data+3, 12, 12), 12);
3302+
v = sign_extend32(hid_field_extract(hdev, data + 3, 12, 12), 11);
33033303
input_report_rel(hidpp->input, REL_Y, v);
33043304

3305-
v = hid_snto32(data[6], 8);
3305+
v = sign_extend32(data[6], 7);
33063306
if (v != 0)
33073307
hidpp_scroll_counter_handle_scroll(hidpp->input,
33083308
&hidpp->vertical_wheel_counter, v);

include/linux/hid.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,6 @@ const struct hid_device_id *hid_match_device(struct hid_device *hdev,
974974
struct hid_driver *hdrv);
975975
bool hid_compare_device_paths(struct hid_device *hdev_a,
976976
struct hid_device *hdev_b, char separator);
977-
s32 hid_snto32(__u32 value, unsigned n);
978977
__u32 hid_field_extract(const struct hid_device *hid, __u8 *report,
979978
unsigned offset, unsigned n);
980979

0 commit comments

Comments
 (0)