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.

Merge tag 'gpio-fixes-for-v6.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux

Pull gpio fixes from Bartosz Golaszewski:
"Apart from some regular driver fixes there's a relatively big revert
of the locking changes that were introduced to GPIOLIB in this merge
window.

This is because it turned out that some legacy GPIO interfaces - that
need to translate a number from the global GPIO numberspace to the
address of the relevant descriptor, thus running a GPIO device lookup
and taking the GPIO device list lock - are still used in old code from
atomic context resulting in "scheduling while atomic" errors.

I'll try to make the read-only part of the list access entirely
lockless using SRCU but this will take some time so let's go back to
the old global spinlock for now.

Summary:

- revert the changes aiming to use a read-write semaphore to protect
the list of GPIO devices due to calls to legacy API taking that
lock from atomic context in old code

- fix inverted logic in DEFINE_FREE() for GPIO device references

- check the return value of bgpio_init() in gpio-mlxbf3

- fix node address in the DT bindings example for gpio-xilinx

- fix signedness bug in gpio-rtd

- fix kernel-doc warnings in gpio-en7523"

* tag 'gpio-fixes-for-v6.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux:
gpiolib: revert the attempt to protect the GPIO device list with an rwsem
gpio: EN7523: fix kernel-doc warnings
gpiolib: Fix scope-based gpio_device refcounting
gpio: mlxbf3: add an error code check in mlxbf3_gpio_probe
dt-bindings: gpio: xilinx: Fix node address in gpio
gpio: rtd: Fix signedness bug in probe

