Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1431480pxb; Fri, 1 Apr 2022 13:20:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxmoIydk+7N4fdqiiYziFvpuzrP50DKZtFcat4/UJkKVVFYIKG5CRpN6CkYNSSxMb16fJHm X-Received: by 2002:a17:902:ec8d:b0:154:7f38:cd40 with SMTP id x13-20020a170902ec8d00b001547f38cd40mr12137359plg.40.1648844403198; Fri, 01 Apr 2022 13:20:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648844403; cv=none; d=google.com; s=arc-20160816; b=L9g3O3ytCO4L3POvV+9TfAPVWeArm8iueXqhsyllm24q6tyaq4zY3k+uFvFpQhsJtP sYQ3torU33ewmdKkzlydSbxVjla2wJcyhuPKH6bU2nPj73KWmHJSF1AigJ73ubm854Xn Swxq02U4jUfCbkUvsV6W27fJSqgbkMVBCf4kOGKD5lM+20Vr8r3DABI6evnlt57cBsZQ /WEGDobWCw6k4L0BBk65GJWJsIUnA+7mw9P3JpodcGWQorsZ2p7P7QanDXnFUmw7FE0U 7sOlURkdKFKiSfPuBkZuuXEMnUgfHASNt7guFJiO+fs0buM9HbunVIG2d7qxEIHDXEkU wAAQ== 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=s7WvWGnp8e2+ZYg4JNgLcns/TOfiaFHz5BOyp+VBRH4=; b=n8Tnv2XGbpRicg97cSyJBKewJEGZnbEZtsFvLVqorsi1ZrHc1757XSlC++a+1g13uR kAuK3G39/3V7zkdOnQqiaIKgNU951HD1nzRtwqh8/oq8fjc8ZweVTuUzZ5BrabLcAwOi r4jqnNU9d0V69GNnMRRGdYG2i8JDH7MW9cVG/7usXE6EH19lxqVNX3mLOwyG1xoeLwO4 HOeij+yvgOzSOxcIi7O/3rXhng02MSbZBrSmyf5mWhrk9a8+65pWOqshqoch1yXtLeyf i5KKX0DsCCKMZ3pk/ZEeGRv3vhCtCk+8bgak4qLhXjLeP2DXdJ5z+FseaFniuvZYAL4J tGhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=lTyVqB+Z; 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 z16-20020a170903019000b00151f8f6cce5si3239203plg.3.2022.04.01.13.19.46; Fri, 01 Apr 2022 13:20:03 -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=lTyVqB+Z; 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 S237230AbiCaVyp (ORCPT + 99 others); Thu, 31 Mar 2022 17:54:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233991AbiCaVyo (ORCPT ); Thu, 31 Mar 2022 17:54:44 -0400 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91D58231AC1 for ; Thu, 31 Mar 2022 14:52:56 -0700 (PDT) Received: by mail-ej1-x62b.google.com with SMTP id j15so2003607eje.9 for ; Thu, 31 Mar 2022 14:52:56 -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=s7WvWGnp8e2+ZYg4JNgLcns/TOfiaFHz5BOyp+VBRH4=; b=lTyVqB+Zc0e84QnpugtFoYsU6sl7K9xjMJMkDzI/2MY0BSJekhavkyJQoQveEAWCdU U/29yUBVpmdYDctiBtXhoEYWP97aqmJaRfvJx/8zju1ldkj8caD+VGEQPmdRLcJPDfN3 TzTBYCAxHgI0B99roIcLtlO2DXlv/SBgb11EHj0mpaudvCBRHBjt5HznTGbG92ak7BsM G6+xpDaBUobsstl3W8YTkgsQgbjsRot9Mkm4cRA8sWE2qbZPxCRxM6BqHi6Y/Tegc2Xa etQ78axO6I3D6qHS40dFndrk8PBpMN7wIudlaPGoTn/5TpyC4bAis2zdx9DTjQURPGeZ AR7Q== 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=s7WvWGnp8e2+ZYg4JNgLcns/TOfiaFHz5BOyp+VBRH4=; b=R6rgO5NWHp38IaHXvZxaGc/eH3vgHqV8oTZGH0CCUUVio42M6QDEalwcNuUWw8bp36 2UcdRFfOzUKpPt7/tmh2Gl2MRlv6kBkN4eXMw9xYtLPx58AAqag2HIG7XG29IdA5WELj ztXhZx7XjEjElLfBtvThp2yiFX7h4W+ruBTPTjvRW2rE0z2FUUc7U8FGiQmZ3gA5S88l kp+l4q9ak+T7eQXGYRDU8BXacX6cIIvcUrMUGV/yisiTTCooXduC5MvFlrW8L2KADi2M kwMjxLxfnKUv8XMwjF30PDl1XIscxwDIbpHKQaq8vn5Kk3RaN5SbosHp6v8Zrpvk5vrT TRPg== X-Gm-Message-State: AOAM531AzDRXxqJ1b0HBtgZ2UHtNnt9cdwC3MvQKs2+PA9gLTeOWPrRk a8F3+tP1tcuyMIrYCO+arus= X-Received: by 2002:a17:906:e4c:b0:6e0:b002:2b2e with SMTP id q12-20020a1709060e4c00b006e0b0022b2emr6627609eji.690.1648763575022; Thu, 31 Mar 2022 14:52:55 -0700 (PDT) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id g20-20020aa7c594000000b004194b07bbfasm299980edq.10.2022.03.31.14.52.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Mar 2022 14:52:54 -0700 (PDT) From: Jakob Koschel To: Codrin Ciubotariu Cc: Arnd Bergmann , Greg Kroah-Hartman , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , Cezary Rojewski , Pierre-Louis Bossart , Liam Girdwood , Jie Yang , Mark Brown , Jaroslav Kysela , Takashi Iwai , Orson Zhai , Baolin Wang , Chunyan Zhang , Yang Yingliang , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org, Mike Rapoport , "Brian Johannesmeyer" , Cristiano Giuffrida , "Bos, H.J." , Jakob Koschel Subject: [PATCH 1/3] ASoC: Intel: catpt: remove check of list iterator against head past the loop body Date: Thu, 31 Mar 2022 23:50:01 +0200 Message-Id: <20220331215003.882143-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 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 limiting 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 --- sound/soc/intel/catpt/pcm.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/sound/soc/intel/catpt/pcm.c b/sound/soc/intel/catpt/pcm.c index a26000cd5ceb..b103b2d4026e 100644 --- a/sound/soc/intel/catpt/pcm.c +++ b/sound/soc/intel/catpt/pcm.c @@ -330,7 +330,8 @@ static int catpt_dai_apply_usettings(struct snd_soc_dai *dai, struct catpt_stream_runtime *stream) { struct snd_soc_component *component = dai->component; - struct snd_kcontrol *pos; + struct snd_kcontrol *pos = NULL; + struct snd_kcontrol *iter; struct catpt_dev *cdev = dev_get_drvdata(dai->dev); const char *name; int ret; @@ -354,12 +355,14 @@ static int catpt_dai_apply_usettings(struct snd_soc_dai *dai, return 0; } - list_for_each_entry(pos, &component->card->snd_card->controls, list) { - if (pos->private_data == component && - !strncmp(name, pos->id.name, sizeof(pos->id.name))) + list_for_each_entry(iter, &component->card->snd_card->controls, list) { + if (iter->private_data == component && + !strncmp(name, iter->id.name, sizeof(iter->id.name))) { + pos = iter; break; + } } - if (list_entry_is_head(pos, &component->card->snd_card->controls, list)) + if (!pos) return -ENOENT; if (stream->template->type != CATPT_STRM_TYPE_LOOPBACK) base-commit: f82da161ea75dc4db21b2499e4b1facd36dab275 -- 2.25.1