habanalabs: added return value check for hl_fw_dynamic_send_clear_cmd()

Message ID 20221116134126.199087-1-marpagan@redhat.com
State New
Headers
Series habanalabs: added return value check for hl_fw_dynamic_send_clear_cmd() |

Commit Message

Marco Pagani Nov. 16, 2022, 1:41 p.m. UTC
  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.

Signed-off-by: Marco Pagani <marpagan@redhat.com>
---
 drivers/misc/habanalabs/common/firmware_if.c | 2 ++
 1 file changed, 2 insertions(+)
  

Comments

Greg KH Nov. 16, 2022, 3:17 p.m. UTC | #1
On Wed, Nov 16, 2022 at 02:41:25PM +0100, Marco Pagani wrote:
> 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.
> 
> Signed-off-by: Marco Pagani <marpagan@redhat.com>
> ---
>  drivers/misc/habanalabs/common/firmware_if.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/misc/habanalabs/common/firmware_if.c b/drivers/misc/habanalabs/common/firmware_if.c
> index 2de6a9bd564d..311942108dbc 100644
> --- a/drivers/misc/habanalabs/common/firmware_if.c
> +++ b/drivers/misc/habanalabs/common/firmware_if.c
> @@ -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
  
Oded Gabbay Nov. 17, 2022, 8:45 a.m. UTC | #2
On Wed, Nov 16, 2022 at 5:17 PM Greg Kroah-Hartman
<gregkh@linuxfoundation.org> wrote:
>
> On Wed, Nov 16, 2022 at 02:41:25PM +0100, Marco Pagani wrote:
> > 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.
> >
> > Signed-off-by: Marco Pagani <marpagan@redhat.com>
> > ---
> >  drivers/misc/habanalabs/common/firmware_if.c | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/drivers/misc/habanalabs/common/firmware_if.c b/drivers/misc/habanalabs/common/firmware_if.c
> > index 2de6a9bd564d..311942108dbc 100644
> > --- a/drivers/misc/habanalabs/common/firmware_if.c
> > +++ b/drivers/misc/habanalabs/common/firmware_if.c
> > @@ -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

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.
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Thanks,
Oded
  

Patch

diff --git a/drivers/misc/habanalabs/common/firmware_if.c b/drivers/misc/habanalabs/common/firmware_if.c
index 2de6a9bd564d..311942108dbc 100644
--- a/drivers/misc/habanalabs/common/firmware_if.c
+++ b/drivers/misc/habanalabs/common/firmware_if.c
@@ -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);