mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Lorenzo Bianconi <lorenzo@kernel.org>
Cc: "Kees Cook" <kees@kernel.org>,
	"Kees Cook" <kees+treewide@kernel.org>,
	"David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-hardening@vger.kernel.org
Subject: Re: [PATCH] iio: imu: st_lsm6dsx: Allocate ext_channels with ARRAY_SIZE()
Date: Mon, 21 Sep 2026 00:22:47 +0100	[thread overview]
Message-ID: <20260921002247.7d7d08b1@jic23-hlaptop> (raw)
In-Reply-To: <aqzcxf84JEdoyzwA@lore-qca>

On Fri, 18 Sep 2026 08:40:05 +0200
Lorenzo Bianconi <lorenzo@kernel.org> wrote:

> > From: Kees Cook <kees+treewide@kernel.org>
> > 
> > In preparation for making the devm_kmalloc family of allocators type
> > aware, we need to make sure that the returned type from the allocation
> > matches the type of the variable being assigned. (Before, the allocator
> > would always return "void *", which can be implicitly cast to any
> > pointer type.)
> > 
> > This is allocating a copy of magn_channels, which is an array of struct
> > iio_chan_spec, but the size was taken from the whole array, which would
> > make the allocation type a pointer to the array rather than the
> > "struct iio_chan_spec *" being assigned. Allocate ARRAY_SIZE-many
> > entries instead. The resulting allocation size is the same.
> > 
> > Build tested ARCH=x86_64 allmodconfig with GCC 16.2.0:
> > drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.o
> > 
> > Assisted-by: LLM coccinelle
> > Signed-off-by: Kees Cook <kees+treewide@kernel.org>  
> 
> Acked-by: Lorenzo Bianconi <lorenzo@kernel.org>
Applied to the testing branch of iio.git (next merge window
material).

Thanks

Jonathan

> 
> > ---
> > Cc: Lorenzo Bianconi <lorenzo@kernel.org>
> > Cc: Jonathan Cameron <jic23@kernel.org>
> > Cc: David Lechner <dlechner@baylibre.com>
> > Cc: "Nuno Sá" <nuno.sa@analog.com>
> > Cc: Andy Shevchenko <andy@kernel.org>
> > Cc: <linux-iio@vger.kernel.org>
> > ---
> >  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
> > index d6a1eeb151ca..cbc47fa5b101 100644
> > --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
> > +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
> > @@ -766,8 +766,8 @@ st_lsm6dsx_shub_alloc_iiodev(struct st_lsm6dsx_hw *hw,
> >  			IIO_CHAN_SOFT_TIMESTAMP(3),
> >  		};
> >  
> > -		ext_channels = devm_kzalloc(hw->dev, sizeof(magn_channels),
> > -					    GFP_KERNEL);
> > +		ext_channels = devm_kcalloc(hw->dev, ARRAY_SIZE(magn_channels),
> > +					    sizeof(*ext_channels), GFP_KERNEL);
> >  		if (!ext_channels)
> >  			return NULL;
> >  
> > -- 
> > 2.34.1
> >   


      reply	other threads:[~2026-09-20 23:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-17 21:13 Kees Cook
2026-09-18  6:40 ` Lorenzo Bianconi
2026-09-20 23:22   ` 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=20260921002247.7d7d08b1@jic23-hlaptop \
    --to=jic23@kernel.org \
    --cc=andy@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=kees+treewide@kernel.org \
    --cc=kees@kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lorenzo@kernel.org \
    --cc=nuno.sa@analog.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

all inboxes | Powered by JetHome®