Skip to contentSkip to conversation

drm/nouveau: fix error path in nvkm_gsp_fwsec_v2

PATCH Superseded Timur Tabi 2 participants 6 messages Jul 15, 2025 – Jul 18, 2025

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Timur Tabi

author
#0 lore raw

PATCH 1/1 drm/nouveau: fix error path in nvkm_gsp_fwsec_v2

Function nvkm_gsp_fwsec_v2() sets 'ret' if the kmemdup() call fails, but it never uses or returns 'ret' after that point. We always need to release the firmware regardless, so do that and then check for error.

Fixes 176fdcbddfd2 ("drm/nouveau/gsp/r535: add support for booting GSP-RM")
---
 drivers/gpu/drm/nouveau/nvkm/subdev/gsp/fwsec.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/fwsec.c +3 -2
index 52412965fac1..5b721bd9d799 100644
@@ -209,11 +209,12 @@ nvkm_gsp_fwsec_v2(struct nvkm_gsp *gsp, const char *name,
 	fw->boot_addr = bld->start_tag << 8;
 	fw->boot_size = bld->code_size;
 	fw->boot = kmemdup(bl->data + hdr->data_offset + bld->code_off, fw->boot_size, GFP_KERNEL);
-	if (!fw->boot)
-		ret = -ENOMEM;
 
 	nvkm_firmware_put(bl);
 
+	if (!fw->boot)
+		return -ENOMEM;
+
 	/* Patch in interface data. */
 	return nvkm_gsp_fwsec_patch(gsp, fw, desc->InterfaceOffset, init_cmd);
 }

base-commit: 155a3c003e555a7300d156a5252c004c392ec6b0

Signature · 1 line
2.43.0
author
#1 lore raw

PATCH 1/1 drm/nouveau: remove unused memory target test

The memory target check is a hold-over from a refactor. It's harmless but distracting, so just remove it.

---
 drivers/gpu/drm/nouveau/nvkm/falcon/gm200.c | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)
