Linux IIO development
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Marcus Folkesson <marcus.folkesson@gmail.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>,
	Kent Gustavsson <kent@minoris.se>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Andy Shevchenko <andy.shevchenko@gmail.com>,
	linux-iio@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] iio: adc: mcp3911: fix sizeof() vs ARRAY_SIZE() bug
Date: Sun, 2 Oct 2022 13:20:53 +0100	[thread overview]
Message-ID: <20221002132053.113f595f@jic23-huawei> (raw)
In-Reply-To: <YzGKolEWAZ0Z/fQf@gmail.com>

On Mon, 26 Sep 2022 13:18:58 +0200
Marcus Folkesson <marcus.folkesson@gmail.com> wrote:

> Hi,
> 
> Good catch.
> Too bad I missed it.
> 
> /Marcus
> 
> On Mon, Sep 26, 2022 at 12:10:37PM +0300, Dan Carpenter wrote:
> > This code uses sizeof() instead of ARRAY_SIZE() so it reads beyond the
> > end of the mcp3911_osr_table[] array.
> > 
> > Fixes: 6d965885f4ea ("iio: adc: mcp3911: add support for oversampling ratio")
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>  
> 
> Reviewed-by: Marcus Folkesson <marcus.folkesson@gmail.com>
Applied to the fixes-togreg branch of iio.git, but I'm not going to push that
tree out until Linus takes the char-misc-next pull request as otherwise I'll make
a mess of linux-next as the trees will effectively merge out of normal order.

Jonathan

> 
> > ---
> >  drivers/iio/adc/mcp3911.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/iio/adc/mcp3911.c b/drivers/iio/adc/mcp3911.c
> > index b35fd2c9c3c0..015a9ffdb26a 100644
> > --- a/drivers/iio/adc/mcp3911.c
> > +++ b/drivers/iio/adc/mcp3911.c
> > @@ -248,7 +248,7 @@ static int mcp3911_write_raw(struct iio_dev *indio_dev,
> >  		break;
> >  
> >  	case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
> > -		for (int i = 0; i < sizeof(mcp3911_osr_table); i++) {
> > +		for (int i = 0; i < ARRAY_SIZE(mcp3911_osr_table); i++) {
> >  			if (val == mcp3911_osr_table[i]) {
> >  				val = FIELD_PREP(MCP3911_CONFIG_OSR, i);
> >  				ret = mcp3911_update(adc, MCP3911_REG_CONFIG, MCP3911_CONFIG_OSR,
> > -- 
> > 2.35.1
> >   


      reply	other threads:[~2022-10-02 12:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-26  9:10 [PATCH] iio: adc: mcp3911: fix sizeof() vs ARRAY_SIZE() bug Dan Carpenter
2022-09-26 11:18 ` Marcus Folkesson
2022-10-02 12:20   ` Jonathan Cameron [this message]

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=20221002132053.113f595f@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=andy.shevchenko@gmail.com \
    --cc=dan.carpenter@oracle.com \
    --cc=kent@minoris.se \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=marcus.folkesson@gmail.com \
    /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