mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jakob Koschel <jakobkoschel@gmail.com>
To: Codrin Ciubotariu <codrin.ciubotariu@microchip.com>
Cc: Arnd Bergmann <arnd@arndb.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Nicolas Ferre <nicolas.ferre@microchip.com>,
	Alexandre Belloni <alexandre.belloni@bootlin.com>,
	Claudiu Beznea <claudiu.beznea@microchip.com>,
	Cezary Rojewski <cezary.rojewski@intel.com>,
	Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>,
	Liam Girdwood <liam.r.girdwood@linux.intel.com>,
	Jie Yang <yang.jie@linux.intel.com>,
	Mark Brown <broonie@kernel.org>, Jaroslav Kysela <perex@perex.cz>,
	Takashi Iwai <tiwai@suse.com>, Orson Zhai <orsonzhai@gmail.com>,
	Baolin Wang <baolin.wang7@gmail.com>,
	Chunyan Zhang <zhang.lyra@gmail.com>,
	Yang Yingliang <yangyingliang@huawei.com>,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org,
	Mike Rapoport <rppt@kernel.org>,
	"Brian Johannesmeyer" <bjohannesmeyer@gmail.com>,
	Cristiano Giuffrida <c.giuffrida@vu.nl>,
	"Bos, H.J." <h.j.bos@vu.nl>,
	Jakob Koschel <jakobkoschel@gmail.com>
Subject: [PATCH 2/3] ASoC: sprd: remove check of list iterator against head past the loop body
Date: Thu, 31 Mar 2022 23:50:02 +0200	[thread overview]
Message-ID: <20220331215003.882143-2-jakobkoschel@gmail.com> (raw)
In-Reply-To: <20220331215003.882143-1-jakobkoschel@gmail.com>

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 <jakobkoschel@gmail.com>
---
 sound/soc/sprd/sprd-mcdt.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/sound/soc/sprd/sprd-mcdt.c b/sound/soc/sprd/sprd-mcdt.c
index f6a55fa60c1b..6e27789a0df5 100644
--- a/sound/soc/sprd/sprd-mcdt.c
+++ b/sound/soc/sprd/sprd-mcdt.c
@@ -866,20 +866,19 @@ EXPORT_SYMBOL_GPL(sprd_mcdt_chan_dma_disable);
 struct sprd_mcdt_chan *sprd_mcdt_request_chan(u8 channel,
 					      enum sprd_mcdt_channel_type type)
 {
-	struct sprd_mcdt_chan *temp;
+	struct sprd_mcdt_chan *temp = NULL;
+	struct sprd_mcdt_chan *iter;
 
 	mutex_lock(&sprd_mcdt_list_mutex);
 
-	list_for_each_entry(temp, &sprd_mcdt_chan_list, list) {
-		if (temp->type == type && temp->id == channel) {
-			list_del_init(&temp->list);
+	list_for_each_entry(iter, &sprd_mcdt_chan_list, list) {
+		if (iter->type == type && iter->id == channel) {
+			list_del_init(&iter->list);
+			temp = iter;
 			break;
 		}
 	}
 
-	if (list_entry_is_head(temp, &sprd_mcdt_chan_list, list))
-		temp = NULL;
-
 	mutex_unlock(&sprd_mcdt_list_mutex);
 
 	return temp;
-- 
2.25.1


  reply	other threads:[~2022-03-31 21:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-31 21:50 [PATCH 1/3] ASoC: Intel: catpt: " Jakob Koschel
2022-03-31 21:50 ` Jakob Koschel [this message]
2022-04-01  2:12   ` [PATCH 2/3] ASoC: sprd: " Baolin Wang
2022-03-31 21:50 ` [PATCH 3/3] ASoC: atmel-ssc: replace usage of found with dedicated list iterator variable Jakob Koschel
2022-04-05  6:44   ` Codrin.Ciubotariu
2022-04-01  7:00 ` [PATCH 1/3] ASoC: Intel: catpt: remove check of list iterator against head past the loop body Cezary Rojewski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220331215003.882143-2-jakobkoschel@gmail.com \
    --to=jakobkoschel@gmail.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=arnd@arndb.de \
    --cc=baolin.wang7@gmail.com \
    --cc=bjohannesmeyer@gmail.com \
    --cc=broonie@kernel.org \
    --cc=c.giuffrida@vu.nl \
    --cc=cezary.rojewski@intel.com \
    --cc=claudiu.beznea@microchip.com \
    --cc=codrin.ciubotariu@microchip.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=h.j.bos@vu.nl \
    --cc=liam.r.girdwood@linux.intel.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nicolas.ferre@microchip.com \
    --cc=orsonzhai@gmail.com \
    --cc=perex@perex.cz \
    --cc=pierre-louis.bossart@linux.intel.com \
    --cc=rppt@kernel.org \
    --cc=tiwai@suse.com \
    --cc=yang.jie@linux.intel.com \
    --cc=yangyingliang@huawei.com \
    --cc=zhang.lyra@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®