mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ian Abbott <abbotti@mev.co.uk>
To: Arnd Bergmann <arnd@arndb.de>,
	H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] staging/comedi/dt282x: avoid integer overflow warning
Date: Thu, 17 Mar 2016 10:21:50 +0000	[thread overview]
Message-ID: <56EA853E.10403@mev.co.uk> (raw)
In-Reply-To: <1458161501-283680-1-git-send-email-arnd@arndb.de>

On 16/03/16 20:51, Arnd Bergmann wrote:
> gcc-6 warns about passing negative signed integer into swab16()
> in the dt282x driver:
>
> drivers/staging/comedi/drivers/dt282x.c: In function 'dt282x_load_changain':
> include/uapi/linux/swab.h:14:33: warning: integer overflow in expression [-Woverflow]
>    (((__u16)(x) & (__u16)0xff00U) >> 8)))
>    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
> include/uapi/linux/swab.h:107:2: note: in expansion of macro '___constant_swab16'
>    ___constant_swab16(x) :   \
>    ^~~~~~~~~~~~~~~~~~
> include/uapi/linux/byteorder/big_endian.h:34:43: note: in expansion of macro '__swab16'
>   #define __cpu_to_le16(x) ((__force __le16)__swab16((x)))
>                                             ^~~~~~~~
> include/linux/byteorder/generic.h:89:21: note: in expansion of macro '__cpu_to_le16'
>   #define cpu_to_le16 __cpu_to_le16
>                       ^~~~~~~~~~~~~
> arch/arm/include/asm/io.h:250:6: note: in expansion of macro 'cpu_to_le16'
>        cpu_to_le16(v),__io(p)); })
>        ^~~~~~~~~~~
> drivers/staging/comedi/drivers/dt282x.c:566:2: note: in expansion of macro 'outw'
>    outw(DT2821_CHANCSR_LLE | DT2821_CHANCSR_NUMB(n),
>    ^~~~
>
> The warning makes sense, though the code is correct as far as I
> can tell.
>
> This disambiguates the operation by making the constant expressions
> we pass here explicitly 'unsigned', which helps to avoid the warning.
>
> As pointed out by Hartley Sweeten, scripts/checkpatch.pl notices that
> the shifts here are rather unreadable, though the suggested BIT()
> macro wouldn't work either. I'm changing it to a hexadecimal notation,
> which hopefully improves readability. I'm leaving the DT2821_CHANCSR_PRESLA
> alone because it seems wrong.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
> v2: also reformat to make checkpatch.pl happy
>
>   drivers/staging/comedi/drivers/dt282x.c | 72 ++++++++++++++++-----------------
>   1 file changed, 36 insertions(+), 36 deletions(-)
>
> diff --git a/drivers/staging/comedi/drivers/dt282x.c b/drivers/staging/comedi/drivers/dt282x.c
[snip]
> -#define DT2821_CHANCSR_LLE		(1 << 15)
> -#define DT2821_CHANCSR_PRESLA(x)	(((x) & 0xf) >> 8)
> -#define DT2821_CHANCSR_NUMB(x)		((((x) - 1) & 0xf) << 0)
> +#define DT2821_CHANCSR_LLE		0x8000u
> +#define DT2821_CHANCSR_PRESLA(x)	(((x) & 0xf) >> 8) /* always 0? */

The patch is fine, thanks.

Just a note on that dodgy-looking '>>' in the DT2821_CHANCSR_PRESLA 
macro.... I seems to be a typo in 0f8e8c5ab67a ("staging: comedi: 
dt282x: tidy up the register map and bit defines").  It should be a 
left-shift.  Fortunately, it isn't used, but we ought to correct it 
sometime.

Reviewed-by: Ian Abbott <abbotti@mev.co.uk>

-- 
-=( Ian Abbott @ MEV Ltd.    E-mail: <abbotti@mev.co.uk> )=-
-=(                          Web: http://www.mev.co.uk/  )=-

  reply	other threads:[~2016-03-17 10:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-16 20:51 Arnd Bergmann
2016-03-17 10:21 ` Ian Abbott [this message]
2016-03-17 15:47 ` Hartley Sweeten
2016-03-17 16:08   ` Arnd Bergmann
2016-03-17 16:59     ` Hartley Sweeten

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=56EA853E.10403@mev.co.uk \
    --to=abbotti@mev.co.uk \
    --cc=arnd@arndb.de \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=hsweeten@visionengravers.com \
    --cc=linux-kernel@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

all inboxes | Powered by JetHome®