diff mbox series

drm/amdgpu: Avoid printing of stack contents on firmware load error

Message ID nycvar.YFH.7.76.2106241135440.18969@cbobk.fhfr.pm (mailing list archive)
State New, archived
Headers show
Series drm/amdgpu: Avoid printing of stack contents on firmware load error | expand

Commit Message

Jiri Kosina June 24, 2021, 9:37 a.m. UTC
From: Jiri Kosina <jkosina@suse.cz>

In case when psp_init_asd_microcode() fails to load ASD microcode file, 
psp_v12_0_init_microcode() tries to print the firmware filename that 
failed to load before bailing out.

This is wrong because:

- the firmware filename it would want it print is an incorrect one as
  psp_init_asd_microcode() and psp_v12_0_init_microcode() are loading
  different filenames
- it tries to print fw_name, but that's not yet been initialized by that
  time, so it prints random stack contents, e.g.

    amdgpu 0000:04:00.0: Direct firmware load for amdgpu/renoir_asd.bin failed with error -2
    amdgpu 0000:04:00.0: amdgpu: fail to initialize asd microcode
    amdgpu 0000:04:00.0: amdgpu: psp v12.0: Failed to load firmware "\xfeTO\x8e\xff\xff"

Fix that by bailing out immediately, instead of priting the bogus error 
message.

Reported-by: Vojtech Pavlik <vojtech@ucw.cz>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
---
 drivers/gpu/drm/amd/amdgpu/psp_v12_0.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

kernel test robot June 24, 2021, 1:33 p.m. UTC | #1
Hi Jiri,

I love your patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v5.13-rc7 next-20210624]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Jiri-Kosina/drm-amdgpu-Avoid-printing-of-stack-contents-on-firmware-load-error/20210624-173740
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 7426cedc7dad67bf3c71ea6cc29ab7822e1a453f
config: arm64-randconfig-r006-20210622 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project 7c8a507272587f181ec29401453949ebcd8fec65)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install arm64 cross compiling tool for clang build
        # apt-get install binutils-aarch64-linux-gnu
        # https://github.com/0day-ci/linux/commit/f9d4f2041c2724ff3c9126761199d37acede1187
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Jiri-Kosina/drm-amdgpu-Avoid-printing-of-stack-contents-on-firmware-load-error/20210624-173740
        git checkout f9d4f2041c2724ff3c9126761199d37acede1187
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> drivers/gpu/drm/amd/amdgpu/psp_v12_0.c:111:1: warning: unused label 'out' [-Wunused-label]
   out:
   ^~~~
   1 warning generated.


vim +/out +111 drivers/gpu/drm/amd/amdgpu/psp_v12_0.c

