Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: 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>

authored by

Jakob Koschel and committed by
Greg Kroah-Hartman
88517757 f76a9ae6

+13 -16
+13 -16
drivers/misc/bcm-vk/bcm_vk_msg.c
··· 757 757 u16 q_num, 758 758 u16 msg_id) 759 759 { 760 - bool found = false; 761 - struct bcm_vk_wkent *entry; 760 + struct bcm_vk_wkent *entry = NULL, *iter; 762 761 763 762 spin_lock(&chan->pendq_lock); 764 - list_for_each_entry(entry, &chan->pendq[q_num], node) { 765 - if (get_msg_id(&entry->to_v_msg[0]) == msg_id) { 766 - list_del(&entry->node); 767 - found = true; 763 + list_for_each_entry(iter, &chan->pendq[q_num], node) { 764 + if (get_msg_id(&iter->to_v_msg[0]) == msg_id) { 765 + list_del(&iter->node); 766 + entry = iter; 768 767 bcm_vk_msgid_bitmap_clear(vk, msg_id, 1); 769 768 break; 770 769 } 771 770 } 772 771 spin_unlock(&chan->pendq_lock); 773 - return ((found) ? entry : NULL); 772 + return entry; 774 773 } 775 774 776 775 s32 bcm_to_h_msg_dequeue(struct bcm_vk *vk) ··· 1009 1010 miscdev); 1010 1011 struct device *dev = &vk->pdev->dev; 1011 1012 struct bcm_vk_msg_chan *chan = &vk->to_h_msg_chan; 1012 - struct bcm_vk_wkent *entry = NULL; 1013 + struct bcm_vk_wkent *entry = NULL, *iter; 1013 1014 u32 q_num; 1014 1015 u32 rsp_length; 1015 - bool found = false; 1016 1016 1017 1017 if (!bcm_vk_drv_access_ok(vk)) 1018 1018 return -EPERM; 1019 1019 1020 1020 dev_dbg(dev, "Buf count %zu\n", count); 1021 - found = false; 1022 1021 1023 1022 /* 1024 1023 * search through the pendq on the to_h chan, and return only those ··· 1025 1028 */ 1026 1029 spin_lock(&chan->pendq_lock); 1027 1030 for (q_num = 0; q_num < chan->q_nr; q_num++) { 1028 - list_for_each_entry(entry, &chan->pendq[q_num], node) { 1029 - if (entry->ctx->idx == ctx->idx) { 1031 + list_for_each_entry(iter, &chan->pendq[q_num], node) { 1032 + if (iter->ctx->idx == ctx->idx) { 1030 1033 if (count >= 1031 - (entry->to_h_blks * VK_MSGQ_BLK_SIZE)) { 1032 - list_del(&entry->node); 1034 + (iter->to_h_blks * VK_MSGQ_BLK_SIZE)) { 1035 + list_del(&iter->node); 1033 1036 atomic_dec(&ctx->pend_cnt); 1034 - found = true; 1037 + entry = iter; 1035 1038 } else { 1036 1039 /* buffer not big enough */ 1037 1040 rc = -EMSGSIZE; ··· 1043 1046 read_loop_exit: 1044 1047 spin_unlock(&chan->pendq_lock); 1045 1048 1046 - if (found) { 1049 + if (entry) { 1047 1050 /* retrieve the passed down msg_id */ 1048 1051 set_msg_id(&entry->to_h_msg[0], entry->usr_msg_id); 1049 1052 rsp_length = entry->to_h_blks * VK_MSGQ_BLK_SIZE;