[PATCH] drm/amdgpu: Add NULL check for imu.funcs in gfx_v11_0_rlc_backdoor_autoload_enable

Srinivasan Shanmugam srinivasan.shanmugam at amd.com
Sat Jun 15 12:33:22 UTC 2024


This commit adds a null check for `adev->gfx.imu.funcs` in the
`gfx_v11_0_rlc_backdoor_autoload_enable` function. This prevents
potential null pointer dereferences when calling the `load_microcode`,
`setup_imu`, and `start_imu` functions.

Previously, if `adev->gfx.imu.funcs` was null, it could lead to a null
pointer dereference. With this change, these function calls are   only
made if `adev->gfx.imu.funcs` is not null.

Fixes the below:
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c:4503 gfx_v11_0_hw_init()
error: we previously assumed 'adev->gfx.imu.funcs' could be null (see line 4497)

drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
    4491 static int gfx_v11_0_hw_init(void *handle)
    4492 {
    4493         int r;
    4494         struct amdgpu_device *adev = (struct amdgpu_device *)handle;
    4495
    4496         if (adev->firmware.load_type == AMDGPU_FW_LOAD_RLC_BACKDOOR_AUTO) {
    4497                 if (adev->gfx.imu.funcs) {
                             ^^^^^^^^^^^^^^^^^^^ Check for NULL

    4498                         /* RLC autoload sequence 1: Program rlc ram */
    4499                         if (adev->gfx.imu.funcs->program_rlc_ram)
    4500                                 adev->gfx.imu.funcs->program_rlc_ram(adev);
    4501                 }
    4502                 /* rlc autoload firmware */
--> 4503                 r = gfx_v11_0_rlc_backdoor_autoload_enable(adev);
                                                                    ^^^^ Unchecked dereference inside the function.
    4505                         return r;
    4506         } else {

Fixes: 3d879e81f0f9 ("drm/amdgpu: add init support for GFX11 (v2)")
Reported-by: Dan Carpenter <dan.carpenter at linaro.org>
Cc: Hawking Zhang <Hawking.Zhang at amd.com>
Cc: Alex Deucher <alexander.deucher at amd.com>
Cc: Christian König <christian.koenig at amd.com>
Signed-off-by: Srinivasan Shanmugam <srinivasan.shanmugam at amd.com>
---
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
index 2a510351dfce..4af4567ba197 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
@@ -1459,14 +1459,16 @@ static int gfx_v11_0_rlc_backdoor_autoload_enable(struct amdgpu_device *adev)
 
 	WREG32_SOC15(GC, 0, regGFX_IMU_RLC_BOOTLOADER_SIZE, rlc_g_size);
 
-	/* RLC autoload sequence 3: load IMU fw */
-	if (adev->gfx.imu.funcs->load_microcode)
-		adev->gfx.imu.funcs->load_microcode(adev);
-	/* RLC autoload sequence 4 init IMU fw */
-	if (adev->gfx.imu.funcs->setup_imu)
-		adev->gfx.imu.funcs->setup_imu(adev);
-	if (adev->gfx.imu.funcs->start_imu)
-		adev->gfx.imu.funcs->start_imu(adev);
+	if (adev->gfx.imu.funcs) {
+		/* RLC autoload sequence 3: load IMU fw */
+		if (adev->gfx.imu.funcs->load_microcode)
+			adev->gfx.imu.funcs->load_microcode(adev);
+		/* RLC autoload sequence 4 init IMU fw */
+		if (adev->gfx.imu.funcs->setup_imu)
+			adev->gfx.imu.funcs->setup_imu(adev);
+		if (adev->gfx.imu.funcs->start_imu)
+			adev->gfx.imu.funcs->start_imu(adev);
+	}
 
 	/* RLC autoload sequence 5 disable gpa mode */
 	gfx_v11_0_disable_gpa_mode(adev);
-- 
2.34.1



More information about the amd-gfx mailing list