mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] staging: vme_user: avoid iterator variable access outside list loop
@ 2026-10-12  3:40 Riccardo Oliva
  2026-10-13 13:40 ` Greg KH
  0 siblings, 1 reply; 3+ messages in thread
From: Riccardo Oliva @ 2026-10-12  3:40 UTC (permalink / raw)
  To: gregkh, linux-staging; +Cc: linux-kernel, oliva.scorza

In vme_slave_request(), vme_master_request(), vme_dma_request(), and
vme_lm_request(), the list iterators (slave_image, master_image,
dma_ctrlr, and lm) are accessed in the err_alloc error paths after
exiting the list_for_each_entry() loops.

While the iterator variable retains its pointer value upon hitting a
break, accessing list iterators outside the loop body violates modern
kernel coding standards.

Fix this by referencing the dedicated allocated resource pointers
(allocated_image, allocated_ctrlr, allocated_lm) in the error cleanup
blocks instead.

Signed-off-by: Riccardo Oliva <oliva.scorza@gmail.com>
---
Hi! This is my first patch to the kernel. I am learning the submission 
workflow. Any feedback is very much appreciated. Thanks!

 drivers/staging/vme_user/vme.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/staging/vme_user/vme.c b/drivers/staging/vme_user/vme.c
index b5c66b66c..d38c792eb 100644
--- a/drivers/staging/vme_user/vme.c
+++ b/drivers/staging/vme_user/vme.c
@@ -298,9 +298,9 @@ struct vme_resource *vme_slave_request(struct vme_dev *vdev, u32 address,
 
 err_alloc:
 	/* Unlock image */
-	mutex_lock(&slave_image->mtx);
-	slave_image->locked = 0;
-	mutex_unlock(&slave_image->mtx);
+	mutex_lock(&allocated_image->mtx);
+	allocated_image->locked = 0;
+	mutex_unlock(&allocated_image->mtx);
 err_image:
 err_bus:
 	return NULL;
@@ -495,9 +495,9 @@ struct vme_resource *vme_master_request(struct vme_dev *vdev, u32 address,
 
 err_alloc:
 	/* Unlock image */
-	spin_lock(&master_image->lock);
-	master_image->locked = 0;
-	spin_unlock(&master_image->lock);
+	spin_lock(&allocated_image->lock);
+	allocated_image->locked = 0;
+	spin_unlock(&allocated_image->lock);
 err_image:
 err_bus:
 	return NULL;
@@ -865,9 +865,9 @@ struct vme_resource *vme_dma_request(struct vme_dev *vdev, u32 route)
 
 err_alloc:
 	/* Unlock image */
-	mutex_lock(&dma_ctrlr->mtx);
-	dma_ctrlr->locked = 0;
-	mutex_unlock(&dma_ctrlr->mtx);
+	mutex_lock(&allocated_ctrlr->mtx);
+	allocated_ctrlr->locked = 0;
+	mutex_unlock(&allocated_ctrlr->mtx);
 err_ctrlr:
 err_bus:
 	return NULL;
@@ -1469,9 +1469,9 @@ struct vme_resource *vme_lm_request(struct vme_dev *vdev)
 
 err_alloc:
 	/* Unlock image */
-	mutex_lock(&lm->mtx);
-	lm->locked = 0;
-	mutex_unlock(&lm->mtx);
+	mutex_lock(&allocated_lm->mtx);
+	allocated_lm->locked = 0;
+	mutex_unlock(&allocated_lm->mtx);
 err_lm:
 err_bus:
 	return NULL;
-- 
2.43.0


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

* Re: [PATCH] staging: vme_user: avoid iterator variable access outside list loop
  2026-10-12  3:40 [PATCH] staging: vme_user: avoid iterator variable access outside list loop Riccardo Oliva
@ 2026-10-13 13:40 ` Greg KH
  2026-10-13 17:30   ` Riccardo Oliva
  0 siblings, 1 reply; 3+ messages in thread
From: Greg KH @ 2026-10-13 13:40 UTC (permalink / raw)
  To: Riccardo Oliva; +Cc: linux-staging, linux-kernel

On Sun, Oct 11, 2026 at 10:40:20PM -0500, Riccardo Oliva wrote:
> In vme_slave_request(), vme_master_request(), vme_dma_request(), and
> vme_lm_request(), the list iterators (slave_image, master_image,
> dma_ctrlr, and lm) are accessed in the err_alloc error paths after
> exiting the list_for_each_entry() loops.
> 
> While the iterator variable retains its pointer value upon hitting a
> break, accessing list iterators outside the loop body violates modern
> kernel coding standards.
> 
> Fix this by referencing the dedicated allocated resource pointers
> (allocated_image, allocated_ctrlr, allocated_lm) in the error cleanup
> blocks instead.
> 
> Signed-off-by: Riccardo Oliva <oliva.scorza@gmail.com>
> ---
> Hi! This is my first patch to the kernel. I am learning the submission 
> workflow. Any feedback is very much appreciated. Thanks!

How was this found and tested?

thanks,

greg k-h

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

* Re: [PATCH] staging: vme_user: avoid iterator variable access outside list loop
  2026-10-13 13:40 ` Greg KH
@ 2026-10-13 17:30   ` Riccardo Oliva
  0 siblings, 0 replies; 3+ messages in thread
From: Riccardo Oliva @ 2026-10-13 17:30 UTC (permalink / raw)
  To: Greg KH; +Cc: linux-staging, linux-kernel

> How was this found and tested?
>
> thanks,
>
> greg k-h

This was found using Coccinelle with:
linux/scripts/coccinelle/iterators/use_after_iter.cocci

It was compile-tested on x86_64 using defconfig:
make M=drivers/staging/vme_user

(Note: I do not have access to the physical hardware for testing)

Thanks,
Riccardo Oliva


Il giorno mar 13 ott 2026 alle ore 08:40 Greg KH
<gregkh@linuxfoundation.org> ha scritto:
>
> On Sun, Oct 11, 2026 at 10:40:20PM -0500, Riccardo Oliva wrote:
> > In vme_slave_request(), vme_master_request(), vme_dma_request(), and
> > vme_lm_request(), the list iterators (slave_image, master_image,
> > dma_ctrlr, and lm) are accessed in the err_alloc error paths after
> > exiting the list_for_each_entry() loops.
> >
> > While the iterator variable retains its pointer value upon hitting a
> > break, accessing list iterators outside the loop body violates modern
> > kernel coding standards.
> >
> > Fix this by referencing the dedicated allocated resource pointers
> > (allocated_image, allocated_ctrlr, allocated_lm) in the error cleanup
> > blocks instead.
> >
> > Signed-off-by: Riccardo Oliva <oliva.scorza@gmail.com>
> > ---
> > Hi! This is my first patch to the kernel. I am learning the submission
> > workflow. Any feedback is very much appreciated. Thanks!
>
> How was this found and tested?
>
> thanks,
>
> greg k-h

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

end of thread, other threads:[~2026-10-13 17:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-12  3:40 [PATCH] staging: vme_user: avoid iterator variable access outside list loop Riccardo Oliva
2026-10-13 13:40 ` Greg KH
2026-10-13 17:30   ` Riccardo Oliva

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®