Skip to content

Commit 36ddc9e

Browse files
committed
gpio: don't compare raw GPIO descriptor pointers
Merge series from Bartosz Golaszewski <[email protected]>: Handling of shared GPIOs in the kernel needs some improvements. Let's start with a simple change of not comparing GPIO descriptor pointers directly as there's nothing that guarantees that the same physical pin will always be represented by a single GPIO descriptor obtained by calling gpiod_get().
2 parents 4a7c28e + aaf6223 commit 36ddc9e

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

drivers/gpio/gpiolib.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,20 @@ struct gpio_device *gpiod_to_gpio_device(struct gpio_desc *desc)
265265
}
266266
EXPORT_SYMBOL_GPL(gpiod_to_gpio_device);
267267

268+
/**
269+
* gpiod_is_equal() - Check if two GPIO descriptors refer to the same pin.
270+
* @desc: Descriptor to compare.
271+
* @other: The second descriptor to compare against.
272+
*
273+
* Returns:
274+
* True if the descriptors refer to the same physical pin. False otherwise.
275+
*/
276+
bool gpiod_is_equal(struct gpio_desc *desc, struct gpio_desc *other)
277+
{
278+
return desc == other;
279+
}
280+
EXPORT_SYMBOL_GPL(gpiod_is_equal);
281+
268282
/**
269283
* gpio_device_get_base() - Get the base GPIO number allocated by this device
270284
* @gdev: GPIO device

drivers/regulator/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2617,7 +2617,7 @@ static int regulator_ena_gpio_request(struct regulator_dev *rdev,
26172617
mutex_lock(&regulator_list_mutex);
26182618

26192619
list_for_each_entry(pin, &regulator_ena_gpio_list, list) {
2620-
if (pin->gpiod == gpiod) {
2620+
if (gpiod_is_equal(pin->gpiod, gpiod)) {
26212621
rdev_dbg(rdev, "GPIO is already used\n");
26222622
goto update_ena_gpio_to_rdev;
26232623
}

include/linux/gpio/consumer.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ struct gpio_desc *devm_fwnode_gpiod_get_index(struct device *dev,
180180
enum gpiod_flags flags,
181181
const char *label);
182182

183+
bool gpiod_is_equal(struct gpio_desc *desc, struct gpio_desc *other);
184+
183185
#else /* CONFIG_GPIOLIB */
184186

185187
#include <linux/bug.h>
@@ -547,6 +549,13 @@ struct gpio_desc *devm_fwnode_gpiod_get_index(struct device *dev,
547549
return ERR_PTR(-ENOSYS);
548550
}
549551

552+
static inline bool
553+
gpiod_is_equal(struct gpio_desc *desc, struct gpio_desc *other)
554+
{
555+
WARN_ON(desc || other);
556+
return false;
557+
}
558+
550559
#endif /* CONFIG_GPIOLIB */
551560

552561
#if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_HTE)

0 commit comments

Comments
 (0)