drivers/gpu/drm/nouveau/nvkm/falcon/gm200.c +3 -10
index b7da3ab44c27..f0acfaa153d1 100644
@@ -249,9 +249,11 @@ int
 gm200_flcn_fw_load(struct nvkm_falcon_fw *fw)
 {
 	struct nvkm_falcon *falcon = fw->falcon;
-	int target, ret;
+	int ret;
 
 	if (fw->inst) {
+		int target;
+
 		nvkm_falcon_mask(falcon, 0x048, 0x00000001, 0x00000001);
 
 		switch (nvkm_memory_target(fw->inst)) {
@@ -285,15 +287,6 @@ gm200_flcn_fw_load(struct nvkm_falcon_fw *fw)
 	}
 
 	if (fw->boot) {
-		switch (nvkm_memory_target(&fw->fw.mem.memory)) {
-		case NVKM_MEM_TARGET_VRAM: target = 4; break;
-		case NVKM_MEM_TARGET_HOST: target = 5; break;
-		case NVKM_MEM_TARGET_NCOH: target = 6; break;
-		default:
-			WARN_ON(1);
-			return -EINVAL;
-		}
-
 		ret = nvkm_falcon_pio_wr(falcon, fw->boot, 0, 0,
 					 IMEM, falcon->code.limit - fw->boot_size, fw->boot_size,
 					 fw->boot_addr >> 8, false);

base-commit: 155a3c003e555a7300d156a5252c004c392ec6b0

Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH] drm/nouveau: remove unused memory target test

On Tue, 15 Jul 2025 16:05:59 -0500
Timur Tabi <[email protected]> wrote:

There is also a similar code block in this function:

        if (fw->inst) {
                nvkm_falcon_mask(falcon, 0x048, 0x00000001, 0x00000001);

                switch (nvkm_memory_target(fw->inst)) {
                case NVKM_MEM_TARGET_VRAM: target = 0; break;
                case NVKM_MEM_TARGET_HOST: target = 2; break;
                case NVKM_MEM_TARGET_NCOH: target = 3; break;
                default:
                        WARN_ON(1);
                        return -EINVAL;
                }

Should this be removed with the same purpose here?

Z.

Quoted 43 lines

The memory target check is a hold-over from a refactor. It's harmless but distracting, so just remove it.

---
 drivers/gpu/drm/nouveau/nvkm/falcon/gm200.c | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/nouveau/nvkm/falcon/gm200.c index b7da3ab44c27..f0acfaa153d1 100644 --- a/drivers/gpu/drm/nouveau/nvkm/falcon/gm200.c +++ b/drivers/gpu/drm/nouveau/nvkm/falcon/gm200.c @@ -249,9 +249,11 @@ int
gm200_flcn_fw_load(struct nvkm_falcon_fw *fw)
{

drivers/gpu/drm/nouveau/nvkm/falcon/gm200.c +3 -1
 	struct nvkm_falcon *falcon = fw->falcon;
-	int target, ret;
+	int ret;
 
 	if (fw->inst) {
+		int target;
+
 		nvkm_falcon_mask(falcon, 0x048, 0x00000001,

0x00000001);

drivers/gpu/drm/nouveau/nvkm/falcon/gm200.c +0 -9
 		switch (nvkm_memory_target(fw->inst)) {
@@ -285,15 +287,6 @@ gm200_flcn_fw_load(struct nvkm_falcon_fw *fw)
 	}
 
 	if (fw->boot) {
-		switch (nvkm_memory_target(&fw->fw.mem.memory)) {
-		case NVKM_MEM_TARGET_VRAM: target = 4; break;
-		case NVKM_MEM_TARGET_HOST: target = 5; break;
-		case NVKM_MEM_TARGET_NCOH: target = 6; break;
-		default:
-			WARN_ON(1);
-			return -EINVAL;
-		}
-
 		ret = nvkm_falcon_pio_wr(falcon, fw->boot, 0, 0,
 					 IMEM, falcon->code.limit -
 fw->boot_size, fw->boot_size, fw->boot_addr >> 8, false);

base-commit: 155a3c003e555a7300d156a5252c004c392ec6b0

author
#3 lore raw

Re: [PATCH] drm/nouveau: remove unused memory target test

Quoted 17 lines · Zhi Wang

On Tue, 15 Jul 2025 16:05:59 -0500
Timur Tabi <[email protected]> wrote:

There is also a similar code block in this function:

        if (fw->inst) {
                nvkm_falcon_mask(falcon, 0x048, 0x00000001, 0x00000001);

                switch (nvkm_memory_target(fw->inst)) { case NVKM_MEM_TARGET_VRAM: target = 0; break; case NVKM_MEM_TARGET_HOST: target = 2; break; case NVKM_MEM_TARGET_NCOH: target = 3; break; default:
                        WARN_ON(1);
                        return -EINVAL;
                }

Quoted 1 line

Should this be removed with the same purpose here?

No, 'target' is actually used in this block. That's why I moved that variable to inside the block.

	falcon->func->bind_inst(falcon, target, nvkm_memory_addr(fw->inst));
Reviewed-by
#4 lore raw

Re: [PATCH] drm/nouveau: remove unused memory target test

On Thu, 17 Jul 2025 15:06:24 +0000
Timur Tabi <[email protected]> wrote:

Oh, you are right. LGTM then.

Quoted 27 lines · Zhi Wang
Quoted 18 lines

On Tue, 15 Jul 2025 16:05:59 -0500
Timur Tabi <[email protected]> wrote:

There is also a similar code block in this function:

        if (fw->inst) {
                nvkm_falcon_mask(falcon, 0x048, 0x00000001, 0x00000001);

                switch (nvkm_memory_target(fw->inst)) { case NVKM_MEM_TARGET_VRAM: target = 0; break; case NVKM_MEM_TARGET_HOST: target = 2; break; case NVKM_MEM_TARGET_NCOH: target = 3; break; default:
                        WARN_ON(1);
                        return -EINVAL;
                }

Quoted 1 line

Should this be removed with the same purpose here?

No, 'target' is actually used in this block. That's why I moved that variable to inside the block.

	falcon->func->bind_inst(falcon, target,

nvkm_memory_addr(fw->inst));

#5 lore raw
In reply to Timur Tabi
Quoted 5 lines · On Tue, 15 Jul 2025 16:05:58 -0500 Timur Tabi <[email protected]> wrote:

Function nvkm_gsp_fwsec_v2() sets 'ret' if the kmemdup() call fails, but it never uses or returns 'ret' after that point. We always need to release the firmware regardless, so do that and then check for error.

LGTM. Reviewed-by: Zhi Wang <[email protected]>

Quoted 28 lines
Fixes 176fdcbddfd2 ("drm/nouveau/gsp/r535: add support for booting

GSP-RM") Signed-off-by: Timur Tabi <[email protected]>

---
 drivers/gpu/drm/nouveau/nvkm/subdev/gsp/fwsec.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/fwsec.c index 52412965fac1..5b721bd9d799 100644 --- a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/fwsec.c +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/fwsec.c @@ -209,11 +209,12 @@ nvkm_gsp_fwsec_v2(struct nvkm_gsp *gsp, const char *name, fw->boot_addr = bld->start_tag << 8; fw->boot_size = bld->code_size;
fw->boot = kmemdup(bl->data + hdr->data_offset +
bld->code_off, fw->boot_size, GFP_KERNEL);

drivers/gpu/drm/nouveau/nvkm/subdev/gsp/fwsec.c +3 -2
-	if (!fw->boot)
-		ret = -ENOMEM;
 
 	nvkm_firmware_put(bl);
 
+	if (!fw->boot)
+		return -ENOMEM;
+
 	/* Patch in interface data. */
 	return nvkm_gsp_fwsec_patch(gsp, fw, desc->InterfaceOffset,

init_cmd); }

base-commit: 155a3c003e555a7300d156a5252c004c392ec6b0