[PATCH 1/2] staging: media: atomisp: return early on hmm_bo_device_init() failure

Abdelrahman Fekry posted 2 patches 3 months ago
[PATCH 1/2] staging: media: atomisp: return early on hmm_bo_device_init() failure
Posted by Abdelrahman Fekry 3 months ago
hmm_init() would continue execution even if hmm_bo_device_init() failed,
potentially leading to bad behaviour when calling hmm_alloc().

- returns the error immediately if hmm_bo_device_init() fails.

Signed-off-by: Abdelrahman Fekry <abdelrahmanfekry375@gmail.com>
---
 drivers/staging/media/atomisp/pci/hmm/hmm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/media/atomisp/pci/hmm/hmm.c b/drivers/staging/media/atomisp/pci/hmm/hmm.c
index f998b57f90c4..c2ee9d2ec0d5 100644
--- a/drivers/staging/media/atomisp/pci/hmm/hmm.c
+++ b/drivers/staging/media/atomisp/pci/hmm/hmm.c
@@ -36,6 +36,7 @@ int hmm_init(void)
 				 ISP_VM_START, ISP_VM_SIZE);
 	if (ret)
 		dev_err(atomisp_dev, "hmm_bo_device_init failed.\n");
+		return ret;
 
 	hmm_initialized = true;
 
@@ -48,7 +49,7 @@ int hmm_init(void)
 	 */
 	dummy_ptr = hmm_alloc(1);
 
-	return ret;
+	return 0;
 }
 
 void hmm_cleanup(void)
-- 
2.25.1
Re: [PATCH 1/2] staging: media: atomisp: return early on hmm_bo_device_init() failure
Posted by Hans de Goede 3 months ago
Hi Abdelrahman,

On 7-Jul-25 16:09, Abdelrahman Fekry wrote:
> hmm_init() would continue execution even if hmm_bo_device_init() failed,
> potentially leading to bad behaviour when calling hmm_alloc().
> 
> - returns the error immediately if hmm_bo_device_init() fails.
> 
> Signed-off-by: Abdelrahman Fekry <abdelrahmanfekry375@gmail.com>
> ---
>  drivers/staging/media/atomisp/pci/hmm/hmm.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/media/atomisp/pci/hmm/hmm.c b/drivers/staging/media/atomisp/pci/hmm/hmm.c
> index f998b57f90c4..c2ee9d2ec0d5 100644
> --- a/drivers/staging/media/atomisp/pci/hmm/hmm.c
> +++ b/drivers/staging/media/atomisp/pci/hmm/hmm.c
> @@ -36,6 +36,7 @@ int hmm_init(void)
>  				 ISP_VM_START, ISP_VM_SIZE);
>  	if (ret)
>  		dev_err(atomisp_dev, "hmm_bo_device_init failed.\n");
> +		return ret;

You need to add { } here otherwise the "return ret;" will
always get executed since it is not part of the code block
guarded by the if (despite the indentation).

Regards,

Hans



>  
>  	hmm_initialized = true;
>  
> @@ -48,7 +49,7 @@ int hmm_init(void)
>  	 */
>  	dummy_ptr = hmm_alloc(1);
>  
> -	return ret;
> +	return 0;
>  }
>  
>  void hmm_cleanup(void)
Re: [PATCH 1/2] staging: media: atomisp: return early on hmm_bo_device_init() failure
Posted by Abdelrahman Fekry 3 months ago
Hi Hans.
On Mon, Jul 7, 2025 at 5:12 PM Hans de Goede <hansg@kernel.org> wrote:
>
> Hi Abdelrahman,
>
> On 7-Jul-25 16:09, Abdelrahman Fekry wrote:
> > hmm_init() would continue execution even if hmm_bo_device_init() failed,
> > potentially leading to bad behaviour when calling hmm_alloc().
> >
> > - returns the error immediately if hmm_bo_device_init() fails.
> >
> > Signed-off-by: Abdelrahman Fekry <abdelrahmanfekry375@gmail.com>
> > ---
> >  drivers/staging/media/atomisp/pci/hmm/hmm.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/staging/media/atomisp/pci/hmm/hmm.c b/drivers/staging/media/atomisp/pci/hmm/hmm.c
> > index f998b57f90c4..c2ee9d2ec0d5 100644
> > --- a/drivers/staging/media/atomisp/pci/hmm/hmm.c
> > +++ b/drivers/staging/media/atomisp/pci/hmm/hmm.c
> > @@ -36,6 +36,7 @@ int hmm_init(void)
> >                                ISP_VM_START, ISP_VM_SIZE);
> >       if (ret)
> >               dev_err(atomisp_dev, "hmm_bo_device_init failed.\n");
> > +             return ret;
>
> You need to add { } here otherwise the "return ret;" will
> always get executed since it is not part of the code block
> guarded by the if (despite the indentation).
>
Yes , sorry for this dumb mistake. I will send v2.

