public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Bartosz Golaszewski <brgl@bgdev.pl>,
	linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
	Linus Walleij <linus.walleij@linaro.org>
Subject: Re: [PATCH v1 2/2] gpiolib: of: Integrate of_gpiochip_init_valid_mask() into gpiochip_init_valid_mask()
Date: Tue, 8 Nov 2022 10:41:42 +0200	[thread overview]
Message-ID: <Y2oWRofuTzPbzHdE@smile.fi.intel.com> (raw)
In-Reply-To: <Y2l7ZRe7+wb9YkEm@google.com>

On Mon, Nov 07, 2022 at 01:40:53PM -0800, Dmitry Torokhov wrote:
> On Mon, Nov 07, 2022 at 11:09:19PM +0200, Andy Shevchenko wrote:
> > On Mon, Nov 07, 2022 at 10:20:37AM -0800, Dmitry Torokhov wrote:
> > > On Mon, Nov 07, 2022 at 06:10:27PM +0200, Andy Shevchenko wrote:

...

> > > > +static int gpiochip_apply_reserved_ranges(struct gpio_chip *gc, unsigned int sz)
> > > > +{
> > > > +	u32 *ranges;
> > > > +	int ret;
> > > > +
> > > > +	ranges = kmalloc_array(sz, sizeof(*ranges), GFP_KERNEL);
> > > > +	if (!ranges)
> > > > +		return -ENOMEM;
> > > > +
> > > > +	ret = fwnode_property_read_u32_array(gc->fwnode, "gpio-reserved-ranges", ranges, sz);
> > > > +	if (ret) {
> > > > +		kfree(ranges);
> > > > +		return ret;
> > > > +	}
> > > > +
> > > > +	while (sz) {
> > > > +		u32 count = ranges[--sz];
> > > > +		u32 start = ranges[--sz];
> > > 
> > > I know we checked sz validity, but I wonder if re-checking it in this
> > > function would not insulate us from errors creeping in after some other
> > > code refactoring.
> > 
> > I'm not sure I understand what you meant. The fwnode_property_read_u32_array()
> > will fail if the given sz is too big for the real data, so while (sz) would
> > never even go on the invalid data.
> 
> I am more worried about sz being odd and the loop ending up trying to
> dereference ranges[-1].

I see. What if we take amount of ranges as the parameter and convert to size by
multiplying by 2?

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2022-11-08  8:42 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-07 16:10 [PATCH v1 1/2] gpiolib: of: Prepare of_gpiochip_add() / of_gpiochip_remove() for fwnode Andy Shevchenko
2022-11-07 16:10 ` [PATCH v1 2/2] gpiolib: of: Integrate of_gpiochip_init_valid_mask() into gpiochip_init_valid_mask() Andy Shevchenko
2022-11-07 18:20   ` Dmitry Torokhov
2022-11-07 21:09     ` Andy Shevchenko
2022-11-07 21:40       ` Dmitry Torokhov
2022-11-08  8:41         ` Andy Shevchenko [this message]
2022-11-08 13:23           ` Andy Shevchenko
2022-11-07 18:14 ` [PATCH v1 1/2] gpiolib: of: Prepare of_gpiochip_add() / of_gpiochip_remove() for fwnode Dmitry Torokhov
2022-11-09 13:13 ` Bartosz Golaszewski
2022-11-09 13:13   ` Bartosz Golaszewski
2022-11-09 13:23     ` Andy Shevchenko

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=Y2oWRofuTzPbzHdE@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=brgl@bgdev.pl \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --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