Commit
851bb4a42991666f515040e95e6f40191da9e899
gpio: kunit: fix GPIO device reference leak with __free()
KUnit aborts the test thread immediately using kthread_exit() so the
variable annotated with __free() never really goes out of scope and the
associated callback is not called. Schedule a kunit action instead.
Fixes: a05cfd98c5ec ("gpio: kunit: add test cases for software node hogs")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/patchset/20261013-gpio-kunit-plat-lookup-v3-0-3907f913e964%40oss.qualcomm.com?part=1
Link: https://patch.msgid.link/20261014-gpio-kunit-autofree-leak-fix-v1-1-5bfa7be0eb1f@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com> · 2026-10-14 08:44 UTC
1 file changed,
+7
−2
modified drivers/gpio/gpiolib-kunit.c
| @@ -28,6 +28,8 @@ | |||
| 28 | 28 | ||
| 29 | 29 | #define GPIO_TEST_PROVIDER_NGPIO 4 | |
| 30 | 30 | ||
| 31 | + | KUNIT_DEFINE_ACTION_WRAPPER(gpio_device_put_wrapper, gpio_device_put, struct gpio_device *); | |
| 32 | + | ||
| 31 | 33 | /* | |
| 32 | 34 | * The test provider tracks per-line direction and value so that lines can be | |
| 33 | 35 | * driven as both inputs and outputs - this is needed to exercise input as well | |
| @@ -770,6 +772,7 @@ static void gpio_hog_assert(struct kunit *test, unsigned int offset, | |||
| 770 | 772 | struct property_entry properties[2]; | |
| 771 | 773 | struct platform_device *pdev; | |
| 772 | 774 | struct fwnode_handle *fwnode; | |
| 775 | + | struct gpio_device *gdev; | |
| 773 | 776 | struct gpio_desc *desc; | |
| 774 | 777 | bool bound = true; | |
| 775 | 778 | int ret; | |
| @@ -789,10 +792,12 @@ static void gpio_hog_assert(struct kunit *test, unsigned int offset, | |||
| 789 | 792 | wait_for_device_probe(); | |
| 790 | 793 | ||
| 791 | 794 | /* The hog must have configured the line with the expected direction. */ | |
| 792 | - | struct gpio_device *gdev __free(gpio_device_put) = | |
| 793 | - | gpio_device_find_by_label(GPIO_CONSUMER_NAME); | |
| 795 | + | gdev = gpio_device_find_by_label(GPIO_CONSUMER_NAME); | |
| 794 | 796 | KUNIT_ASSERT_NOT_ERR_OR_NULL(test, gdev); | |
| 795 | 797 | ||
| 798 | + | ret = kunit_add_action_or_reset(test, gpio_device_put_wrapper, gdev); | |
| 799 | + | KUNIT_ASSERT_EQ(test, ret, 0); | |
| 800 | + | ||
| 796 | 801 | desc = gpio_device_get_desc(gdev, offset); | |
| 797 | 802 | KUNIT_ASSERT_NOT_ERR_OR_NULL(test, desc); | |
| 798 | 803 | ||