Skip to contentSkip to conversation

gpiolib: Use list_first_entry()/list_last_entry()

PATCH Applied Andy Shevchenko 2 participants 2 messages Mar 7, 2022 – Mar 8, 2022 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpiolib: Use list_first_entry()/list_last_entry()

Use list_first_entry()/list_last_entry() instead of open coded variants.

---
 drivers/gpio/gpiolib.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpio/gpiolib.c +3 -3
index 002bf4b1616b..f5e7443208d4 100644
@@ -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);
@@ -4426,7 +4426,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";
Signature · 1 line
2.34.1
#1 lore raw
Quoted 39 lines · Andy Shevchenko

Use list_first_entry()/list_last_entry() instead of open coded variants.

---
 drivers/gpio/gpiolib.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpio/gpiolib.c +3 -4
index 002bf4b1616b..f5e7443208d4 100644
@@ -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);
@@ -4426,7 +4426,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";
--
Quoted 2 lines

2.34.1

Applied, thanks!

Bart