linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>
To: d binderman <dcb314-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org>
Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: i2c/busses/i2c-highlander.c: using char variable in bit operation
Date: Mon, 1 Feb 2010 11:07:21 +0100	[thread overview]
Message-ID: <20100201110721.461fd142@hyperion.delvare> (raw)
In-Reply-To: <BLU108-W10538CE8A7EF6373FB36AE9C580-MsuGFMq8XAE@public.gmane.org>

On Mon, 1 Feb 2010 09:51:42 +0000, d binderman wrote:
> 
> 
> Hello there,
> 
> I just ran the sourceforge tool cppcheck over the source code of the
> new Linux kernel 2.6.33-rc6
> 
> It said
> 
> [./i2c/busses/i2c-highlander.c:284]: (style) Warning - using char variable in bit operation
> 
> The source code is
> 
> static int highlander_i2c_smbus_xfer(struct i2c_adapter *adap, u16 addr,
>                                   unsigned short flags, char read_write,
>                                   u8 command, int size,
>                                   union i2c_smbus_data *data)
> {
>         struct highlander_i2c_dev *dev = i2c_get_adapdata(adap);
>         int read = read_write & I2C_SMBUS_READ;
> 
> In C, chars can be signed or unsigned, so the value written into
> local variable read by sign extension is not certain.
> 
> Suggest new code
> 
> static int highlander_i2c_smbus_xfer(struct i2c_adapter *adap, u16 addr,
>                                   unsigned short flags, char read_write,
>                                   u8 command, int size,
>                                   union i2c_smbus_data *data)
> {
>         struct highlander_i2c_dev *dev = i2c_get_adapdata(adap);
>         int read = ((unsigned char) read_write) & I2C_SMBUS_READ;

read_write can only have value 0 or 1, so we don't care if chars are
signed or not. That being said, the code above looks odd, the value of
read_write can be used in the code directly without using an
intermediate variable:

	iowrite16((addr << 1) | read_write, dev->base + SMSMADR);

This would solve your warning issue and make the code more simple too.

-- 
Jean Delvare

  parent reply	other threads:[~2010-02-01 10:07 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-01  9:51 i2c/busses/i2c-highlander.c: using char variable in bit operation d binderman
     [not found] ` <BLU108-W10538CE8A7EF6373FB36AE9C580-MsuGFMq8XAE@public.gmane.org>
2010-02-01 10:07   ` Jean Delvare [this message]
     [not found]     ` <20100201110721.461fd142-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2010-02-01 10:15       ` Wolfram Sang
     [not found]         ` <20100201101509.GB3288-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2010-02-02 12:17           ` [PATCH] i2c/highlander: remover superflous variable Wolfram Sang
     [not found]             ` <1265113063-22894-1-git-send-email-w.sang-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2010-02-02 12:29               ` Jean Delvare
2010-02-02 14:31               ` Paul Mundt

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=20100201110721.461fd142@hyperion.delvare \
    --to=khali-puyad+kwke1g9huczpvpmw@public.gmane.org \
    --cc=dcb314-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org \
    --cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.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).