Skip to contentSkip to conversation

drm/radeon/r100: enhance error handling in r100_cp_init_microcode

PATCH In review Zhouyi Zhou 2 participants 4 messages May 27, 2024 – May 28, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/radeon/r100: enhance error handling in r100_cp_init_microcode

In r100_cp_init_microcode, if rdev->family don't match any of if statement, fw_name will be NULL, which will cause gcc (11.4.0 powerpc64le-linux-gnu) complain:

In function ‘r100_cp_init_microcode’,

    inlined from ‘r100_cp_init’ at drivers/gpu/drm/radeon/r100.c:1136:7:

./include/linux/printk.h:457:44: warning: ‘%s’ directive argument is null [-Wformat-overflow=]
457 | #define printk(fmt, ...) printk_index_wrap(_printk, fmt, ##__VA_ARGS__)

Above warning is emitted during the rcutorture test in in PPC VM of Opensource Lab of Oregon State Univerisity.

Enhance error handling in r100_cp_init_microcode, let r100_cp_init_microcode return with -EINVAL when none of chip families is matched.

---
 drivers/gpu/drm/radeon/r100.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/gpu/drm/radeon/r100.c +7 -0
index 0b1e19345f43..4f8a1bdd9365 100644
@@ -1055,6 +1055,11 @@ static int r100_cp_init_microcode(struct radeon_device *rdev)
 		   (rdev->family == CHIP_RV570)) {
 		DRM_INFO("Loading R500 Microcode\n");
 		fw_name = FIRMWARE_R520;
+	} else {
+		pr_err("radeon_cp: Failed to load firmware \"%d\"\n",
+			rdev->family);
+		err = -EINVAL;
+		goto out;
 	}
 
 	err = request_firmware(&rdev->me_fw, fw_name, rdev->dev);
@@ -1067,6 +1072,8 @@ static int r100_cp_init_microcode(struct radeon_device *rdev)
 		release_firmware(rdev->me_fw);
 		rdev->me_fw = NULL;
 	}
+
+out:
 	return err;
 }
 
Signature · 1 line
2.34.1
maintainer
#1 lore raw

Am 27.05.24 um 03:20 schrieb Zhouyi Zhou:

Quoted 38 lines

In r100_cp_init_microcode, if rdev->family don't match any of if statement, fw_name will be NULL, which will cause gcc (11.4.0 powerpc64le-linux-gnu) complain:

In function ‘r100_cp_init_microcode’,

     inlined from ‘r100_cp_init’ at drivers/gpu/drm/radeon/r100.c:1136:7:

./include/linux/printk.h:457:44: warning: ‘%s’ directive argument is null [-Wformat-overflow=]
457 | #define printk(fmt, ...) printk_index_wrap(_printk, fmt, ##__VA_ARGS__)

Above warning is emitted during the rcutorture test in in PPC VM of Opensource Lab of Oregon State Univerisity.

Enhance error handling in r100_cp_init_microcode, let r100_cp_init_microcode return with -EINVAL when none of chip families is matched.

---
  drivers/gpu/drm/radeon/r100.c | 7 +++++++
  1 file changed, 7 insertions(+)
drivers/gpu/drm/radeon/r100.c +5 -0
index 0b1e19345f43..4f8a1bdd9365 100644
@@ -1055,6 +1055,11 @@ static int r100_cp_init_microcode(struct radeon_device *rdev)
  		   (rdev->family == CHIP_RV570)) {
  		DRM_INFO("Loading R500 Microcode\n");
  		fw_name = FIRMWARE_R520;
+	} else {
+		pr_err("radeon_cp: Failed to load firmware \"%d\"\n",
+			rdev->family);
+		err = -EINVAL;
+		goto out;
  	}
 
  	err = request_firmware(&rdev->me_fw, fw_name, rdev->dev);

drivers/gpu/drm/radeon/r100.c static int r100_cp_init_microcode(struct radeon_device *rdev) · line 1076

Quoted 5 lines
drivers/gpu/drm/radeon/r100.c +2 -0
@@ -1067,6 +1072,8 @@ static int r100_cp_init_microcode(struct radeon_device *rdev)
  		release_firmware(rdev->me_fw);
  		rdev->me_fw = NULL;
  	}
+
+out:

That looks superfluous, just return -EINVAL directly in the else case above.

Apart from that this is for ~15year old hardware. I'm a bit reluctant adding code for something that old even when this change here looks harmless.

Is there a plan to complain about that in an automated checker? If yes then the change is probably justified, if no then I would rather not do it.

Regards,
Christian.

Quoted 3 lines
drivers/gpu/drm/radeon/r100.c +0 -0
  	return err;
  }
 
#2 lore raw

Thanks for reviewing the patch

Quoted 48 lines · Christian König

Am 27.05.24 um 03:20 schrieb Zhouyi Zhou:

Quoted 38 lines

In r100_cp_init_microcode, if rdev->family don't match any of if statement, fw_name will be NULL, which will cause gcc (11.4.0 powerpc64le-linux-gnu) complain:

In function ‘r100_cp_init_microcode’,

     inlined from ‘r100_cp_init’ at drivers/gpu/drm/radeon/r100.c:1136:7:

./include/linux/printk.h:457:44: warning: ‘%s’ directive argument is null [-Wformat-overflow=]
457 | #define printk(fmt, ...) printk_index_wrap(_printk, fmt, ##__VA_ARGS__)

Above warning is emitted during the rcutorture test in in PPC VM of Opensource Lab of Oregon State Univerisity.

Enhance error handling in r100_cp_init_microcode, let r100_cp_init_microcode return with -EINVAL when none of chip families is matched.

---
  drivers/gpu/drm/radeon/r100.c | 7 +++++++
  1 file changed, 7 insertions(+)
