drm/nouveau/mmu/r535: uninitialized variable in r535_bar_new_()

Message ID dab21df7-4d90-4479-97d8-97e5d228c714@moroto.mountain
State New
Headers
Series drm/nouveau/mmu/r535: uninitialized variable in r535_bar_new_() |

Commit Message

Dan Carpenter Feb. 13, 2024, 6:09 p.m. UTC
  If gf100_bar_new_() fails then "bar" is not initialized.

Fixes: 5bf0257136a2 ("drm/nouveau/mmu/r535: initial support")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
It looks like this was intended to handle a failure from the "rm" func
but "rm" can't actually fail so it's easier to write the error handling
for the code as-is.

 drivers/gpu/drm/nouveau/nvkm/subdev/bar/r535.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
  

Comments

Danilo Krummrich Feb. 16, 2024, 6:28 p.m. UTC | #1
On 2/13/24 19:09, Dan Carpenter wrote:
> If gf100_bar_new_() fails then "bar" is not initialized.
> 
> Fixes: 5bf0257136a2 ("drm/nouveau/mmu/r535: initial support")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>

Applied to drm-misc-fixes, thanks!

> ---
> It looks like this was intended to handle a failure from the "rm" func
> but "rm" can't actually fail so it's easier to write the error handling
> for the code as-is.
> 
>   drivers/gpu/drm/nouveau/nvkm/subdev/bar/r535.c | 5 ++---
>   1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/bar/r535.c b/drivers/gpu/drm/nouveau/nvkm/subdev/bar/r535.c
> index 4135690326f4..3a30bea30e36 100644
> --- a/drivers/gpu/drm/nouveau/nvkm/subdev/bar/r535.c
> +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/bar/r535.c
> @@ -168,12 +168,11 @@ r535_bar_new_(const struct nvkm_bar_func *hw, struct nvkm_device *device,
>   	rm->flush = r535_bar_flush;
>   
>   	ret = gf100_bar_new_(rm, device, type, inst, &bar);
> -	*pbar = bar;
>   	if (ret) {
> -		if (!bar)
> -			kfree(rm);
> +		kfree(rm);
>   		return ret;
>   	}
> +	*pbar = bar;
>   
>   	bar->flushBAR2PhysMode = ioremap(device->func->resource_addr(device, 3), PAGE_SIZE);
>   	if (!bar->flushBAR2PhysMode)
  

Patch

diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/bar/r535.c b/drivers/gpu/drm/nouveau/nvkm/subdev/bar/r535.c
index 4135690326f4..3a30bea30e36 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/bar/r535.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/bar/r535.c
@@ -168,12 +168,11 @@  r535_bar_new_(const struct nvkm_bar_func *hw, struct nvkm_device *device,
 	rm->flush = r535_bar_flush;
 
 	ret = gf100_bar_new_(rm, device, type, inst, &bar);
-	*pbar = bar;
 	if (ret) {
-		if (!bar)
-			kfree(rm);
+		kfree(rm);
 		return ret;
 	}
+	*pbar = bar;
 
 	bar->flushBAR2PhysMode = ioremap(device->func->resource_addr(device, 3), PAGE_SIZE);
 	if (!bar->flushBAR2PhysMode)