Message ID | 20241003144656.3786064-1-dmitry.torokhov@gmail.com |
---|---|
State | New |
Headers | show |
Series | [1/2] HID: simplify snto32() | expand |
On Thu, 03 Oct 2024 07:46:50 -0700, Dmitry Torokhov wrote: > snto32() does exactly what sign_extend32() does, but handles > potentially malformed data coming from the device. Keep the checks, > but then call sign_extend32() to perform the actual conversion. > > Applied to hid/hid.git (for-6.13/core), thanks! [1/2] HID: simplify snto32() https://git.kernel.org/hid/hid/c/ae9b956cb26c [2/2] HID: stop exporting hid_snto32() https://git.kernel.org/hid/hid/c/c653ffc28340 Cheers,
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index 00942d40fe08..5f62df91030d 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c @@ -1313,9 +1313,7 @@ int hid_open_report(struct hid_device *device) EXPORT_SYMBOL_GPL(hid_open_report); /* - * Convert a signed n-bit integer to signed 32-bit integer. Common - * cases are done through the compiler, the screwed things has to be - * done by hand. + * Convert a signed n-bit integer to signed 32-bit integer. */ static s32 snto32(__u32 value, unsigned n) @@ -1326,12 +1324,7 @@ static s32 snto32(__u32 value, unsigned n) if (n > 32) n = 32; - switch (n) { - case 8: return ((__s8)value); - case 16: return ((__s16)value); - case 32: return ((__s32)value); - } - return value & (1 << (n - 1)) ? value | (~0U << n) : value; + return sign_extend32(value, n - 1); } s32 hid_snto32(__u32 value, unsigned n)
snto32() does exactly what sign_extend32() does, but handles potentially malformed data coming from the device. Keep the checks, but then call sign_extend32() to perform the actual conversion. Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> --- drivers/hid/hid-core.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)