Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp4677274pxb; Mon, 28 Mar 2022 00:58:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy42deQ4Ox0sU5F2HZ+r+sXh8S1SUbOXOWcua2H52v4UL9ejssX6k+gw82R6wFq9JOHUUlH X-Received: by 2002:a17:907:9623:b0:6de:c0fb:8acc with SMTP id gb35-20020a170907962300b006dec0fb8accmr25525653ejc.380.1648454281585; Mon, 28 Mar 2022 00:58:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648454281; cv=none; d=google.com; s=arc-20160816; b=Zy7GF8GZLl8zFNgAwiipBPV8IbyqPZi8RM2f3pGOYvXzgHurWCNZDWBGYiSuaFVRRi rHCTnY6z/+hfs0zBXK9Oyf12wM8coqhuc45KN3jEAI812BN71chVVxWHtCdkhZ1ydH9Y 9W/Sys3ua/yqfOpxGVWzlbixiH7NhK8Xe+Mws7MB+TF0+GUpPe5ZPmbxAsnrVJhTjE1u 056muCjljKnn/n6Gpz1HKckximcn1sZb75f/NxmmqZ85kiUgyxosL3qqHXxCEvKboX1y /Epb1Wv3aoTs8criWVoApLvV0K8cZYT9C0PSNHqWr4PXLFWUe6dvic3EIrtT9EInypbN PliQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=20Qku66Un0STcQwrUDTvMrfzVHtMmdMF1TmmER8SnJY=; b=B3TylLjYbhmGWg+nZmFeuj7NJNGb9oDCVlp+e1T6Pa8cp4hTOzNKZKVTmlIvWI5oaS jF15tcsC+wQvI0pR3RB6v0Wgryq3HrE4QH2Msx4AEIaevP/OW8XdsCxGgBmuHwi+NCvJ ++gdasFYenREZLQNQgHRKodqQOXhP2E3Qdled+qTCo/qPXLBPf17zW13U4iD3VRJyDXB /ZLnflIC/rFUxO0ejZ7uD5p4qJ4PCSOl+FVe1/DkcfrKx64wmXtiM41tP2gyoUhd60l2 eF2Lm83+Rx/d+tGDVSIVHQ1U+rhsH2NRnD8IIMd2F/q9Yq7WrSD9t8Ov8ZRBE6rwojWQ cEig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="FoDAg4e/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a8-20020a17090680c800b006df76385e5csi12587789ejx.764.2022.03.28.00.57.36; Mon, 28 Mar 2022 00:58:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="FoDAg4e/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235765AbiC0Vs1 (ORCPT + 99 others); Sun, 27 Mar 2022 17:48:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230226AbiC0VsZ (ORCPT ); Sun, 27 Mar 2022 17:48:25 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87C2338784 for ; Sun, 27 Mar 2022 14:46:46 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id y10so14905487edv.7 for ; Sun, 27 Mar 2022 14:46:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=20Qku66Un0STcQwrUDTvMrfzVHtMmdMF1TmmER8SnJY=; b=FoDAg4e/PGIria8vzwCAxOEuxrwDQwIGCluc3GEnGj2GDpvVZ4ev3cIUA2TR95+O0U xj5eN+Xnb/+qfKAxicpgNenLbFQXgXLS52Hk9Xgh+NIJsRWOHi4MROOnNOaUbj3YVqhB 3TTELcQiZGEDGETLkESdWH7bRkCXGA3GFxQUkcuaEsZCWilDayZ5TGcM8k2bif8gbEwC YNVwYlehu/iOf341tPXfYRi9JvRxFAFjjFJjaTs+rX0uAi5Js7cNV0KrLr3InlKBMjvV 779l5tGkOGuHKgqHVpNfOZY7id6ZXaQnk+JSMB2LCCVEg3lw1HZkcNHkxm3emqW9Fs/v aGbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=20Qku66Un0STcQwrUDTvMrfzVHtMmdMF1TmmER8SnJY=; b=AviDNN3feQbyrCPDgGrSd4FQlcxg5Pj1yunhtUeJGwaUR1vjmvpQXk1jZiDo4pfZij T5oKC75ZNxPZB6jWoSNrZUcJ2SFnYbvmC4WS94xNbvZb2vPc9qsY/hNwQcHers80CJTZ CCvdbJTjBRe82l4uB/eDgqZl1FeHLXvFass5ewVZHRfCSQC/CcEOCQA+nY8yxSrL4nMH VG0r3imKhRMDHJdug2SN/TFuaRH+vFCVn8VbIHtS2nShIwByWUR8SPF/89w80c0UpNLC dVH59SWpOotUrPnDlh6JrazJVCePw34OuKwbjPyvTOETdXcJKkoeK9gBH+RCmg5+i83O HwNQ== X-Gm-Message-State: AOAM532WLzIYtA9A7i+p3toizaTql+R+snWSXOcfgm7eVClm2lS9aYah APtf5cQCJAIKAouhcLwIOfIN+E1x4Omefw== X-Received: by 2002:a50:9d49:0:b0:418:681b:f6d with SMTP id j9-20020a509d49000000b00418681b0f6dmr12358612edk.160.1648417605044; Sun, 27 Mar 2022 14:46:45 -0700 (PDT) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id js24-20020a170906ca9800b006c8aeca8fe8sm4990367ejb.58.2022.03.27.14.46.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Mar 2022 14:46:44 -0700 (PDT) From: Jakob Koschel To: Scott Branden Cc: Arnd Bergmann , Greg Kroah-Hartman , bcm-kernel-feedback-list@broadcom.com, linux-kernel@vger.kernel.org, Mike Rapoport , "Brian Johannesmeyer" , Cristiano Giuffrida , "Bos, H.J." , Jakob Koschel Subject: [PATCH] misc: bcm-vk: replace usage of found with dedicated list iterator variable Date: Sun, 27 Mar 2022 23:45:51 +0200 Message-Id: <20220327214551.2188544-1-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/misc/bcm-vk/bcm_vk_msg.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/drivers/misc/bcm-vk/bcm_vk_msg.c b/drivers/misc/bcm-vk/bcm_vk_msg.c index 066b9ef7fcd7..3c081504f38c 100644 --- a/drivers/misc/bcm-vk/bcm_vk_msg.c +++ b/drivers/misc/bcm-vk/bcm_vk_msg.c @@ -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; base-commit: b47d5a4f6b8d42f8a8fbe891b36215e4fddc53be -- 2.25.1