misc: bcm-vk: replace usage of found with dedicated list iterator variable
authorJakob Koschel <jakobkoschel@gmail.com>
Sun, 27 Mar 2022 21:45:51 +0000 (23:45 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 24 Apr 2022 15:30:27 +0000 (17:30 +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/20220327214551.2188544-1-jakobkoschel@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/misc/bcm-vk/bcm_vk_msg.c

index 066b9ef..3c08150 100644 (file)
@@ -757,20 +757,19 @@ static struct bcm_vk_wkent *bcm_vk_dequeue_pending(struct bcm_vk *vk,
                                                   u16 q_num,
                                                   u16 msg_id)
 {
-       bool found = false;
-       struct bcm_vk_wkent *entry;
+       struct bcm_vk_wkent *entry = NULL, *iter;
 
        spin_lock(&chan->pendq_lock);
-       list_for_each_entry(entry, &chan->pendq[q_num], node) {
-               if (get_msg_id(&entry->to_v_msg[0]) == msg_id) {
-                       list_del(&entry->node);
-                       found = true;
+       list_for_each_entry(iter, &chan->pendq[q_num], node) {
+               if (get_msg_id(&iter->to_v_msg[0]) == msg_id) {
+                       list_del(&iter->node);
+                       entry = iter;
                        bcm_vk_msgid_bitmap_clear(vk, msg_id, 1);
                        break;
                }
        }
        spin_unlock(&chan->pendq_lock);
-       return ((found) ? entry : NULL);
+       return entry;
 }
 
 s32 bcm_to_h_msg_dequeue(struct bcm_vk *vk)
@@ -1010,16 +1009,14 @@ ssize_t bcm_vk_read(struct file *p_file,
                                         miscdev);
        struct device *dev = &vk->pdev->dev;
        struct bcm_vk_msg_chan *chan = &vk->to_h_msg_chan;
-       struct bcm_vk_wkent *entry = NULL;
+       struct bcm_vk_wkent *entry = NULL, *iter;
        u32 q_num;
        u32 rsp_length;
-       bool found = false;
 
        if (!bcm_vk_drv_access_ok(vk))
                return -EPERM;
 
        dev_dbg(dev, "Buf count %zu\n", count);
-       found = false;
 
        /*
         * search through the pendq on the to_h chan, and return only those
@@ -1028,13 +1025,13 @@ ssize_t bcm_vk_read(struct file *p_file,
         */
        spin_lock(&chan->pendq_lock);
        for (q_num = 0; q_num < chan->q_nr; q_num++) {
-               list_for_each_entry(entry, &chan->pendq[q_num], node) {
-                       if (entry->ctx->idx == ctx->idx) {
+               list_for_each_entry(iter, &chan->pendq[q_num], node) {
+                       if (iter->ctx->idx == ctx->idx) {
                                if (count >=
-                                   (entry->to_h_blks * VK_MSGQ_BLK_SIZE)) {
-                                       list_del(&entry->node);
+                                   (iter->to_h_blks * VK_MSGQ_BLK_SIZE)) {
+                                       list_del(&iter->node);
                                        atomic_dec(&ctx->pend_cnt);
-                                       found = true;
+                                       entry = iter;
                                } else {
                                        /* buffer not big enough */
                                        rc = -EMSGSIZE;
@@ -1046,7 +1043,7 @@ ssize_t bcm_vk_read(struct file *p_file,
 read_loop_exit:
        spin_unlock(&chan->pendq_lock);
 
-       if (found) {
+       if (entry) {
                /* retrieve the passed down msg_id */
                set_msg_id(&entry->to_h_msg[0], entry->usr_msg_id);
                rsp_length = entry->to_h_blks * VK_MSGQ_BLK_SIZE;