+114 -101
+1 -1
Documentation/devicetree/bindings/gpio/xlnx,gpio-xilinx.yaml
··· 126 126 - | 127 127 #include <dt-bindings/interrupt-controller/arm-gic.h> 128 128 129 - gpio@e000a000 { 129 + gpio@a0020000 { 130 130 compatible = "xlnx,xps-gpio-1.00.a"; 131 131 reg = <0xa0020000 0x10000>; 132 132 #gpio-cells = <2>;
+3 -3
drivers/gpio/gpio-en7523.c
··· 12 12 #define AIROHA_GPIO_MAX 32 13 13 14 14 /** 15 - * airoha_gpio_ctrl - Airoha GPIO driver data 15 + * struct airoha_gpio_ctrl - Airoha GPIO driver data 16 16 * @gc: Associated gpio_chip instance. 17 17 * @data: The data register. 18 - * @dir0: The direction register for the lower 16 pins. 19 - * @dir1: The direction register for the higher 16 pins. 18 + * @dir: [0] The direction register for the lower 16 pins. 19 + * [1]: The direction register for the higher 16 pins. 20 20 * @output: The output enable register. 21 21 */ 22 22 struct airoha_gpio_ctrl {
+2
drivers/gpio/gpio-mlxbf3.c
··· 215 215 gs->gpio_clr_io + MLXBF_GPIO_FW_DATA_OUT_CLEAR, 216 216 gs->gpio_set_io + MLXBF_GPIO_FW_OUTPUT_ENABLE_SET, 217 217 gs->gpio_clr_io + MLXBF_GPIO_FW_OUTPUT_ENABLE_CLEAR, 0); 218 + if (ret) 219 + return dev_err_probe(dev, ret, "%s: bgpio_init() failed", __func__); 218 220 219 221 gc->request = gpiochip_generic_request; 220 222 gc->free = gpiochip_generic_free;
+9 -6
drivers/gpio/gpio-rtd.c
··· 525 525 struct device *dev = &pdev->dev; 526 526 struct gpio_irq_chip *irq_chip; 527 527 struct rtd_gpio *data; 528 + int ret; 528 529 529 530 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); 530 531 if (!data) 531 532 return -ENOMEM; 532 533 533 - data->irqs[0] = platform_get_irq(pdev, 0); 534 - if (data->irqs[0] < 0) 535 - return data->irqs[0]; 534 + ret = platform_get_irq(pdev, 0); 535 + if (ret < 0) 536 + return ret; 537 + data->irqs[0] = ret; 536 538 537 - data->irqs[1] = platform_get_irq(pdev, 1); 538 - if (data->irqs[1] < 0) 539 - return data->irqs[1]; 539 + ret = platform_get_irq(pdev, 1); 540 + if (ret < 0) 541 + return ret; 542 + data->irqs[1] = ret; 540 543 541 544 data->info = device_get_match_data(dev); 542 545 if (!data->info)
+24 -21
drivers/gpio/gpiolib-sysfs.c
··· 768 768 return 0; 769 769 } 770 770 771 - int gpiochip_sysfs_register_all(void) 772 - { 773 - struct gpio_device *gdev; 774 - int ret; 775 - 776 - guard(rwsem_read)(&gpio_devices_sem); 777 - 778 - list_for_each_entry(gdev, &gpio_devices, list) { 779 - if (gdev->mockdev) 780 - continue; 781 - 782 - ret = gpiochip_sysfs_register(gdev); 783 - if (ret) 784 - return ret; 785 - } 786 - 787 - return 0; 788 - } 789 - 790 771 void gpiochip_sysfs_unregister(struct gpio_device *gdev) 791 772 { 792 773 struct gpio_desc *desc; ··· 792 811 793 812 static int __init gpiolib_sysfs_init(void) 794 813 { 795 - int status; 814 + int status; 815 + unsigned long flags; 816 + struct gpio_device *gdev; 796 817 797 818 status = class_register(&gpio_class); 798 819 if (status < 0) ··· 806 823 * We run before arch_initcall() so chip->dev nodes can have 807 824 * registered, and so arch_initcall() can always gpiod_export(). 808 825 */ 809 - return gpiochip_sysfs_register_all(); 826 + spin_lock_irqsave(&gpio_lock, flags); 827 + list_for_each_entry(gdev, &gpio_devices, list) { 828 + if (gdev->mockdev) 829 + continue; 830 + 831 + /* 832 + * TODO we yield gpio_lock here because 833 + * gpiochip_sysfs_register() acquires a mutex. This is unsafe 834 + * and needs to be fixed. 835 + * 836 + * Also it would be nice to use gpio_device_find() here so we 837 + * can keep gpio_chips local to gpiolib.c, but the yield of 838 + * gpio_lock prevents us from doing this. 839 + */ 840 + spin_unlock_irqrestore(&gpio_lock, flags); 841 + status = gpiochip_sysfs_register(gdev); 842 + spin_lock_irqsave(&gpio_lock, flags); 843 + } 844 + spin_unlock_irqrestore(&gpio_lock, flags); 845 + 846 + return status; 810 847 } 811 848 postcore_initcall(gpiolib_sysfs_init);
-6
drivers/gpio/gpiolib-sysfs.h
··· 8 8 #ifdef CONFIG_GPIO_SYSFS 9 9 10 10 int gpiochip_sysfs_register(struct gpio_device *gdev); 11 - int gpiochip_sysfs_register_all(void); 12 11 void gpiochip_sysfs_unregister(struct gpio_device *gdev); 13 12 14 13 #else 15 14 16 15 static inline int gpiochip_sysfs_register(struct gpio_device *gdev) 17 - { 18 - return 0; 19 - } 20 - 21 - static inline int gpiochip_sysfs_register_all(void) 22 16 { 23 17 return 0; 24 18 }
+74 -61
drivers/gpio/gpiolib.c
··· 2 2 3 3 #include <linux/acpi.h> 4 4 #include <linux/bitmap.h> 5 - #include <linux/cleanup.h> 6 5 #include <linux/compat.h> 7 6 #include <linux/debugfs.h> 8 7 #include <linux/device.h> ··· 15 16 #include <linux/kernel.h> 16 17 #include <linux/list.h> 17 18 #include <linux/module.h> 18 - #include <linux/mutex.h> 19 19 #include <linux/of.h> 20 20 #include <linux/pinctrl/consumer.h> 21 21 #include <linux/seq_file.h> ··· 81 83 82 84 static DEFINE_MUTEX(gpio_lookup_lock); 83 85 static LIST_HEAD(gpio_lookup_list); 84 - 85 86 LIST_HEAD(gpio_devices); 86 - DECLARE_RWSEM(gpio_devices_sem); 87 87 88 88 static DEFINE_MUTEX(gpio_machine_hogs_mutex); 89 89 static LIST_HEAD(gpio_machine_hogs); ··· 113 117 struct gpio_desc *gpio_to_desc(unsigned gpio) 114 118 { 115 119 struct gpio_device *gdev; 120 + unsigned long flags; 116 121 117 - scoped_guard(rwsem_read, &gpio_devices_sem) { 118 - list_for_each_entry(gdev, &gpio_devices, list) { 119 - if (gdev->base <= gpio && 120 - gdev->base + gdev->ngpio > gpio) 121 - return &gdev->descs[gpio - gdev->base]; 122 + spin_lock_irqsave(&gpio_lock, flags); 123 + 124 + list_for_each_entry(gdev, &gpio_devices, list) { 125 + if (gdev->base <= gpio && 126 + gdev->base + gdev->ngpio > gpio) { 127 + spin_unlock_irqrestore(&gpio_lock, flags); 128 + return &gdev->descs[gpio - gdev->base]; 122 129 } 123 130 } 131 + 132 + spin_unlock_irqrestore(&gpio_lock, flags); 124 133 125 134 if (!gpio_is_valid(gpio)) 126 135 pr_warn("invalid GPIO %d\n", gpio); ··· 399 398 static struct gpio_desc *gpio_name_to_desc(const char * const name) 400 399 { 401 400 struct gpio_device *gdev; 401 + unsigned long flags; 402 402 403 403 if (!name) 404 404 return NULL; 405 405 406 - guard(rwsem_read)(&gpio_devices_sem); 406 + spin_lock_irqsave(&gpio_lock, flags); 407 407 408 408 list_for_each_entry(gdev, &gpio_devices, list) { 409 409 struct gpio_desc *desc; 410 410 411 411 for_each_gpio_desc(gdev->chip, desc) { 412 - if (desc->name && !strcmp(desc->name, name)) 412 + if (desc->name && !strcmp(desc->name, name)) { 413 + spin_unlock_irqrestore(&gpio_lock, flags); 413 414 return desc; 415 + } 414 416 } 415 417 } 418 + 419 + spin_unlock_irqrestore(&gpio_lock, flags); 416 420 417 421 return NULL; 418 422 } ··· 813 807 struct lock_class_key *request_key) 814 808 { 815 809 struct gpio_device *gdev; 810 + unsigned long flags; 816 811 unsigned int i; 817 812 int base = 0; 818 813 int ret = 0; ··· 878 871 879 872 gdev->ngpio = gc->ngpio; 880 873 881 - scoped_guard(rwsem_write, &gpio_devices_sem) { 882 - /* 883 - * TODO: this allocates a Linux GPIO number base in the global 884 - * GPIO numberspace for this chip. In the long run we want to 885 - * get *rid* of this numberspace and use only descriptors, but 886 - * it may be a pipe dream. It will not happen before we get rid 887 - * of the sysfs interface anyways. 888 - */ 889 - base = gc->base; 874 + spin_lock_irqsave(&gpio_lock, flags); 890 875 876 + /* 877 + * TODO: this allocates a Linux GPIO number base in the global 878 + * GPIO numberspace for this chip. In the long run we want to 879 + * get *rid* of this numberspace and use only descriptors, but 880 + * it may be a pipe dream. It will not happen before we get rid 881 + * of the sysfs interface anyways. 882 + */ 883 + base = gc->base; 884 + if (base < 0) { 885 + base = gpiochip_find_base_unlocked(gc->ngpio); 891 886 if (base < 0) { 892 - base = gpiochip_find_base_unlocked(gc->ngpio); 893 - if (base < 0) { 894 - ret = base; 895 - base = 0; 896 - goto err_free_label; 897 - } 898 - /* 899 - * TODO: it should not be necessary to reflect the assigned 900 - * base outside of the GPIO subsystem. Go over drivers and 901 - * see if anyone makes use of this, else drop this and assign 902 - * a poison instead. 903 - */ 904 - gc->base = base; 905 - } else { 906 - dev_warn(&gdev->dev, 907 - "Static allocation of GPIO base is deprecated, use dynamic allocation.\n"); 908 - } 909 - gdev->base = base; 910 - 911 - ret = gpiodev_add_to_list_unlocked(gdev); 912 - if (ret) { 913 - chip_err(gc, "GPIO integer space overlap, cannot add chip\n"); 887 + spin_unlock_irqrestore(&gpio_lock, flags); 888 + ret = base; 889 + base = 0; 914 890 goto err_free_label; 915 891 } 916 - 917 - for (i = 0; i < gc->ngpio; i++) 918 - gdev->descs[i].gdev = gdev; 892 + /* 893 + * TODO: it should not be necessary to reflect the assigned 894 + * base outside of the GPIO subsystem. Go over drivers and 895 + * see if anyone makes use of this, else drop this and assign 896 + * a poison instead. 897 + */ 898 + gc->base = base; 899 + } else { 900 + dev_warn(&gdev->dev, 901 + "Static allocation of GPIO base is deprecated, use dynamic allocation.\n"); 919 902 } 903 + gdev->base = base; 904 + 905 + ret = gpiodev_add_to_list_unlocked(gdev); 906 + if (ret) { 907 + spin_unlock_irqrestore(&gpio_lock, flags); 908 + chip_err(gc, "GPIO integer space overlap, cannot add chip\n"); 909 + goto err_free_label; 910 + } 911 + 912 + for (i = 0; i < gc->ngpio; i++) 913 + gdev->descs[i].gdev = gdev; 914 + 915 + spin_unlock_irqrestore(&gpio_lock, flags); 920 916 921 917 BLOCKING_INIT_NOTIFIER_HEAD(&gdev->line_state_notifier); 922 918 BLOCKING_INIT_NOTIFIER_HEAD(&gdev->device_notifier); ··· 1011 1001 goto err_print_message; 1012 1002 } 1013 1003 err_remove_from_list: 1014 - scoped_guard(rwsem_write, &gpio_devices_sem) 1015 - list_del(&gdev->list); 1004 + spin_lock_irqsave(&gpio_lock, flags); 1005 + list_del(&gdev->list); 1006 + spin_unlock_irqrestore(&gpio_lock, flags); 1016 1007 err_free_label: 1017 1008 kfree_const(gdev->label); 1018 1009 err_free_descs: ··· 1076 1065 dev_crit(&gdev->dev, 1077 1066 "REMOVING GPIOCHIP WITH GPIOS STILL REQUESTED\n"); 1078 1067 1079 - scoped_guard(rwsem_write, &gpio_devices_sem) 1068 + scoped_guard(spinlock_irqsave, &gpio_lock) 1080 1069 list_del(&gdev->list); 1081 1070 1082 1071 /* ··· 1125 1114 */ 1126 1115 might_sleep(); 1127 1116 1128 - guard(rwsem_read)(&gpio_devices_sem); 1117 + guard(spinlock_irqsave)(&gpio_lock); 1129 1118 1130 1119 list_for_each_entry(gdev, &gpio_devices, list) { 1131 1120 if (gdev->chip && match(gdev->chip, data)) ··· 4736 4725 4737 4726 static void *gpiolib_seq_start(struct seq_file *s, loff_t *pos) 4738 4727 { 4728 + unsigned long flags; 4739 4729 struct gpio_device *gdev = NULL; 4740 4730 loff_t index = *pos; 4741 4731 4742 4732 s->private = ""; 4743 4733 4744 - guard(rwsem_read)(&gpio_devices_sem); 4745 - 4746 - list_for_each_entry(gdev, &gpio_devices, list) { 4747 - if (index-- == 0) 4734 + spin_lock_irqsave(&gpio_lock, flags); 4735 + list_for_each_entry(gdev, &gpio_devices, list) 4736 + if (index-- == 0) { 4737 + spin_unlock_irqrestore(&gpio_lock, flags); 4748 4738 return gdev; 4749 - } 4739 + } 4740 + spin_unlock_irqrestore(&gpio_lock, flags); 4750 4741 4751 4742 return NULL; 4752 4743 } 4753 4744 4754 4745 static void *gpiolib_seq_next(struct seq_file *s, void *v, loff_t *pos) 4755 4746 { 4747 + unsigned long flags; 4756 4748 struct gpio_device *gdev = v; 4757 4749 void *ret = NULL; 4758 4750 4759 - scoped_guard(rwsem_read, &gpio_devices_sem) { 4760 - if (list_is_last(&gdev->list, &gpio_devices)) 4761 - ret = NULL; 4762 - else 4763 - ret = list_first_entry(&gdev->list, struct gpio_device, 4764 - list); 4765 - } 4751 + spin_lock_irqsave(&gpio_lock, flags); 4752 + if (list_is_last(&gdev->list, &gpio_devices)) 4753 + ret = NULL; 4754 + else 4755 + ret = list_first_entry(&gdev->list, struct gpio_device, list); 4756 + spin_unlock_irqrestore(&gpio_lock, flags); 4766 4757 4767 4758 s->private = "\n"; 4768 4759 ++*pos;
-2
drivers/gpio/gpiolib.h
··· 15 15 #include <linux/gpio/consumer.h> /* for enum gpiod_flags */ 16 16 #include <linux/gpio/driver.h> 17 17 #include <linux/module.h> 18 - #include <linux/mutex.h> 19 18 #include <linux/notifier.h> 20 19 #include <linux/rwsem.h> 21 20 ··· 136 137 137 138 extern spinlock_t gpio_lock; 138 139 extern struct list_head gpio_devices; 139 - extern struct rw_semaphore gpio_devices_sem; 140 140 141 141 void gpiod_line_state_notify(struct gpio_desc *desc, unsigned long action); 142 142
+1 -1
include/linux/gpio/driver.h
··· 635 635 void gpio_device_put(struct gpio_device *gdev); 636 636 637 637 DEFINE_FREE(gpio_device_put, struct gpio_device *, 638 - if (IS_ERR_OR_NULL(_T)) gpio_device_put(_T)); 638 + if (!IS_ERR_OR_NULL(_T)) gpio_device_put(_T)) 639 639 640 640 struct device *gpio_device_to_device(struct gpio_device *gdev); 641 641