From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Linus Walleij <linusw@kernel.org>,
Bartosz Golaszewski <brgl@kernel.org>,
Andy Shevchenko <andy@kernel.org>,
Janusz Krzysztofik <jmkrzyszt@gmail.com>,
linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 6/7] gpiolib: avoid krealloc() in gpiod_get_array()
Date: Thu, 5 Nov 2026 00:05:32 +0200 [thread overview]
Message-ID: <auusLNvkCmHs1buP@ashevche-desk.local> (raw)
In-Reply-To: <73caedd26b375ae7671d24bcee115f05@gmail.com>
On Wed, Nov 04, 2026 at 01:51:52PM -0800, Dmitry Torokhov wrote:
> On Wed, Nov 04, 2026 at 11:40:18PM +0200, Andy Shevchenko wrote:
> > On Wed, Nov 04, 2026 at 10:14:49AM -0800, Dmitry Torokhov wrote:
> > > On Wed, Nov 04, 2026 at 02:20:53PM +0200, Andy Shevchenko wrote:
> > > > On Tue, Nov 03, 2026 at 07:40:34PM -0800, Dmitry Torokhov wrote:
...
> > > > > + bitmap_set(array_info->get_mask, 0, count);
> > > > > + bitmap_set(array_info->set_mask, 0, count);
> > > >
> > > > You don't need these, as memory is nullified.
> > > > Also note that we have bitmap_clear() IIRC.
> > >
> > > bitmap_set() sets bits 0 .. count - 1 to 1, not 0. Both get_mask and
> > > set_mask start with all count bits set (assuming all pins in the array
> > > are eligible for the fast path), and then gpio_descs_check_fastpath()
> > > clears individual bits for pins that do not qualify.
> >
> > Ah, indeed, but we still have bitmap_fill().
>
> bitmap_fill(dst, count) fills whole unsigned long words with 0xff
> without masking the tail bits in the last word. Here get_mask and
> set_mask are sized to max(gdev->ngpio, count) bits and passed to
> gpio_chip_get_multiple() and gpiochip_set_multiple(), which iterate up
> to gc->ngpio bits.
>
> When count < gdev->ngpio, bitmap_fill(mask, count) would leave bits
> count .. round_up(count, BITS_PER_LONG) - 1 set to 1, causing
> get_multiple/set_multiple to touch unrelated pins on the chip and access
> value_bitmap beyond count bits. So we really need bitmap_set(..., 0,
> count) here to set only the first count bits.
I see the point, thanks for elaboration.
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2026-11-04 22:05 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-04 3:40 [PATCH v2 0/7] gpiolib: scope-based management and cleanup for GPIO descriptor arrays Dmitry Torokhov
2026-11-04 3:40 ` [PATCH v2 1/7] gpiolib: fix GPIO descriptor leak in gpiod_get_array() Dmitry Torokhov
2026-11-04 12:06 ` Andy Shevchenko
2026-11-04 12:08 ` Andy Shevchenko
2026-11-04 3:40 ` [PATCH v2 2/7] gpiolib: fix fast-path cancellation " Dmitry Torokhov
2026-11-04 12:09 ` Andy Shevchenko
2026-11-04 3:40 ` [PATCH v2 3/7] gpiolib: of: return -ENOENT from of_gpio_count() stub Dmitry Torokhov
2026-11-04 12:07 ` Andy Shevchenko
2026-11-04 3:40 ` [PATCH v2 4/7] gpiolib: add support for scope-based management of GPIO descriptors Dmitry Torokhov
2026-11-04 12:10 ` Andy Shevchenko
2026-11-04 3:40 ` [PATCH v2 5/7] gpiolib: use __free(gpiod_put_array) in gpiod_get_array() Dmitry Torokhov
2026-11-04 12:13 ` Andy Shevchenko
2026-11-04 3:40 ` [PATCH v2 6/7] gpiolib: avoid krealloc() " Dmitry Torokhov
2026-11-04 12:20 ` Andy Shevchenko
2026-11-04 18:14 ` Dmitry Torokhov
2026-11-04 21:40 ` Andy Shevchenko
2026-11-04 21:51 ` Dmitry Torokhov
2026-11-04 22:05 ` Andy Shevchenko [this message]
2026-11-04 3:40 ` [PATCH v2 7/7] gpiolib: use bitmap_zalloc() for fastpath bitmaps Dmitry Torokhov
2026-11-04 12:17 ` 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=auusLNvkCmHs1buP@ashevche-desk.local \
--to=andriy.shevchenko@intel.com \
--cc=andy@kernel.org \
--cc=brgl@kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=jmkrzyszt@gmail.com \
--cc=linusw@kernel.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
all inboxes | Powered by JetHome®