Re: [PATCH v6 2/8] gpiolib: free the label of lines released after their chip was removed

From: Andy Shevchenko

Date: Tue Nov 17 2026 - 03:33:35 EST


On Mon, Nov 16, 2026 at 03:47:05PM +0200, Adrian Ambrozewicz wrote:
> gpiod_free_commit() drops the consumer label only while the chip is
> still there. A line that user space keeps requested across
> gpiochip_remove() is released when gdev->chip is already NULL, and its
> label leaks:
>
> unreferenced object (size 32):
> comm "gpio-hold"
> backtrace (crc 7ff222d9):
> desc_set_label
> gpiod_request_commit
> gpiod_request
> linereq_create
> gpio_ioctl
>
> Clear the label before the chip check. The ->free() callback, the flags
> update and the line state notification need the chip and stay under it.
>
> Reproduced with gpio-sim: request a line, set the chip's "live"
> attribute to 0, then close the request. kmemleak reports up to 30 such
> objects after 30 cycles; with this change, none after 100.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>

--
With Best Regards,
Andy Shevchenko