mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] staging: greybus: audio: do not use iterator after list loop
@ 2026-10-07  9:11 Rahul Rao
  2026-10-07  9:42 ` Johan Hovold
  0 siblings, 1 reply; 2+ messages in thread
From: Rahul Rao @ 2026-10-07  9:11 UTC (permalink / raw)
  To: Vaibhav Agarwal, Mark Greer, Johan Hovold, Alex Elder,
	Greg Kroah-Hartman
  Cc: greybus-dev, linux-staging, linux-kernel, Rahul Rao

Using the list iterator variable outside the loop breaks iterator scope
semantics and can result in invalid memory access if the loop completes
without finding a match.

Introduce a dedicated iterator variable 'iter' for traversing
codec->module_list and assign it to 'module' only upon finding a match.

Signed-off-by: Rahul Rao <shreeramrahul94@gmail.com>
---
 drivers/staging/greybus/audio_codec.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/greybus/audio_codec.c b/drivers/staging/greybus/audio_codec.c
index 6daa4e706792..f4c3090684bf 100644
--- a/drivers/staging/greybus/audio_codec.c
+++ b/drivers/staging/greybus/audio_codec.c
@@ -395,7 +395,7 @@ static int gbcodec_hw_params(struct snd_pcm_substream *substream,
 	int ret;
 	u8 sig_bits, channels;
 	u32 format, rate;
-	struct gbaudio_module_info *module;
+	struct gbaudio_module_info *module = NULL, *iter;
 	struct gbaudio_data_connection *data;
 	struct gb_bundle *bundle;
 	struct gbaudio_codec_info *codec = dev_get_drvdata(dai->dev);
@@ -437,10 +437,12 @@ static int gbcodec_hw_params(struct snd_pcm_substream *substream,
 	format = GB_AUDIO_PCM_FMT_S16_LE;
 
 	/* find the data connection */
-	list_for_each_entry(module, &codec->module_list, list) {
-		data = find_data(module, dai->id);
-		if (data)
+	list_for_each_entry(iter, &codec->module_list, list) {
+		data = find_data(iter, dai->id);
+		if (data) {
+			module = iter;
 			break;
+		}
 	}
 
 	if (!data) {
-- 
2.43.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] staging: greybus: audio: do not use iterator after list loop
  2026-10-07  9:11 [PATCH] staging: greybus: audio: do not use iterator after list loop Rahul Rao
@ 2026-10-07  9:42 ` Johan Hovold
  0 siblings, 0 replies; 2+ messages in thread
From: Johan Hovold @ 2026-10-07  9:42 UTC (permalink / raw)
  To: Rahul Rao
  Cc: Vaibhav Agarwal, Mark Greer, Alex Elder, Greg Kroah-Hartman,
	greybus-dev, linux-staging, linux-kernel

On Wed, Oct 07, 2026 at 02:41:04PM +0530, Rahul Rao wrote:
> Using the list iterator variable outside the loop breaks iterator scope
> semantics and can result in invalid memory access if the loop completes
> without finding a match.

No, it cannot. I rejected another patch like this earlier this week:

	https://lore.kernel.org/all/asNhLGdigxSqU5Op@hovoldconsulting.com/

I assume this was something flagged by coccinelle here too, which you
should have mentioned in your commit message.

I don't know what the warning message looks like but the term
"potential" is key here. You still need to look at the code to determine
whether there is an actual issue or not.

Johan

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-10-07  9:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-07  9:11 [PATCH] staging: greybus: audio: do not use iterator after list loop Rahul Rao
2026-10-07  9:42 ` Johan Hovold

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®