aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio/gpiolib.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpio/gpiolib.c')
-rw-r--r--drivers/gpio/gpiolib.c41
1 files changed, 19 insertions, 22 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 6630d92e30ad..e59884cc12a7 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -262,14 +262,14 @@ static int gpiodev_add_to_list(struct gpio_device *gdev)
return 0;
}
- next = list_entry(gpio_devices.next, struct gpio_device, list);
+ next = list_first_entry(&gpio_devices, struct gpio_device, list);
if (gdev->base + gdev->ngpio <= next->base) {
/* add before first entry */
list_add(&gdev->list, &gpio_devices);
return 0;
}
- prev = list_entry(gpio_devices.prev, struct gpio_device, list);
+ prev = list_last_entry(&gpio_devices, struct gpio_device, list);
if (prev->base + prev->ngpio <= gdev->base) {
/* add behind last entry */
list_add_tail(&gdev->list, &gpio_devices);
@@ -3951,23 +3951,21 @@ struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
* If a connection label was passed use that, else attempt to use
* the device name as label
*/
- ret = gpiod_request(desc, con_id ? con_id : devname);
+ ret = gpiod_request(desc, con_id ?: devname);
if (ret) {
- if (ret == -EBUSY && flags & GPIOD_FLAGS_BIT_NONEXCLUSIVE) {
- /*
- * This happens when there are several consumers for
- * the same GPIO line: we just return here without
- * further initialization. It is a bit if a hack.
- * This is necessary to support fixed regulators.
- *
- * FIXME: Make this more sane and safe.
- */
- dev_info(dev, "nonexclusive access to GPIO for %s\n",
- con_id ? con_id : devname);
- return desc;
- } else {
+ if (!(ret == -EBUSY && flags & GPIOD_FLAGS_BIT_NONEXCLUSIVE))
return ERR_PTR(ret);
- }
+
+ /*
+ * This happens when there are several consumers for
+ * the same GPIO line: we just return here without
+ * further initialization. It is a bit of a hack.
+ * This is necessary to support fixed regulators.
+ *
+ * FIXME: Make this more sane and safe.
+ */
+ dev_info(dev, "nonexclusive access to GPIO for %s\n", con_id ?: devname);
+ return desc;
}
ret = gpiod_configure_flags(desc, con_id, lookupflags, flags);
@@ -4122,12 +4120,11 @@ int gpiod_hog(struct gpio_desc *desc, const char *name,
*/
static void gpiochip_free_hogs(struct gpio_chip *gc)
{
+ struct gpio_desc *desc;
int id;
- for (id = 0; id < gc->ngpio; id++) {
- if (test_bit(FLAG_IS_HOGGED, &gc->gpiodev->descs[id].flags))
- gpiochip_free_own_desc(&gc->gpiodev->descs[id]);
- }
+ for_each_gpio_desc_with_flag(id, gc, desc, FLAG_IS_HOGGED)
+ gpiochip_free_own_desc(desc);
}
/**
@@ -4446,7 +4443,7 @@ static void *gpiolib_seq_next(struct seq_file *s, void *v, loff_t *pos)
if (list_is_last(&gdev->list, &gpio_devices))
ret = NULL;
else
- ret = list_entry(gdev->list.next, struct gpio_device, list);
+ ret = list_first_entry(&gdev->list, struct gpio_device, list);
spin_unlock_irqrestore(&gpio_lock, flags);
s->private = "\n";