gpiolib: provide gpio_device_get_label()
authorBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Wed, 15 Nov 2023 16:49:59 +0000 (17:49 +0100)
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Fri, 24 Nov 2023 19:27:37 +0000 (20:27 +0100)
Provide a getter for the GPIO device label string so that users don't
have to dereference struct gpio_chip directly.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
drivers/gpio/gpiolib.c
include/linux/gpio/driver.h

index 95d2a7b2ea3e21239ea04c1875c2870ccedb213a..a5faaea6915d47ed058afcc88b51bd3e5fae8318 100644 (file)
@@ -254,6 +254,20 @@ int gpio_device_get_base(struct gpio_device *gdev)
 }
 EXPORT_SYMBOL_GPL(gpio_device_get_base);
 
+/**
+ * gpio_device_get_label() - Get the label of this GPIO device
+ * @gdev: GPIO device
+ *
+ * Returns:
+ * Pointer to the string containing the GPIO device label. The string's
+ * lifetime is tied to that of the underlying GPIO device.
+ */
+const char *gpio_device_get_label(struct gpio_device *gdev)
+{
+       return gdev->label;
+}
+EXPORT_SYMBOL(gpio_device_get_label);
+
 /**
  * gpio_device_get_chip() - Get the gpio_chip implementation of this GPIO device
  * @gdev: GPIO device
index 0aed62f0c63309d8b4962275c8a9b32f1cd9f659..100c329dc986cee43fa55e4d83c0349cd0639d32 100644 (file)
@@ -786,6 +786,7 @@ struct gpio_device *gpiod_to_gpio_device(struct gpio_desc *desc);
 
 /* struct gpio_device getters */
 int gpio_device_get_base(struct gpio_device *gdev);
+const char *gpio_device_get_label(struct gpio_device *gdev);
 
 #else /* CONFIG_GPIOLIB */