Re: [PATCH] staging: vme_user: avoid iterator variable access outside list loop
From: Riccardo Oliva
Date: Tue Oct 13 2026 - 16:50:35 EST
> 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@xxxxxxxxxxxxxxxxxxx> 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@xxxxxxxxx>
> > ---
> > 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