'smc_fw' is not released when its size is not as expected, causing memory leak. And when other firmware sizes do not meet expectations, 'err' is assigned but does not jump to 'out'. Signed-off-by: Lu Yao <yaolu@xxxxxxxxxx> --- drivers/gpu/drm/radeon/ni.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/radeon/ni.c b/drivers/gpu/drm/radeon/ni.c index 3890911fe693..11f7a05a5261 100644 --- a/drivers/gpu/drm/radeon/ni.c +++ b/drivers/gpu/drm/radeon/ni.c @@ -765,6 +765,7 @@ int ni_init_microcode(struct radeon_device *rdev) pr_err("ni_cp: Bogus length %zu in firmware \"%s\"\n", rdev->me_fw->size, fw_name); err = -EINVAL; + goto out; } snprintf(fw_name, sizeof(fw_name), "radeon/%s_rlc.bin", rlc_chip_name); @@ -775,6 +776,7 @@ int ni_init_microcode(struct radeon_device *rdev) pr_err("ni_rlc: Bogus length %zu in firmware \"%s\"\n", rdev->rlc_fw->size, fw_name); err = -EINVAL; + goto out; } /* no MC ucode on TN */ @@ -787,6 +789,7 @@ int ni_init_microcode(struct radeon_device *rdev) pr_err("ni_mc: Bogus length %zu in firmware \"%s\"\n", rdev->mc_fw->size, fw_name); err = -EINVAL; + goto out; } } @@ -795,9 +798,7 @@ int ni_init_microcode(struct radeon_device *rdev) err = request_firmware(&rdev->smc_fw, fw_name, rdev->dev); if (err) { pr_err("smc: error loading firmware \"%s\"\n", fw_name); - release_firmware(rdev->smc_fw); - rdev->smc_fw = NULL; - err = 0; + err = -EINVAL; } else if (rdev->smc_fw->size != smc_req_size) { pr_err("ni_mc: Bogus length %zu in firmware \"%s\"\n", rdev->smc_fw->size, fw_name); @@ -818,6 +819,8 @@ int ni_init_microcode(struct radeon_device *rdev) rdev->rlc_fw = NULL; release_firmware(rdev->mc_fw); rdev->mc_fw = NULL; + release_firmware(rdev->smc_fw); + rdev->smc_fw = NULL; } return err; } -- 2.25.1