parport: Use list_for_each() helper
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Mon, 16 Oct 2023 13:31:34 +0000 (16:31 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 18 Oct 2023 08:02:52 +0000 (10:02 +0200)
Convert hard to read custom code to list_for_each().
No functional changes intended.

Note, we may not use list_for_each_entry() as at the end of the list
the iterator will point to an invalid entry and may not be dereferenced.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20231016133135.1203643-3-andriy.shevchenko@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/parport/share.c

index 8037bcd07bcf94956b7cf55fd553911f7336c064..38780f6a91194689895bce3602671179e31f14c6 100644 (file)
@@ -469,9 +469,11 @@ struct parport *parport_register_port(unsigned long base, int irq, int dma,
        /* Search for the lowest free parport number. */
 
        spin_lock(&full_list_lock);
-       for (l = all_ports.next, num = 0; l != &all_ports; l = l->next, num++) {
+       num = 0;
+       list_for_each(l, &all_ports) {
                struct parport *p = list_entry(l, struct parport, full_list);
-               if (p->number != num)
+
+               if (p->number != num++)
                        break;
        }
        tmp->portnum = tmp->number = num;