Skip to contentSkip to conversation

gpio: fix memory leak in gpiod_request_commit()

PATCH In review Bartosz Golaszewski 1 participant 2 messages Feb 18, 2024 – Feb 19, 2024 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpio: fix memory leak in gpiod_request_commit()

From: Bartosz Golaszewski <[email protected]>

We now copy the label string directly in desc_set_label() so it must not be done a second time in gpiod_request_commit().

Fixes 1f2bcb8c8ccd ("gpio: protect the descriptor label with SRCU")
---
 drivers/gpio/gpiolib.c | 6 ------
 1 file changed, 6 deletions(-)
drivers/gpio/gpiolib.c +0 -6
index e4dd13d81b4d..3c22920bd201 100644
@@ -2250,12 +2250,6 @@ static int gpiod_request_commit(struct gpio_desc *desc, const char *label)
 	if (test_and_set_bit(FLAG_REQUESTED, &desc->flags))
 		return -EBUSY;
 
-	if (label) {
-		label = kstrdup_const(label, GFP_KERNEL);
-		if (!label)
-			return -ENOMEM;
-	}
-
 	/* NOTE:  gpio_request() can be called in early boot,
 	 * before IRQs are enabled, for non-sleeping (SOC) GPIOs.
 	 */
Signature · 1 line
2.40.1
#1 lore raw
Quoted 32 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

We now copy the label string directly in desc_set_label() so it must not be done a second time in gpiod_request_commit().

Fixes 1f2bcb8c8ccd ("gpio: protect the descriptor label with SRCU")
---
 drivers/gpio/gpiolib.c | 6 ------
 1 file changed, 6 deletions(-)
drivers/gpio/gpiolib.c +0 -7
index e4dd13d81b4d..3c22920bd201 100644
@@ -2250,12 +2250,6 @@ static int gpiod_request_commit(struct gpio_desc *desc, const char *label)
        if (test_and_set_bit(FLAG_REQUESTED, &desc->flags))
                return -EBUSY;
 
-       if (label) {
-               label = kstrdup_const(label, GFP_KERNEL);
-               if (!label)
-                       return -ENOMEM;
-       }
-
        /* NOTE:  gpio_request() can be called in early boot,
         * before IRQs are enabled, for non-sleeping (SOC) GPIOs.
         */
--
Quoted 2 lines

2.40.1

I should probably stop coding while sleep-deprived and in the evening, I realized now I sent the exact same fix as you. I thought this was removing the allocation from desc_set_label() and not gpiod_request_commit().

I'll go ahead and apply your patch and you can disregard this thread.

Thanks!
Bartosz