> Regards,
>
> Hans
>
>
>
> >
> >       hmm_initialized = true;
> >
> > @@ -48,7 +49,7 @@ int hmm_init(void)
> >        */
> >       dummy_ptr = hmm_alloc(1);
> >
> > -     return ret;
> > +     return 0;
> >  }
> >
> >  void hmm_cleanup(void)
>
Re: [PATCH 1/2] staging: media: atomisp: return early on hmm_bo_device_init() failure
Posted by Dan Carpenter 2 months, 3 weeks ago
On Mon, Jul 07, 2025 at 05:15:20PM +0300, Abdelrahman Fekry wrote:
> Hi Hans.
> On Mon, Jul 7, 2025 at 5:12 PM Hans de Goede <hansg@kernel.org> wrote:
> >
> > Hi Abdelrahman,
> >
> > On 7-Jul-25 16:09, Abdelrahman Fekry wrote:
> > > hmm_init() would continue execution even if hmm_bo_device_init() failed,
> > > potentially leading to bad behaviour when calling hmm_alloc().
> > >
> > > - returns the error immediately if hmm_bo_device_init() fails.
> > >
> > > Signed-off-by: Abdelrahman Fekry <abdelrahmanfekry375@gmail.com>
> > > ---
> > >  drivers/staging/media/atomisp/pci/hmm/hmm.c | 3 ++-
> > >  1 file changed, 2 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/staging/media/atomisp/pci/hmm/hmm.c b/drivers/staging/media/atomisp/pci/hmm/hmm.c
> > > index f998b57f90c4..c2ee9d2ec0d5 100644
> > > --- a/drivers/staging/media/atomisp/pci/hmm/hmm.c
> > > +++ b/drivers/staging/media/atomisp/pci/hmm/hmm.c
> > > @@ -36,6 +36,7 @@ int hmm_init(void)
> > >                                ISP_VM_START, ISP_VM_SIZE);
> > >       if (ret)
> > >               dev_err(atomisp_dev, "hmm_bo_device_init failed.\n");
> > > +             return ret;
> >
> > You need to add { } here otherwise the "return ret;" will
> > always get executed since it is not part of the code block
> > guarded by the if (despite the indentation).
> >
> Yes , sorry for this dumb mistake. I will send v2.
> 

Smatch has a check for this.

~/smatch/smatch_scripts/kchecker drivers/staging/media/atomisp/pci/hmm/hmm.c

regards,
dan carpenter

Re: [PATCH 1/2] staging: media: atomisp: return early on hmm_bo_device_init() failure
Posted by Abdelrahman Fekry 2 months, 3 weeks ago
Hi Dan,
On Mon, Jul 14, 2025 at 10:13 PM Dan Carpenter <dan.carpenter@linaro.org> wrote:
>
> Smatch has a check for this.
>
> ~/smatch/smatch_scripts/kchecker drivers/staging/media/atomisp/pci/hmm/hmm.c
>
I have sent a new patch series that this was fixed in and added other patches
here is the link :
https://lore.kernel.org/all/20250712191325.132666-1-abdelrahmanfekry375@gmail.com/
> regards,
> dan carpenter
>