linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Benjamin Tissoires <benjamin.tissoires@redhat.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Jiri Kosina <jikos@kernel.org>,
	linux-input@vger.kernel.org,
	Andy Shevchenko <andy.shevchenko@gmail.com>
Subject: Re: [PATCH v1] HID: core: don't use negative operands when shift
Date: Tue, 13 Jun 2017 11:59:27 +0200	[thread overview]
Message-ID: <20170613095927.GC29589@mail.corp.redhat.com> (raw)
In-Reply-To: <20170613092222.4073-1-andriy.shevchenko@linux.intel.com>

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
> 

  reply	other threads:[~2017-06-13  9:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2017-06-13 12:29 ` Jiri Kosina

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170613095927.GC29589@mail.corp.redhat.com \
    --to=benjamin.tissoires@redhat.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).