diff mbox series

[v2,08/10] usb/bus: Remove dead assignment in usb_get_fw_dev_path()

Message ID 20200825112447.126308-9-kuhn.chenqun@huawei.com
State New
Headers show
Series trivial patchs for static code analyzer fixes | expand

Commit Message

Chen Qun Aug. 25, 2020, 11:24 a.m. UTC
Clang static code analyzer show warning:
qemu/hw/usb/bus.c:615:13: warning: Value stored to 'pos' is never read
            pos += snprintf(fw_path + pos, fw_len - pos, "%s@%lx",

Reported-by: Euler Robot <euler.robot@huawei.com>
Signed-off-by: Chen Qun <kuhn.chenqun@huawei.com>
---
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Markus Armbruster <armbru@redhat.com>
---
 hw/usb/bus.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Markus Armbruster Aug. 25, 2020, 2:39 p.m. UTC | #1
Chen Qun <kuhn.chenqun@huawei.com> writes:

> Clang static code analyzer show warning:
> qemu/hw/usb/bus.c:615:13: warning: Value stored to 'pos' is never read
>             pos += snprintf(fw_path + pos, fw_len - pos, "%s@%lx",
>
> Reported-by: Euler Robot <euler.robot@huawei.com>
> Signed-off-by: Chen Qun <kuhn.chenqun@huawei.com>
> ---
> Cc: Gerd Hoffmann <kraxel@redhat.com>
> Cc: Markus Armbruster <armbru@redhat.com>
> ---
>  hw/usb/bus.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/hw/usb/bus.c b/hw/usb/bus.c
> index b17bda3b29..7bab0499ad 100644
> --- a/hw/usb/bus.c
> +++ b/hw/usb/bus.c
> @@ -612,8 +612,8 @@ static char *usb_get_fw_dev_path(DeviceState *qdev)
           if (in[0] == '.') {
               /* some hub between root port and device */
               pos += snprintf(fw_path + pos, fw_len - pos, "hub@%lx/", nr);
>              in++;
>          } else {
>              /* the device itself */
> -            pos += snprintf(fw_path + pos, fw_len - pos, "%s@%lx",
> -                            qdev_fw_name(qdev), nr);
> +            snprintf(fw_path + pos, fw_len - pos, "%s@%lx", qdev_fw_name(qdev),
> +                     nr);
>              break;
>          }
>      }

I'd prefer to keep the line break where it is:

            snprintf(fw_path + pos, fw_len - pos, "%s@%lx",
                     qdev_fw_name(qdev), nr);

The patch is safe, so
Reviewed-by: Markus Armbruster <armbru@redhat.com>

The loss of symmetry betwen the two arms of the if is a bit sad.  Up to
Gerd.
Chen Qun Aug. 26, 2020, 1:59 a.m. UTC | #2
> >  hw/usb/bus.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/hw/usb/bus.c b/hw/usb/bus.c index b17bda3b29..7bab0499ad
> > 100644
> > --- a/hw/usb/bus.c
> > +++ b/hw/usb/bus.c
> > @@ -612,8 +612,8 @@ static char *usb_get_fw_dev_path(DeviceState
> > *qdev)
>            if (in[0] == '.') {
>                /* some hub between root port and device */
>                pos += snprintf(fw_path + pos, fw_len - pos, "hub@%lx/",
> nr);
> >              in++;
> >          } else {
> >              /* the device itself */
> > -            pos += snprintf(fw_path + pos, fw_len - pos, "%s@%lx",
> > -                            qdev_fw_name(qdev), nr);
> > +            snprintf(fw_path + pos, fw_len - pos, "%s@%lx",
> qdev_fw_name(qdev),
> > +                     nr);
> >              break;
> >          }
> >      }
> 
> I'd prefer to keep the line break where it is:
> 
>             snprintf(fw_path + pos, fw_len - pos, "%s@%lx",
>                      qdev_fw_name(qdev), nr);
> 
> The patch is safe, so
> Reviewed-by: Markus Armbruster <armbru@redhat.com>
> 
> The loss of symmetry betwen the two arms of the if is a bit sad.  Up to Gerd.

If symmetry looks better. I should change it later.

Thanks,
Chen Qun
Chen Qun Aug. 26, 2020, 2:25 a.m. UTC | #3
> > >  hw/usb/bus.c | 4 ++--
> > >  1 file changed, 2 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/hw/usb/bus.c b/hw/usb/bus.c index
> > > b17bda3b29..7bab0499ad
> > > 100644
> > > --- a/hw/usb/bus.c
> > > +++ b/hw/usb/bus.c
> > > @@ -612,8 +612,8 @@ static char *usb_get_fw_dev_path(DeviceState
> > > *qdev)
> >            if (in[0] == '.') {
> >                /* some hub between root port and device */
> >                pos += snprintf(fw_path + pos, fw_len - pos,
> > "hub@%lx/", nr);
> > >              in++;
> > >          } else {
> > >              /* the device itself */
> > > -            pos += snprintf(fw_path + pos, fw_len - pos, "%s@%lx",
> > > -                            qdev_fw_name(qdev), nr);
> > > +            snprintf(fw_path + pos, fw_len - pos, "%s@%lx",
> > qdev_fw_name(qdev),
> > > +                     nr);
> > >              break;
> > >          }
> > >      }
> >
> > I'd prefer to keep the line break where it is:
> >
> >             snprintf(fw_path + pos, fw_len - pos, "%s@%lx",
> >                      qdev_fw_name(qdev), nr);
> >
> > The patch is safe, so
> > Reviewed-by: Markus Armbruster <armbru@redhat.com>
> >
> > The loss of symmetry betwen the two arms of the if is a bit sad.  Up to Gerd.
> 
> If symmetry looks better. I should change it later.
Oops, I think I just misunderstood you. I agree with your suggestion to the formatting of the "snprintf(***)" statement.

If the 'pos' assignment is useless, we delete it avoid warning that are always detected by some tools.

Thanks,
Chen Qun
diff mbox series

Patch

diff --git a/hw/usb/bus.c b/hw/usb/bus.c
index b17bda3b29..7bab0499ad 100644
--- a/hw/usb/bus.c
+++ b/hw/usb/bus.c
@@ -612,8 +612,8 @@  static char *usb_get_fw_dev_path(DeviceState *qdev)
             in++;
         } else {
             /* the device itself */
-            pos += snprintf(fw_path + pos, fw_len - pos, "%s@%lx",
-                            qdev_fw_name(qdev), nr);
+            snprintf(fw_path + pos, fw_len - pos, "%s@%lx", qdev_fw_name(qdev),
+                     nr);
             break;
         }
     }