aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio/gpiolib.c
diff options
context:
space:
mode:
authorBartosz Golaszewski <[email protected]>2025-06-20 12:58:02 +0000
committerBartosz Golaszewski <[email protected]>2025-06-30 06:58:26 +0000
commit26981e8906bb5c902e2d34874f64ecfa975d28c8 (patch)
treefc743f73ee6e3393fc44c5882e8f175ab989a6bc /drivers/gpio/gpiolib.c
parentgpio: constify arguments of gpiod_is_equal() (diff)
downloadkernel-26981e8906bb5c902e2d34874f64ecfa975d28c8.tar.gz
kernel-26981e8906bb5c902e2d34874f64ecfa975d28c8.zip
gpio: make gpiod_is_equal() arguments stricter
It makes no sense for a GPIO descriptor comparator to return true when the arguments passed to it are NULL or IS_ERR(). Let's validate both and return false unless both are valid GPIO descriptors. Suggested-by: Andy Shevchenko <[email protected]> Link: https://lore.kernel.org/all/[email protected]/ Reviewed-by: Linus Walleij <[email protected]> Acked-by: Andy Shevchenko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Bartosz Golaszewski <[email protected]>
Diffstat (limited to 'drivers/gpio/gpiolib.c')
-rw-r--r--drivers/gpio/gpiolib.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 6b4f94c3887f..7b2174b10219 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -279,20 +279,6 @@ struct gpio_device *gpiod_to_gpio_device(struct gpio_desc *desc)
EXPORT_SYMBOL_GPL(gpiod_to_gpio_device);
/**
- * gpiod_is_equal() - Check if two GPIO descriptors refer to the same pin.
- * @desc: Descriptor to compare.
- * @other: The second descriptor to compare against.
- *
- * Returns:
- * True if the descriptors refer to the same physical pin. False otherwise.
- */
-bool gpiod_is_equal(const struct gpio_desc *desc, const struct gpio_desc *other)
-{
- return desc == other;
-}
-EXPORT_SYMBOL_GPL(gpiod_is_equal);
-
-/**
* gpio_device_get_base() - Get the base GPIO number allocated by this device
* @gdev: GPIO device
*
@@ -400,6 +386,21 @@ static int validate_desc(const struct gpio_desc *desc, const char *func)
return; \
} while (0)
+/**
+ * gpiod_is_equal() - Check if two GPIO descriptors refer to the same pin.
+ * @desc: Descriptor to compare.
+ * @other: The second descriptor to compare against.
+ *
+ * Returns:
+ * True if the descriptors refer to the same physical pin. False otherwise.
+ */
+bool gpiod_is_equal(const struct gpio_desc *desc, const struct gpio_desc *other)
+{
+ return validate_desc(desc, __func__) > 0 &&
+ !IS_ERR_OR_NULL(other) && desc == other;
+}
+EXPORT_SYMBOL_GPL(gpiod_is_equal);
+
static int gpiochip_get_direction(struct gpio_chip *gc, unsigned int offset)
{
int ret;