drivers/gpu/drm/radeon/r100.c +5 -0
index 0b1e19345f43..4f8a1bdd9365 100644
@@ -1055,6 +1055,11 @@ static int r100_cp_init_microcode(struct radeon_device *rdev)
                 (rdev->family == CHIP_RV570)) {
              DRM_INFO("Loading R500 Microcode\n");
              fw_name = FIRMWARE_R520;
+     } else {
+             pr_err("radeon_cp: Failed to load firmware \"%d\"\n",
+                     rdev->family);
+             err = -EINVAL;
+             goto out;
      }
 
      err = request_firmware(&rdev->me_fw, fw_name, rdev->dev);

drivers/gpu/drm/radeon/r100.c static int r100_cp_init_microcode(struct radeon_device *rdev) · line 1076

Quoted 5 lines
drivers/gpu/drm/radeon/r100.c +2 -0
@@ -1067,6 +1072,8 @@ static int r100_cp_init_microcode(struct radeon_device *rdev)
              release_firmware(rdev->me_fw);
              rdev->me_fw = NULL;
      }
+
+out:

That looks superfluous, just return -EINVAL directly in the else case above.

Quoted 6 lines

Apart from that this is for ~15year old hardware. I'm a bit reluctant adding code for something that old even when this change here looks harmless.

Is there a plan to complain about that in an automated checker? If yes then the change is probably justified, if no then I would rather not do it.

The warning is emitted when I invoke following commands in ubuntu 22.04 (ppc64le)
linux$make allmodconfig
linux$make drivers/gpu/drm/radeon/r100.o (a quick alternative to 'make -j$nproc)

But everything is OK when I invoke following commands in ubuntu 22.04 (ppc64le) linux$make allmodconfig LLVM=1
linux$make drivers/gpu/drm/radeon/r100.o LLVM=1

And I can't reproduce the warning in the x86 environment, so I guess this phenomenon
is toolchain related ;-)

Thanks again
Regards,
Zhouyi

Quoted 8 lines

Regards,
Christian.

Quoted 3 lines
drivers/gpu/drm/radeon/r100.c +0 -0
      return err;
  }
 
#3 lore raw

Fix some error in my previous email

Quoted 57 lines · Zhouyi Zhou

Thanks for reviewing the patch

Quoted 52 lines · Christian König

Am 27.05.24 um 03:20 schrieb Zhouyi Zhou:

Quoted 38 lines

In r100_cp_init_microcode, if rdev->family don't match any of if statement, fw_name will be NULL, which will cause gcc (11.4.0 powerpc64le-linux-gnu) complain:

In function ‘r100_cp_init_microcode’,

     inlined from ‘r100_cp_init’ at drivers/gpu/drm/radeon/r100.c:1136:7:

./include/linux/printk.h:457:44: warning: ‘%s’ directive argument is null [-Wformat-overflow=]
457 | #define printk(fmt, ...) printk_index_wrap(_printk, fmt, ##__VA_ARGS__)

Above warning is emitted during the rcutorture test in in PPC VM of Opensource Lab of Oregon State Univerisity.

Enhance error handling in r100_cp_init_microcode, let r100_cp_init_microcode return with -EINVAL when none of chip families is matched.

---
  drivers/gpu/drm/radeon/r100.c | 7 +++++++
  1 file changed, 7 insertions(+)
drivers/gpu/drm/radeon/r100.c +5 -0
index 0b1e19345f43..4f8a1bdd9365 100644
@@ -1055,6 +1055,11 @@ static int r100_cp_init_microcode(struct radeon_device *rdev)
                 (rdev->family == CHIP_RV570)) {
              DRM_INFO("Loading R500 Microcode\n");
              fw_name = FIRMWARE_R520;
+     } else {
+             pr_err("radeon_cp: Failed to load firmware \"%d\"\n",
+                     rdev->family);
+             err = -EINVAL;
+             goto out;
      }
 
      err = request_firmware(&rdev->me_fw, fw_name, rdev->dev);

drivers/gpu/drm/radeon/r100.c static int r100_cp_init_microcode(struct radeon_device *rdev) · line 1076

Quoted 5 lines
drivers/gpu/drm/radeon/r100.c +2 -0
@@ -1067,6 +1072,8 @@ static int r100_cp_init_microcode(struct radeon_device *rdev)
              release_firmware(rdev->me_fw);
              rdev->me_fw = NULL;
      }
+
+out:

That looks superfluous, just return -EINVAL directly in the else case above.

Apart from that this is for ~15year old hardware. I'm a bit reluctant adding code for something that old even when this change here looks harmless.

Quoted 6 lines
Quoted 2 lines

Is there a plan to complain about that in an automated checker? If yes then the change is probably justified, if no then I would rather not do it.

The warning is emitted when I invoke following commands in ubuntu 22.04 (ppc64le)
linux$make allmodconfig
linux$make drivers/gpu/drm/radeon/r100.o (a quick alternative to 'make -j$nproc)

the command should be make -j(number of CPUs in my machine), please don't invoke 'make -j$nproc' which is my mistake, this command is very dangerous, and make my machine hung ;-(

Sorry for the trouble
Thanks again
Zhouyi

Quoted 19 lines

But everything is OK when I invoke following commands in ubuntu 22.04 (ppc64le) linux$make allmodconfig LLVM=1
linux$make drivers/gpu/drm/radeon/r100.o LLVM=1

And I can't reproduce the warning in the x86 environment, so I guess this phenomenon
is toolchain related ;-)

Thanks again
Regards,
Zhouyi

Quoted 8 lines

Regards,
Christian.

Quoted 3 lines
drivers/gpu/drm/radeon/r100.c +0 -0
      return err;
  }