Commit 88517757 authored by Jakob Koschel's avatar Jakob Koschel Committed by Greg Kroah-Hartman

misc: bcm-vk: replace usage of found with dedicated list iterator variable

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: default avatarJakob Koschel <jakobkoschel@gmail.com>
Link: https://lore.kernel.org/r/20220327214551.2188544-1-jakobkoschel@gmail.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent f76a9ae6
...@@ -757,20 +757,19 @@ static struct bcm_vk_wkent *bcm_vk_dequeue_pending(struct bcm_vk *vk, ...@@ -757,20 +757,19 @@ static struct bcm_vk_wkent *bcm_vk_dequeue_pending(struct bcm_vk *vk,
u16 q_num, u16 q_num,
u16 msg_id) u16 msg_id)
{ {
bool found = false; struct bcm_vk_wkent *entry = NULL, *iter;
struct bcm_vk_wkent *entry;
spin_lock(&chan->pendq_lock); spin_lock(&chan->pendq_lock);
list_for_each_entry(entry, &chan->pendq[q_num], node) { list_for_each_entry(iter, &chan->pendq[q_num], node) {
if (get_msg_id(&entry->to_v_msg[0]) == msg_id) { if (get_msg_id(&iter->to_v_msg[0]) == msg_id) {
list_del(&entry->node); list_del(&iter->node);
found = true; entry = iter;
bcm_vk_msgid_bitmap_clear(vk, msg_id, 1); bcm_vk_msgid_bitmap_clear(vk, msg_id, 1);
break; break;
} }
} }
spin_unlock(&chan->pendq_lock); spin_unlock(&chan->pendq_lock);
return ((found) ? entry : NULL); return entry;
} }
s32 bcm_to_h_msg_dequeue(struct bcm_vk *vk) s32 bcm_to_h_msg_dequeue(struct bcm_vk *vk)
...@@ -1010,16 +1009,14 @@ ssize_t bcm_vk_read(struct file *p_file, ...@@ -1010,16 +1009,14 @@ ssize_t bcm_vk_read(struct file *p_file,
miscdev); miscdev);
struct device *dev = &vk->pdev->dev; struct device *dev = &vk->pdev->dev;
struct bcm_vk_msg_chan *chan = &vk->to_h_msg_chan; 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 q_num;
u32 rsp_length; u32 rsp_length;
bool found = false;
if (!bcm_vk_drv_access_ok(vk)) if (!bcm_vk_drv_access_ok(vk))
return -EPERM; return -EPERM;
dev_dbg(dev, "Buf count %zu\n", count); dev_dbg(dev, "Buf count %zu\n", count);
found = false;
/* /*
* search through the pendq on the to_h chan, and return only those * 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, ...@@ -1028,13 +1025,13 @@ ssize_t bcm_vk_read(struct file *p_file,
*/ */
spin_lock(&chan->pendq_lock); spin_lock(&chan->pendq_lock);
for (q_num = 0; q_num < chan->q_nr; q_num++) { for (q_num = 0; q_num < chan->q_nr; q_num++) {
list_for_each_entry(entry, &chan->pendq[q_num], node) { list_for_each_entry(iter, &chan->pendq[q_num], node) {
if (entry->ctx->idx == ctx->idx) { if (iter->ctx->idx == ctx->idx) {
if (count >= if (count >=
(entry->to_h_blks * VK_MSGQ_BLK_SIZE)) { (iter->to_h_blks * VK_MSGQ_BLK_SIZE)) {
list_del(&entry->node); list_del(&iter->node);
atomic_dec(&ctx->pend_cnt); atomic_dec(&ctx->pend_cnt);
found = true; entry = iter;
} else { } else {
/* buffer not big enough */ /* buffer not big enough */
rc = -EMSGSIZE; rc = -EMSGSIZE;
...@@ -1046,7 +1043,7 @@ ssize_t bcm_vk_read(struct file *p_file, ...@@ -1046,7 +1043,7 @@ ssize_t bcm_vk_read(struct file *p_file,
read_loop_exit: read_loop_exit:
spin_unlock(&chan->pendq_lock); spin_unlock(&chan->pendq_lock);
if (found) { if (entry) {
/* retrieve the passed down msg_id */ /* retrieve the passed down msg_id */
set_msg_id(&entry->to_h_msg[0], entry->usr_msg_id); set_msg_id(&entry->to_h_msg[0], entry->usr_msg_id);
rsp_length = entry->to_h_blks * VK_MSGQ_BLK_SIZE; rsp_length = entry->to_h_blks * VK_MSGQ_BLK_SIZE;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment