* [PATCH v1] HID: core: don't use negative operands when shift
@ 2017-06-13 9:22 Andy Shevchenko
2017-06-13 9:59 ` Benjamin Tissoires
2017-06-13 12:29 ` Jiri Kosina
0 siblings, 2 replies; 3+ messages in thread
From: Andy Shevchenko @ 2017-06-13 9:22 UTC (permalink / raw)
To: Jiri Kosina, Benjamin Tissoires, linux-input; +Cc: Andy Shevchenko
From: Andy Shevchenko <andy.shevchenko@gmail.com>
The recent C standard in 6.5.7 paragraph 4 defines that operands for
bitwise shift operators should be non-negative, otherwise it's an
undefined behaviour.
Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com>
---
drivers/hid/hid-core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 5f87dbe28336..73416fef983e 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -1046,7 +1046,7 @@ static s32 snto32(__u32 value, unsigned n)
case 16: return ((__s16)value);
case 32: return ((__s32)value);
}
- return value & (1 << (n - 1)) ? value | (-1 << n) : value;
+ return value & (1 << (n - 1)) ? value | (~0U << n) : value;
}
s32 hid_snto32(__u32 value, unsigned n)
--
2.11.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v1] HID: core: don't use negative operands when shift
2017-06-13 9:22 [PATCH v1] HID: core: don't use negative operands when shift Andy Shevchenko
@ 2017-06-13 9:59 ` Benjamin Tissoires
2017-06-13 12:29 ` Jiri Kosina
1 sibling, 0 replies; 3+ messages in thread
From: Benjamin Tissoires @ 2017-06-13 9:59 UTC (permalink / raw)
To: Andy Shevchenko; +Cc: Jiri Kosina, linux-input, Andy Shevchenko
On Jun 13 2017 or thereabouts, Andy Shevchenko wrote:
> From: Andy Shevchenko <andy.shevchenko@gmail.com>
>
> The recent C standard in 6.5.7 paragraph 4 defines that operands for
> bitwise shift operators should be non-negative, otherwise it's an
> undefined behaviour.
>
> Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Acked-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
> ---
> drivers/hid/hid-core.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
> index 5f87dbe28336..73416fef983e 100644
> --- a/drivers/hid/hid-core.c
> +++ b/drivers/hid/hid-core.c
> @@ -1046,7 +1046,7 @@ static s32 snto32(__u32 value, unsigned n)
> case 16: return ((__s16)value);
> case 32: return ((__s32)value);
> }
> - return value & (1 << (n - 1)) ? value | (-1 << n) : value;
> + return value & (1 << (n - 1)) ? value | (~0U << n) : value;
> }
>
> s32 hid_snto32(__u32 value, unsigned n)
> --
> 2.11.0
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v1] HID: core: don't use negative operands when shift
2017-06-13 9:22 [PATCH v1] HID: core: don't use negative operands when shift Andy Shevchenko
2017-06-13 9:59 ` Benjamin Tissoires
@ 2017-06-13 12:29 ` Jiri Kosina
1 sibling, 0 replies; 3+ messages in thread
From: Jiri Kosina @ 2017-06-13 12:29 UTC (permalink / raw)
To: Andy Shevchenko; +Cc: Benjamin Tissoires, linux-input, Andy Shevchenko
On Tue, 13 Jun 2017, Andy Shevchenko wrote:
> From: Andy Shevchenko <andy.shevchenko@gmail.com>
>
> The recent C standard in 6.5.7 paragraph 4 defines that operands for
> bitwise shift operators should be non-negative, otherwise it's an
> undefined behaviour.
>
> Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Applied, thanks.
--
Jiri Kosina
SUSE Labs
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-06-13 12:29 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-13 9:22 [PATCH v1] HID: core: don't use negative operands when shift Andy Shevchenko
2017-06-13 9:59 ` Benjamin Tissoires
2017-06-13 12:29 ` Jiri Kosina
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).