diff options
Diffstat (limited to 'drivers/gpio/gpiolib.c')
| -rw-r--r-- | drivers/gpio/gpiolib.c | 36 | 
1 files changed, 18 insertions, 18 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index fa62367ee929..edaeee53db75 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1,6 +1,7 @@  // SPDX-License-Identifier: GPL-2.0  #include <linux/acpi.h> +#include <linux/array_size.h>  #include <linux/bitmap.h>  #include <linux/cleanup.h>  #include <linux/compat.h> @@ -17,6 +18,7 @@  #include <linux/list.h>  #include <linux/lockdep.h>  #include <linux/module.h> +#include <linux/nospec.h>  #include <linux/of.h>  #include <linux/pinctrl/consumer.h>  #include <linux/seq_file.h> @@ -88,6 +90,9 @@ DEFINE_STATIC_SRCU(gpio_devices_srcu);  static DEFINE_MUTEX(gpio_machine_hogs_mutex);  static LIST_HEAD(gpio_machine_hogs); +const char *const gpio_suffixes[] = { "gpios", "gpio" }; +const size_t gpio_suffix_count = ARRAY_SIZE(gpio_suffixes); +  static void gpiochip_free_hogs(struct gpio_chip *gc);  static int gpiochip_add_irqchip(struct gpio_chip *gc,  				struct lock_class_key *lock_key, @@ -105,16 +110,16 @@ const char *gpiod_get_label(struct gpio_desc *desc)  	unsigned long flags;  	flags = READ_ONCE(desc->flags); -	if (test_bit(FLAG_USED_AS_IRQ, &flags) && -	    !test_bit(FLAG_REQUESTED, &flags)) -		return "interrupt"; - -	if (!test_bit(FLAG_REQUESTED, &flags)) -		return NULL;  	label = srcu_dereference_check(desc->label, &desc->gdev->desc_srcu,  				srcu_read_lock_held(&desc->gdev->desc_srcu)); +	if (test_bit(FLAG_USED_AS_IRQ, &flags)) +		return label->str ?: "interrupt"; + +	if (!test_bit(FLAG_REQUESTED, &flags)) +		return NULL; +  	return label->str;  } @@ -174,7 +179,6 @@ struct gpio_desc *gpiochip_get_desc(struct gpio_chip *gc,  {  	return gpio_device_get_desc(gc->gpiodev, hwnum);  } -EXPORT_SYMBOL_GPL(gpiochip_get_desc);  /**   * gpio_device_get_desc() - get the GPIO descriptor corresponding to the given @@ -198,7 +202,7 @@ gpio_device_get_desc(struct gpio_device *gdev, unsigned int hwnum)  	if (hwnum >= gdev->ngpio)  		return ERR_PTR(-EINVAL); -	return &gdev->descs[hwnum]; +	return &gdev->descs[array_index_nospec(hwnum, gdev->ngpio)];  }  EXPORT_SYMBOL_GPL(gpio_device_get_desc); @@ -485,7 +489,7 @@ static struct gpio_desc *gpio_name_to_desc(const char * const name)   *   1. Non-unique names are still accepted,   *   2. Name collisions within the same GPIO chip are not reported.   */ -static int gpiochip_set_desc_names(struct gpio_chip *gc) +static void gpiochip_set_desc_names(struct gpio_chip *gc)  {  	struct gpio_device *gdev = gc->gpiodev;  	int i; @@ -504,8 +508,6 @@ static int gpiochip_set_desc_names(struct gpio_chip *gc)  	/* Then add all names to the GPIO descriptors */  	for (i = 0; i != gc->ngpio; ++i)  		gdev->descs[i].name = gc->names[i]; - -	return 0;  }  /* @@ -999,11 +1001,9 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,  	INIT_LIST_HEAD(&gdev->pin_ranges);  #endif -	if (gc->names) { -		ret = gpiochip_set_desc_names(gc); -		if (ret) -			goto err_cleanup_desc_srcu; -	} +	if (gc->names) +		gpiochip_set_desc_names(gc); +  	ret = gpiochip_set_names(gc);  	if (ret)  		goto err_cleanup_desc_srcu; @@ -4798,11 +4798,11 @@ static void gpiolib_dbg_show(struct seq_file *s, struct gpio_device *gdev)  	for_each_gpio_desc(gc, desc) {  		guard(srcu)(&desc->gdev->desc_srcu); -		if (test_bit(FLAG_REQUESTED, &desc->flags)) { +		is_irq = test_bit(FLAG_USED_AS_IRQ, &desc->flags); +		if (is_irq || test_bit(FLAG_REQUESTED, &desc->flags)) {  			gpiod_get_direction(desc);  			is_out = test_bit(FLAG_IS_OUT, &desc->flags);  			value = gpio_chip_get_value(gc, desc); -			is_irq = test_bit(FLAG_USED_AS_IRQ, &desc->flags);  			active_low = test_bit(FLAG_ACTIVE_LOW, &desc->flags);  			seq_printf(s, " gpio-%-3u (%-20.20s|%-20.20s) %s %s %s%s\n",  				   gpio, desc->name ?: "", gpiod_get_label(desc),  |