Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1062869pxb; Fri, 1 Apr 2022 03:40:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyXXwUd4+CpR67y4Z5Fb2n23Y+QUn+mSfpSHXouDEtv1+VzdMx8e+wTAvmkbT1l3d6tmt/e X-Received: by 2002:a05:6402:8d7:b0:419:1162:a507 with SMTP id d23-20020a05640208d700b004191162a507mr20386093edz.157.1648809642689; Fri, 01 Apr 2022 03:40:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648809642; cv=none; d=google.com; s=arc-20160816; b=DLEo9YBo6fr4HbGCZRL0BX9gpGb9laAG/FIdWj8O7JWBmocUnOhGvHURu1+yt4/QDY wReVesF1t2m4W3IohzJKyeRIXi0fckaMkLudxoh0jN6MeEY9RV0NQd9CaFh5tmOWuik8 auuXSRW4O2HGWwiSaiL65uX2ijkTivB67hUHTAzJl8hpe3+7Um7EJh0fjeipJe5m5F0W Z2zPpR8fTxG/nHMKXPA1+HP9kxx1bZfpeuPWN9hxtUI2T5OW8Dxk1GkDTYht/nEh/O0V IoGgRdKhDg+mTcFhRRaL/mX0JwscVCMQ+zxqjlOFGUJflQsmBZE2050w1p5oAGeA+3Qw H+oA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=qGMBrUlPQYOKyx37WJ+CfAZb6HqK2marpAbff4MbnZ8=; b=EZsUApfzrST9OuhmffBMavHOOStF8+mqWlEUYT5zT+AhhPi+Jad+s04FowMYzgEzkK oPyYRsRXuVM3RoRc9HeHt+k9u0Eksn6fNfBiJtfz5jmi/UWtUuAAiK8DpsSejDxzFCos PRN7tS5BqXJXiqrdhX1f0DTp0Oex4rkzOqDhlQLwEMZU+ZChJ/iz/+l2vJM5RL3Vfbs3 LCMf9LM6Ht1DKliJrP9M4JAztXAeNQR8U9TQ+TT1z9CuzE3HJJCEFzfoF+7b6aL33Blm qkpdgQ2Gq23KAwMD/UsXaS6f+IXpsYlSJYIvWjGrAIXq+H6KBd/9mym0un0qpBnaFYaW cVkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="aH/mGSIx"; 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 n11-20020a05640205cb00b00418c2b5be56si195866edx.312.2022.04.01.03.40.17; Fri, 01 Apr 2022 03:40:42 -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="aH/mGSIx"; 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 S241835AbiCaVvi (ORCPT + 99 others); Thu, 31 Mar 2022 17:51:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233935AbiCaVvg (ORCPT ); Thu, 31 Mar 2022 17:51:36 -0400 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4CA85E779 for ; Thu, 31 Mar 2022 14:49:48 -0700 (PDT) Received: by mail-ed1-x536.google.com with SMTP id g20so832282edw.6 for ; Thu, 31 Mar 2022 14:49:48 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=qGMBrUlPQYOKyx37WJ+CfAZb6HqK2marpAbff4MbnZ8=; b=aH/mGSIx6JYuCSnhq67DpbCnoI8R9U2DwIHvu2o8j1p7edTV/pvvLSCRs/VGoNPAlo a37NWAofXqtZ3OenGsky7Zi238NZPpW0UQQjqSfH/GSJd+rK1TAlzcMK6TX/Y7KhwQ99 u8F8/MzXNiodsFeO0VhdCXjH8PQmeJ/qpvaY2r1NIhvlJc5kJqXNY1aYX2joACdxuOCw 5oz+su87Ri/pROAw9FRbGVz5Ot8RjHNHTPW4W7LANksi6yA1X5kFJels8TS4oLKEPR+I dPXON4cFOOdDZ2LsTZIfueKaPIZHZ/i89eoFSDGbnfedTcNXCPMtv3qyvKQgWek1W8N+ ALhA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=qGMBrUlPQYOKyx37WJ+CfAZb6HqK2marpAbff4MbnZ8=; b=iIc3Z5XDViBz/SGPBfqT/ypn593CaugPZP0MqcbjMdHYp3qtqX1QBf2ciGEbts2u4k iXAmtMsUaWgjE19vl/AVkG/FQ8cbGuvnjkXKSz2neC6mlCZPQ3KzISjW+UUe0e8W9rKs KL8TBWLBe6eUY7inLgugeTn7Yo4Xf5oJRP62kh1vzXGB1SJCBWc6bD/dSSTKKE6stnGh WyyfW8EstdNPuvKcJXGfnjIPbktbI5d2cM8QUDBt6gZDWnJGudgJtwW64v32sSZ+Wez6 VcpyWZYXOrS5eTJ/qHzMBTkFc1KtGncjaQujZ9If6f2W5iWbOBz7piMyznlaN0If+czs O2vw== X-Gm-Message-State: AOAM5331oLRhmKst67u3Vd09q7igOpHW0J3sQDf1hQMfWulxQ1kcE3sq bnetuf5pBfQocUa1l9AXfcM= X-Received: by 2002:a05:6402:847:b0:419:7fb0:9e29 with SMTP id b7-20020a056402084700b004197fb09e29mr18299068edz.45.1648763387245; Thu, 31 Mar 2022 14:49:47 -0700 (PDT) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id b8-20020a056402350800b00419407f0dd9sm311698edd.0.2022.03.31.14.49.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Mar 2022 14:49:46 -0700 (PDT) From: Jakob Koschel To: Lubomir Rintel Cc: Russell King , "Russell King (Oracle)" , =?UTF-8?q?Pali=20Roh=C3=A1r?= , Lorenzo Pieralisi , Mike Rapoport , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, "Brian Johannesmeyer" , Cristiano Giuffrida , "Bos, H.J." , Jakob Koschel Subject: [PATCH 2/3] ARM: pxa: ssp: remove check of list iterator against head past the loop body Date: Thu, 31 Mar 2022 23:47:18 +0200 Message-Id: <20220331214719.881886-2-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220331214719.881886-1-jakobkoschel@gmail.com> References: <20220331214719.881886-1-jakobkoschel@gmail.com> 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 When list_for_each_entry() completes the iteration over the whole list without breaking the loop, the iterator value will be a bogus pointer computed based on the head element. While it is safe to use the pointer to determine if it was computed based on the head element, either with list_entry_is_head() or &pos->member == head, using the iterator variable after the loop should be avoided. In preparation to limit the scope of a list iterator to the list traversal loop, use a dedicated pointer to point to the found element [1]. Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ [1] Signed-off-by: Jakob Koschel --- arch/arm/plat-pxa/ssp.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/arch/arm/plat-pxa/ssp.c b/arch/arm/plat-pxa/ssp.c index 563440315acd..6d638f02eac5 100644 --- a/arch/arm/plat-pxa/ssp.c +++ b/arch/arm/plat-pxa/ssp.c @@ -38,22 +38,20 @@ static LIST_HEAD(ssp_list); struct ssp_device *pxa_ssp_request(int port, const char *label) { struct ssp_device *ssp = NULL; + struct ssp_device *iter; mutex_lock(&ssp_lock); - list_for_each_entry(ssp, &ssp_list, node) { - if (ssp->port_id == port && ssp->use_count == 0) { - ssp->use_count++; - ssp->label = label; + list_for_each_entry(iter, &ssp_list, node) { + if (iter->port_id == port && iter->use_count == 0) { + iter->use_count++; + iter->label = label; + ssp = iter; break; } } mutex_unlock(&ssp_lock); - - if (&ssp->node == &ssp_list) - return NULL; - return ssp; } EXPORT_SYMBOL(pxa_ssp_request); @@ -62,22 +60,20 @@ struct ssp_device *pxa_ssp_request_of(const struct device_node *of_node, const char *label) { struct ssp_device *ssp = NULL; + struct ssp_device *iter; mutex_lock(&ssp_lock); - list_for_each_entry(ssp, &ssp_list, node) { - if (ssp->of_node == of_node && ssp->use_count == 0) { - ssp->use_count++; - ssp->label = label; + list_for_each_entry(iter, &ssp_list, node) { + if (iter->of_node == of_node && iter->use_count == 0) { + iter->use_count++; + iter->label = label; + ssp = iter; break; } } mutex_unlock(&ssp_lock); - - if (&ssp->node == &ssp_list) - return NULL; - return ssp; } EXPORT_SYMBOL(pxa_ssp_request_of); -- 2.25.1