linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: cmo@melexis.com
Cc: linux-iio@vger.kernel.org
Subject: re: iio: mlx90614: Implement filter configuration
Date: Fri, 2 Oct 2015 01:16:09 +0300	[thread overview]
Message-ID: <20151001221609.GA3694@mwanda> (raw)

Hello Crt Mori,

The patch 764589b688a1: "iio: mlx90614: Implement filter
configuration" from Aug 17, 2015, leads to the following static
checker warning:

	drivers/iio/temperature/mlx90614.c:167 mlx90614_iir_search()
	warn: this cast is a no-op

drivers/iio/temperature/mlx90614.c
   158          ret = i2c_smbus_read_word_data(client, MLX90614_CONFIG);
   159          if (ret > 0)
   160                  return ret;
   161  
   162          /* Write changed values */
   163          ret = mlx90614_write_word(client, MLX90614_CONFIG,
   164                          (i << MLX90614_CONFIG_IIR_SHIFT) |
   165                          (((u16) ((0x7 << MLX90614_CONFIG_FIR_SHIFT) |
   166                          ((u16) ret & (~((u16) MLX90614_CONFIG_FIR_MASK))))) &
   167                          (~(u16) MLX90614_CONFIG_IIR_MASK)));

Quite a few of these casts make no sense.  It's not clear what was
intended.

	(~(u16) MLX90614_CONFIG_IIR_MASK)

So we take int 0x7 and cast it to u16, then because of type promotion
we convert it to int and do a bitwise negate.  The static checker
warning is because often that means (u16)~MLX90614_CONFIG_IIR_MASK is
intended instead.  In this case it looks like we could just remove the
cast with no harm done.

But why are we ANDing it with "ret" which is a negative error code???
I think there is some other typo here beyond the extra casts.

   168          return ret;

regards,
dan carpenter

             reply	other threads:[~2015-10-01 22:16 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-01 22:16 Dan Carpenter [this message]
2015-10-01 23:09 ` iio: mlx90614: Implement filter configuration Crt Mori
2015-10-02  7:00   ` Dan Carpenter
2015-10-02  8:12     ` Crt Mori
2015-10-02  8:32       ` Dan Carpenter
2015-10-02  8:48         ` Crt Mori
2015-10-02  8:56           ` Dan Carpenter
2015-10-02  9:04             ` Crt Mori

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=20151001221609.GA3694@mwanda \
    --to=dan.carpenter@oracle.com \
    --cc=cmo@melexis.com \
    --cc=linux-iio@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).