Skip to contentSkip to conversation

habanalabs: added return value check for hl_fw_dynamic_send_clear_cmd()

PATCH In review Marco Pagani 3 participants 3 messages Nov 16, 2022 – Nov 17, 2022 Char and misc drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 habanalabs: added return value check for hl_fw_dynamic_send_clear_cmd()

The clang-analyzer reported a warning: "Value stored to 'rc' is never read".

The return value check for the first hl_fw_dynamic_send_clear_cmd() call in hl_fw_dynamic_send_protocol_cmd() appears to be missing.

---
 drivers/misc/habanalabs/common/firmware_if.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/misc/habanalabs/common/firmware_if.c +2 -0
index 2de6a9bd564d..311942108dbc 100644
@@ -1782,6 +1782,8 @@ int hl_fw_dynamic_send_protocol_cmd(struct hl_device *hdev,
 
 	/* first send clear command to clean former commands */
 	rc = hl_fw_dynamic_send_clear_cmd(hdev, fw_loader);
+	if (rc)
+		return rc;
 
 	/* send the actual command */
 	hl_fw_dynamic_send_cmd(hdev, fw_loader, cmd, size);
Signature · 1 line
2.38.1
#1 lore raw
Quoted 16 lines · Marco Pagani

The clang-analyzer reported a warning: "Value stored to 'rc' is never read".

The return value check for the first hl_fw_dynamic_send_clear_cmd() call in hl_fw_dynamic_send_protocol_cmd() appears to be missing.

---
 drivers/misc/habanalabs/common/firmware_if.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/misc/habanalabs/common/firmware_if.c +0 -0
index 2de6a9bd564d..311942108dbc 100644

drivers/misc/habanalabs/common/firmware_if.c int hl_fw_dynamic_send_protocol_cmd(struct hl_device *hdev, · line 1789

Quoted 8 lines
drivers/misc/habanalabs/common/firmware_if.c +2 -0
@@ -1782,6 +1782,8 @@ int hl_fw_dynamic_send_protocol_cmd(struct hl_device *hdev,
 
 	/* first send clear command to clean former commands */
 	rc = hl_fw_dynamic_send_clear_cmd(hdev, fw_loader);
+	if (rc)
+		return rc;
 
 	/* send the actual command */
 	hl_fw_dynamic_send_cmd(hdev, fw_loader, cmd, size);

Are you sure this is ok? If the first "clean the buffer" command fails, all should still be good as that wasn't the real command.

But maybe the hardware will never fail this?

thanks,

greg k-h

Reviewed-by
#2 lore raw
Quoted 30 lines · Greg Kroah-Hartman
Quoted 16 lines · Marco Pagani

The clang-analyzer reported a warning: "Value stored to 'rc' is never read".

The return value check for the first hl_fw_dynamic_send_clear_cmd() call in hl_fw_dynamic_send_protocol_cmd() appears to be missing.

---
 drivers/misc/habanalabs/common/firmware_if.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/misc/habanalabs/common/firmware_if.c +0 -0
index 2de6a9bd564d..311942108dbc 100644

drivers/misc/habanalabs/common/firmware_if.c int hl_fw_dynamic_send_protocol_cmd(struct hl_device *hdev, · line 1789

Quoted 8 lines
drivers/misc/habanalabs/common/firmware_if.c +2 -0
@@ -1782,6 +1782,8 @@ int hl_fw_dynamic_send_protocol_cmd(struct hl_device *hdev,
 
      /* first send clear command to clean former commands */
      rc = hl_fw_dynamic_send_clear_cmd(hdev, fw_loader);
+     if (rc)
+             return rc;
 
      /* send the actual command */
      hl_fw_dynamic_send_cmd(hdev, fw_loader, cmd, size);

Are you sure this is ok? If the first "clean the buffer" command fails, all should still be good as that wasn't the real command.

Quoted 5 lines

But maybe the hardware will never fail this?

thanks,

greg k-h

Actually it's a real mistake, it was overlooked when the code was written (although chances of failure in clear cmd are very small). I'll apply it to my tree.

Thanks,
Oded