[bug report] gpio: protect the pointer to gpio_chip in gpio_device with SRCU

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello Bartosz Golaszewski,

The patch d83cee3d2bb1: "gpio: protect the pointer to gpio_chip in
gpio_device with SRCU" from Jan 23, 2024 (linux-next), leads to the
following Smatch static checker warning:

	drivers/gpio/gpiolib-sysfs.c:808 gpiochip_sysfs_unregister()
	error: we previously assumed 'chip' could be null (see line 804)

drivers/gpio/gpiolib-sysfs.c
    786 void gpiochip_sysfs_unregister(struct gpio_device *gdev)
    787 {
    788         struct gpio_desc *desc;
    789         struct gpio_chip *chip;
    790 
    791         scoped_guard(mutex, &sysfs_lock) {
    792                 if (!gdev->mockdev)
    793                         return;
    794 
    795                 device_unregister(gdev->mockdev);
    796 
    797                 /* prevent further gpiod exports */
    798                 gdev->mockdev = NULL;
    799         }
    800 
    801         guard(srcu)(&gdev->srcu);
    802 
    803         chip = rcu_dereference(gdev->chip);
    804         if (chip)
                    ^^^^
Is this test reversed?

    805                 return;
    806 
    807         /* unregister gpiod class devices owned by sysfs */
--> 808         for_each_gpio_desc_with_flag(chip, desc, FLAG_SYSFS) {
                                             ^^^^
NULL dereference

    809                 gpiod_unexport(desc);
    810                 gpiod_free(desc);
    811         }
    812 }

regards,
dan carpenter




[Index of Archives]     [Linux SPI]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux