staging: vchiq: replace usage of found with dedicated list iterator variable
authorJakob Koschel <jakobkoschel@gmail.com>
Thu, 24 Mar 2022 07:30:24 +0000 (08:30 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 4 Apr 2022 05:33:46 +0000 (07:33 +0200)
To move the list iterator variable into the list_for_each_entry_*()
macro in the future it should be avoided to use the list iterator
variable after the loop body.

To *never* use the list iterator variable after the loop it was
concluded to use a separate iterator variable instead of a
found boolean [1].

This removes the need to use a found variable and simply checking if
the variable was set, can determine if the break/goto was hit.

Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/
Signed-off-by: Jakob Koschel <jakobkoschel@gmail.com>
Link: https://lore.kernel.org/r/20220324073024.65943-1-jakobkoschel@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c

index f0bfacf..313a4e9 100644 (file)
@@ -918,8 +918,7 @@ vchiq_blocking_bulk_transfer(unsigned int handle, void *data, unsigned int size,
        struct vchiq_instance *instance;
        struct vchiq_service *service;
        enum vchiq_status status;
-       struct bulk_waiter_node *waiter = NULL;
-       bool found = false;
+       struct bulk_waiter_node *waiter = NULL, *iter;
 
        service = find_service_by_handle(handle);
        if (!service)
@@ -930,16 +929,16 @@ vchiq_blocking_bulk_transfer(unsigned int handle, void *data, unsigned int size,
        vchiq_service_put(service);
 
        mutex_lock(&instance->bulk_waiter_list_mutex);
-       list_for_each_entry(waiter, &instance->bulk_waiter_list, list) {
-               if (waiter->pid == current->pid) {
-                       list_del(&waiter->list);
-                       found = true;
+       list_for_each_entry(iter, &instance->bulk_waiter_list, list) {
+               if (iter->pid == current->pid) {
+                       list_del(&iter->list);
+                       waiter = iter;
                        break;
                }
        }
        mutex_unlock(&instance->bulk_waiter_list_mutex);
 
-       if (found) {
+       if (waiter) {
                struct vchiq_bulk *bulk = waiter->bulk_waiter.bulk;
 
                if (bulk) {
index b41c2a2..66bbfec 100644 (file)
@@ -289,8 +289,7 @@ static int vchiq_irq_queue_bulk_tx_rx(struct vchiq_instance *instance,
                                      enum vchiq_bulk_mode __user *mode)
 {
        struct vchiq_service *service;
-       struct bulk_waiter_node *waiter = NULL;
-       bool found = false;
+       struct bulk_waiter_node *waiter = NULL, *iter;
        void *userdata;
        int status = 0;
        int ret;
@@ -309,16 +308,16 @@ static int vchiq_irq_queue_bulk_tx_rx(struct vchiq_instance *instance,
                userdata = &waiter->bulk_waiter;
        } else if (args->mode == VCHIQ_BULK_MODE_WAITING) {
                mutex_lock(&instance->bulk_waiter_list_mutex);
-               list_for_each_entry(waiter, &instance->bulk_waiter_list,
+               list_for_each_entry(iter, &instance->bulk_waiter_list,
                                    list) {
-                       if (waiter->pid == current->pid) {
-                               list_del(&waiter->list);
-                               found = true;
+                       if (iter->pid == current->pid) {
+                               list_del(&iter->list);
+                               waiter = iter;
                                break;
                        }
                }
                mutex_unlock(&instance->bulk_waiter_list_mutex);
-               if (!found) {
+               if (!waiter) {
                        vchiq_log_error(vchiq_arm_log_level,
                                        "no bulk_waiter found for pid %d", current->pid);
                        ret = -ESRCH;