6a7a0bdbfa0c24 Aaron Liu     2019-08-09   47  
6a7a0bdbfa0c24 Aaron Liu     2019-08-09   48  static int psp_v12_0_init_microcode(struct psp_context *psp)
6a7a0bdbfa0c24 Aaron Liu     2019-08-09   49  {
6a7a0bdbfa0c24 Aaron Liu     2019-08-09   50  	struct amdgpu_device *adev = psp->adev;
6a7a0bdbfa0c24 Aaron Liu     2019-08-09   51  	const char *chip_name;
6627d1c1a82ba7 Changfeng     2020-09-01   52  	char fw_name[30];
6a7a0bdbfa0c24 Aaron Liu     2019-08-09   53  	int err = 0;
6627d1c1a82ba7 Changfeng     2020-09-01   54  	const struct ta_firmware_header_v1_0 *ta_hdr;
6627d1c1a82ba7 Changfeng     2020-09-01   55  	DRM_DEBUG("\n");
6a7a0bdbfa0c24 Aaron Liu     2019-08-09   56  
6a7a0bdbfa0c24 Aaron Liu     2019-08-09   57  	switch (adev->asic_type) {
6a7a0bdbfa0c24 Aaron Liu     2019-08-09   58  	case CHIP_RENOIR:
68697982204b21 Aaron Liu     2020-10-01   59  		if (adev->apu_flags & AMD_APU_IS_RENOIR)
6a7a0bdbfa0c24 Aaron Liu     2019-08-09   60  			chip_name = "renoir";
68697982204b21 Aaron Liu     2020-10-01   61  		else
68697982204b21 Aaron Liu     2020-10-01   62  			chip_name = "green_sardine";
6a7a0bdbfa0c24 Aaron Liu     2019-08-09   63  		break;
6a7a0bdbfa0c24 Aaron Liu     2019-08-09   64  	default:
6a7a0bdbfa0c24 Aaron Liu     2019-08-09   65  		BUG();
6a7a0bdbfa0c24 Aaron Liu     2019-08-09   66  	}
6a7a0bdbfa0c24 Aaron Liu     2019-08-09   67  
f4503f9eb3a16c Hawking Zhang 2020-04-20   68  	err = psp_init_asd_microcode(psp, chip_name);
6627d1c1a82ba7 Changfeng     2020-09-01   69  	if (err)
f9d4f2041c2724 Jiri Kosina   2021-06-24   70  		return err;
6627d1c1a82ba7 Changfeng     2020-09-01   71  
6627d1c1a82ba7 Changfeng     2020-09-01   72  	snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_ta.bin", chip_name);
6627d1c1a82ba7 Changfeng     2020-09-01   73  	err = request_firmware(&adev->psp.ta_fw, fw_name, adev->dev);
6627d1c1a82ba7 Changfeng     2020-09-01   74  	if (err) {
6627d1c1a82ba7 Changfeng     2020-09-01   75  		release_firmware(adev->psp.ta_fw);
6627d1c1a82ba7 Changfeng     2020-09-01   76  		adev->psp.ta_fw = NULL;
6627d1c1a82ba7 Changfeng     2020-09-01   77  		dev_info(adev->dev,
6627d1c1a82ba7 Changfeng     2020-09-01   78  			 "psp v12.0: Failed to load firmware \"%s\"\n",
6627d1c1a82ba7 Changfeng     2020-09-01   79  			 fw_name);
6627d1c1a82ba7 Changfeng     2020-09-01   80  	} else {
6627d1c1a82ba7 Changfeng     2020-09-01   81  		err = amdgpu_ucode_validate(adev->psp.ta_fw);
6627d1c1a82ba7 Changfeng     2020-09-01   82  		if (err)
6627d1c1a82ba7 Changfeng     2020-09-01   83  			goto out2;
6627d1c1a82ba7 Changfeng     2020-09-01   84  
6627d1c1a82ba7 Changfeng     2020-09-01   85  		ta_hdr = (const struct ta_firmware_header_v1_0 *)
6627d1c1a82ba7 Changfeng     2020-09-01   86  				 adev->psp.ta_fw->data;
6627d1c1a82ba7 Changfeng     2020-09-01   87  		adev->psp.ta_hdcp_ucode_version =
6627d1c1a82ba7 Changfeng     2020-09-01   88  			le32_to_cpu(ta_hdr->ta_hdcp_ucode_version);
6627d1c1a82ba7 Changfeng     2020-09-01   89  		adev->psp.ta_hdcp_ucode_size =
6627d1c1a82ba7 Changfeng     2020-09-01   90  			le32_to_cpu(ta_hdr->ta_hdcp_size_bytes);
6627d1c1a82ba7 Changfeng     2020-09-01   91  		adev->psp.ta_hdcp_start_addr =
6627d1c1a82ba7 Changfeng     2020-09-01   92  			(uint8_t *)ta_hdr +
6627d1c1a82ba7 Changfeng     2020-09-01   93  			le32_to_cpu(ta_hdr->header.ucode_array_offset_bytes);
6627d1c1a82ba7 Changfeng     2020-09-01   94  
6627d1c1a82ba7 Changfeng     2020-09-01   95  		adev->psp.ta_fw_version = le32_to_cpu(ta_hdr->header.ucode_version);
6627d1c1a82ba7 Changfeng     2020-09-01   96  
6627d1c1a82ba7 Changfeng     2020-09-01   97  		adev->psp.ta_dtm_ucode_version =
6627d1c1a82ba7 Changfeng     2020-09-01   98  			le32_to_cpu(ta_hdr->ta_dtm_ucode_version);
6627d1c1a82ba7 Changfeng     2020-09-01   99  		adev->psp.ta_dtm_ucode_size =
6627d1c1a82ba7 Changfeng     2020-09-01  100  			le32_to_cpu(ta_hdr->ta_dtm_size_bytes);
6627d1c1a82ba7 Changfeng     2020-09-01  101  		adev->psp.ta_dtm_start_addr =
6627d1c1a82ba7 Changfeng     2020-09-01  102  			(uint8_t *)adev->psp.ta_hdcp_start_addr +
6627d1c1a82ba7 Changfeng     2020-09-01  103  			le32_to_cpu(ta_hdr->ta_dtm_offset_bytes);
6627d1c1a82ba7 Changfeng     2020-09-01  104  	}
6627d1c1a82ba7 Changfeng     2020-09-01  105  
6627d1c1a82ba7 Changfeng     2020-09-01  106  	return 0;
6627d1c1a82ba7 Changfeng     2020-09-01  107  
6627d1c1a82ba7 Changfeng     2020-09-01  108  out2:
6627d1c1a82ba7 Changfeng     2020-09-01  109  	release_firmware(adev->psp.ta_fw);
6627d1c1a82ba7 Changfeng     2020-09-01  110  	adev->psp.ta_fw = NULL;
6627d1c1a82ba7 Changfeng     2020-09-01 @111  out:
6627d1c1a82ba7 Changfeng     2020-09-01  112  	if (err) {
6627d1c1a82ba7 Changfeng     2020-09-01  113  		dev_err(adev->dev,
6627d1c1a82ba7 Changfeng     2020-09-01  114  			"psp v12.0: Failed to load firmware \"%s\"\n",
6627d1c1a82ba7 Changfeng     2020-09-01  115  			fw_name);
6627d1c1a82ba7 Changfeng     2020-09-01  116  	}
6627d1c1a82ba7 Changfeng     2020-09-01  117  
6a7a0bdbfa0c24 Aaron Liu     2019-08-09  118  	return err;
6a7a0bdbfa0c24 Aaron Liu     2019-08-09  119  }
6a7a0bdbfa0c24 Aaron Liu     2019-08-09  120  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff mbox series

Patch

diff --git a/drivers/gpu/drm/amd/amdgpu/psp_v12_0.c b/drivers/gpu/drm/amd/amdgpu/psp_v12_0.c
index c4828bd3264b..5b21e22ad4b9 100644
--- a/drivers/gpu/drm/amd/amdgpu/psp_v12_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/psp_v12_0.c
@@ -67,7 +67,7 @@  static int psp_v12_0_init_microcode(struct psp_context *psp)
 
 	err = psp_init_asd_microcode(psp, chip_name);
 	if (err)
-		goto out;
+		return err;
 
 	snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_ta.bin", chip_name);
 	err = request_firmware(&adev->psp.ta_fw, fw_name, adev->dev);