Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

gpio: Ensure struct gpio_chip for gpiochip_setup_dev()

Ensure struct gpio_chip for gpiochip_setup_dev(). This eliminates a few
checks for struct gpio_chip.

Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://patch.msgid.link/20260223061726.82161-5-tzungbi@kernel.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>

authored by

Tzung-Bi Shih and committed by
Bartosz Golaszewski
cf674f1a 395b8e55

+32 -33
+4 -10
drivers/gpio/gpiolib-cdev.c
··· 2733 2733 #endif 2734 2734 }; 2735 2735 2736 - int gpiolib_cdev_register(struct gpio_device *gdev, dev_t devt) 2736 + int gpiolib_cdev_register(struct gpio_chip *gc, dev_t devt) 2737 2737 { 2738 - struct gpio_chip *gc; 2738 + struct gpio_device *gdev = gc->gpiodev; 2739 2739 int ret; 2740 + 2741 + lockdep_assert_held(&gdev->srcu); 2740 2742 2741 2743 cdev_init(&gdev->chrdev, &gpio_fileops); 2742 2744 gdev->chrdev.owner = THIS_MODULE; ··· 2753 2751 if (ret) { 2754 2752 destroy_workqueue(gdev->line_state_wq); 2755 2753 return ret; 2756 - } 2757 - 2758 - guard(srcu)(&gdev->srcu); 2759 - gc = srcu_dereference(gdev->chip, &gdev->srcu); 2760 - if (!gc) { 2761 - cdev_device_del(&gdev->chrdev, &gdev->dev); 2762 - destroy_workqueue(gdev->line_state_wq); 2763 - return -ENODEV; 2764 2754 } 2765 2755 2766 2756 gpiochip_dbg(gc, "added GPIO chardev (%d:%d)\n", MAJOR(devt), gdev->id);
+1 -1
drivers/gpio/gpiolib-cdev.h
··· 7 7 8 8 struct gpio_device; 9 9 10 - int gpiolib_cdev_register(struct gpio_device *gdev, dev_t devt); 10 + int gpiolib_cdev_register(struct gpio_chip *gc, dev_t devt); 11 11 void gpiolib_cdev_unregister(struct gpio_device *gdev); 12 12 13 13 #endif /* GPIOLIB_CDEV_H */
+8 -13
drivers/gpio/gpiolib-sysfs.c
··· 983 983 } 984 984 EXPORT_SYMBOL_GPL(gpiod_unexport); 985 985 986 - int gpiochip_sysfs_register(struct gpio_device *gdev) 986 + int gpiochip_sysfs_register(struct gpio_chip *gc) 987 987 { 988 + struct gpio_device *gdev = gc->gpiodev; 988 989 struct gpiodev_data *data; 989 - struct gpio_chip *chip; 990 990 struct device *parent; 991 991 int err; 992 + 993 + lockdep_assert_held(&gdev->srcu); 992 994 993 995 /* 994 996 * Many systems add gpio chips for SOC support very early, ··· 1001 999 if (!class_is_registered(&gpio_class)) 1002 1000 return 0; 1003 1001 1004 - guard(srcu)(&gdev->srcu); 1005 - 1006 - chip = srcu_dereference(gdev->chip, &gdev->srcu); 1007 - if (!chip) 1008 - return -ENODEV; 1009 - 1010 1002 /* 1011 1003 * For sysfs backward compatibility we need to preserve this 1012 1004 * preferred parenting to the gpio_chip parent field, if set. 1013 1005 */ 1014 - if (chip->parent) 1015 - parent = chip->parent; 1006 + if (gc->parent) 1007 + parent = gc->parent; 1016 1008 else 1017 1009 parent = &gdev->dev; 1018 1010 ··· 1025 1029 MKDEV(0, 0), data, 1026 1030 gpiochip_groups, 1027 1031 GPIOCHIP_NAME "%d", 1028 - chip->base); 1032 + gc->base); 1029 1033 if (IS_ERR(data->cdev_base)) { 1030 1034 err = PTR_ERR(data->cdev_base); 1031 1035 kfree(data); ··· 1081 1085 */ 1082 1086 static int gpiofind_sysfs_register(struct gpio_chip *gc, const void *data) 1083 1087 { 1084 - struct gpio_device *gdev = gc->gpiodev; 1085 1088 int ret; 1086 1089 1087 - ret = gpiochip_sysfs_register(gdev); 1090 + ret = gpiochip_sysfs_register(gc); 1088 1091 if (ret) 1089 1092 gpiochip_err(gc, "failed to register the sysfs entry: %d\n", ret); 1090 1093
+2 -2
drivers/gpio/gpiolib-sysfs.h
··· 7 7 8 8 #ifdef CONFIG_GPIO_SYSFS 9 9 10 - int gpiochip_sysfs_register(struct gpio_device *gdev); 10 + int gpiochip_sysfs_register(struct gpio_chip *gc); 11 11 void gpiochip_sysfs_unregister(struct gpio_chip *gc); 12 12 13 13 #else 14 14 15 - static inline int gpiochip_sysfs_register(struct gpio_device *gdev) 15 + static inline int gpiochip_sysfs_register(struct gpio_chip *gc) 16 16 { 17 17 return 0; 18 18 }
+17 -7
drivers/gpio/gpiolib.c
··· 882 882 }; 883 883 884 884 #ifdef CONFIG_GPIO_CDEV 885 - #define gcdev_register(gdev, devt) gpiolib_cdev_register((gdev), (devt)) 885 + #define gcdev_register(gc, devt) gpiolib_cdev_register((gc), (devt)) 886 886 #define gcdev_unregister(gdev) gpiolib_cdev_unregister((gdev)) 887 887 #else 888 888 /* 889 889 * gpiolib_cdev_register() indirectly calls device_add(), which is still 890 890 * required even when cdev is not selected. 891 891 */ 892 - #define gcdev_register(gdev, devt) device_add(&(gdev)->dev) 892 + #define gcdev_register(gc, devt) device_add(&(gc)->gpiodev->dev) 893 893 #define gcdev_unregister(gdev) device_del(&(gdev)->dev) 894 894 #endif 895 895 ··· 897 897 * An initial reference count has been held in gpiochip_add_data_with_key(). 898 898 * The caller should drop the reference via gpio_device_put() on errors. 899 899 */ 900 - static int gpiochip_setup_dev(struct gpio_device *gdev) 900 + static int gpiochip_setup_dev(struct gpio_chip *gc) 901 901 { 902 + struct gpio_device *gdev = gc->gpiodev; 902 903 struct fwnode_handle *fwnode = dev_fwnode(&gdev->dev); 903 904 int ret; 904 905 ··· 912 911 if (fwnode && !fwnode->dev) 913 912 fwnode_dev_initialized(fwnode, false); 914 913 915 - ret = gcdev_register(gdev, gpio_devt); 914 + ret = gcdev_register(gc, gpio_devt); 916 915 if (ret) 917 916 return ret; 918 917 919 - ret = gpiochip_sysfs_register(gdev); 918 + ret = gpiochip_sysfs_register(gc); 920 919 if (ret) 921 920 goto err_remove_device; 922 921 ··· 963 962 static void gpiochip_setup_devs(void) 964 963 { 965 964 struct gpio_device *gdev; 965 + struct gpio_chip *gc; 966 966 int ret; 967 967 968 968 guard(srcu)(&gpio_devices_srcu); 969 969 970 970 list_for_each_entry_srcu(gdev, &gpio_devices, list, 971 971 srcu_read_lock_held(&gpio_devices_srcu)) { 972 - ret = gpiochip_setup_dev(gdev); 972 + guard(srcu)(&gdev->srcu); 973 + 974 + gc = srcu_dereference(gdev->chip, &gdev->srcu); 975 + if (!gc) { 976 + dev_err(&gdev->dev, "Underlying GPIO chip is gone\n"); 977 + continue; 978 + } 979 + 980 + ret = gpiochip_setup_dev(gc); 973 981 if (ret) { 974 982 gpio_device_put(gdev); 975 983 dev_err(&gdev->dev, ··· 1236 1226 * (i.e., `gpio_bus_type` is ready). Otherwise, defer until later. 1237 1227 */ 1238 1228 if (gpiolib_initialized) { 1239 - ret = gpiochip_setup_dev(gdev); 1229 + ret = gpiochip_setup_dev(gc); 1240 1230 if (ret) 1241 1231 goto err_teardown_shared; 1242 1232 }