Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp693320pxb; Tue, 5 Apr 2022 19:03:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzPWXKnVJdIp8r88EJb9Um8BMKXxXVA8fXX7X9KKCgQJ1dPCFW5kcb7p3dTxrSAeEcThTF7 X-Received: by 2002:a63:f10c:0:b0:382:623b:3bb9 with SMTP id f12-20020a63f10c000000b00382623b3bb9mr5179456pgi.97.1649210589633; Tue, 05 Apr 2022 19:03:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649210589; cv=none; d=google.com; s=arc-20160816; b=mO6JV+l3yBa/eFqUm/f08DC6679oEcO16NwrZTWYOAkFwUV2887Iq5rYmSoP4X7M1y tCtcx0einoELCSy7lcWSHBOpr97ZlJN/BzqPXqm4sP7xam5ETVt3ppBAmE88PId8vopP 5r1FlLY13EhHtY2BZ4BB/IdmlZx7ozjDlTbevlH5gLVCBcnLKEjN/BhE/w/OXlNj4mRf j+2Og4MaTmrdK98F6dHqCkAw7z58yRyUTJv6sGKxSVnQDfQApRzLYTl6rPa7nvvUJ99l 4Vu4s5+bRV5t4Tw60adTBbEJJW/TzuCSIwGXB4pzTSuxqT+DqtZRNidcPkavEb0CFPhF 9VMQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6UdjhNqAODGdtL7AG1x1UwR6Md72DgPVUrP6bC9//Z4=; b=lVFhLiEfaVynvu4XM4I+BeqdYGYPSU2DQE9sL2P11beD9Vd8xzebPVUFjJaZNfCmpG +U3peQGf6Bn8ny9d534pP4imFMBruJpAqLrOmWuLRmRA8o3AjagOd/4mjK8uWyDCV5R2 Wt6Jz9vbmtN4zeCai2Fb1rNOq/arZ7qcdWwx5VXLpa0D09M/17KsDdHrVhDUmDycgSM9 3QurqgxQUFz7Q4jUYV3Esfsqaxbeh896/OOKcuUHLEHdnEF0GL9WBRQSwi13IesqwkrB xv1LOFzP8PZh+Guat76PcmzaMkLzzBNphjkMWvsDWl0IIviYSrWkxu4Qq9GyrWOSas3e 3Wiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=RuDP2zcU; 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=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f8-20020a656288000000b003816043ef06si14543760pgv.251.2022.04.05.19.02.52; Tue, 05 Apr 2022 19:03:09 -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=@linuxfoundation.org header.s=korg header.b=RuDP2zcU; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343727AbiDEK7g (ORCPT + 99 others); Tue, 5 Apr 2022 06:59:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242291AbiDEIhS (ORCPT ); Tue, 5 Apr 2022 04:37:18 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EDB151CB13; Tue, 5 Apr 2022 01:32:39 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8CF7960B0E; Tue, 5 Apr 2022 08:32:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 97857C385A0; Tue, 5 Apr 2022 08:32:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649147559; bh=u8cclAT3USm2ckXvRzJKzZhIhuNCejG+lU+PnBp3YA8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RuDP2zcUy3V4AmS2EW2CcDXknhjYO0iCcyUw9rP+ucBMZMZZV0z3trIF3ZD4q7cWX TKGdVbnB7R5Zv7lyqI6ajG/nYGGDarYKBR5yzi301jLZD15G5CllpVLd1v4iXGkBNd g9qYzDqJHyAXGUzZfNc3GSlooEq0tfYt1xQcTCVA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexander Usyskin , Tomas Winkler Subject: [PATCH 5.16 0040/1017] mei: avoid iterator usage outside of list_for_each_entry Date: Tue, 5 Apr 2022 09:15:53 +0200 Message-Id: <20220405070355.369810367@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 From: Alexander Usyskin commit c10187b1c5ebb8681ca467ab7b0ded5ea415d258 upstream. Usage of the iterator outside of the list_for_each_entry is considered harmful. https://lkml.org/lkml/2022/2/17/1032 Do not reference the loop variable outside of the loop, by rearranging the orders of execution. Instead of performing search loop and checking outside the loop if the end of the list was hit and no matching element was found, the execution is performed inside the loop upon a successful match followed by a goto statement to the next step, therefore no condition has to be performed after the loop has ended. Cc: Signed-off-by: Alexander Usyskin Signed-off-by: Tomas Winkler Link: https://lore.kernel.org/r/20220308095926.300412-1-tomas.winkler@intel.com Signed-off-by: Greg Kroah-Hartman --- drivers/misc/mei/interrupt.c | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) --- a/drivers/misc/mei/interrupt.c +++ b/drivers/misc/mei/interrupt.c @@ -424,31 +424,26 @@ int mei_irq_read_handler(struct mei_devi list_for_each_entry(cl, &dev->file_list, link) { if (mei_cl_hbm_equal(cl, mei_hdr)) { cl_dbg(dev, cl, "got a message\n"); - break; + ret = mei_cl_irq_read_msg(cl, mei_hdr, meta_hdr, cmpl_list); + goto reset_slots; } } /* if no recipient cl was found we assume corrupted header */ - if (&cl->link == &dev->file_list) { - /* A message for not connected fixed address clients - * should be silently discarded - * On power down client may be force cleaned, - * silently discard such messages - */ - if (hdr_is_fixed(mei_hdr) || - dev->dev_state == MEI_DEV_POWER_DOWN) { - mei_irq_discard_msg(dev, mei_hdr, mei_hdr->length); - ret = 0; - goto reset_slots; - } - dev_err(dev->dev, "no destination client found 0x%08X\n", - dev->rd_msg_hdr[0]); - ret = -EBADMSG; - goto end; + /* A message for not connected fixed address clients + * should be silently discarded + * On power down client may be force cleaned, + * silently discard such messages + */ + if (hdr_is_fixed(mei_hdr) || + dev->dev_state == MEI_DEV_POWER_DOWN) { + mei_irq_discard_msg(dev, mei_hdr, mei_hdr->length); + ret = 0; + goto reset_slots; } - - ret = mei_cl_irq_read_msg(cl, mei_hdr, meta_hdr, cmpl_list); - + dev_err(dev->dev, "no destination client found 0x%08X\n", dev->rd_msg_hdr[0]); + ret = -EBADMSG; + goto end; reset_slots: /* reset the number of slots and header */