Message ID | 20200321114615.5360-8-philmd@redhat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | misc: Trivial static code analyzer fixes | expand |
On Sat, 21 Mar 2020, Philippe Mathieu-Daudé wrote: > Fix warning reported by Clang static code analyzer: > > hw/gpio/aspeed_gpio.c:717:18: warning: Value stored to 'g_idx' during its initialization is never read > int set_idx, g_idx = *group_idx; > ^~~~~ ~~~~~~~~~~ > > Reported-by: Clang Static Analyzer > Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> > --- > hw/gpio/aspeed_gpio.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/hw/gpio/aspeed_gpio.c b/hw/gpio/aspeed_gpio.c > index 41e11ea9b0..cc07ab9866 100644 > --- a/hw/gpio/aspeed_gpio.c > +++ b/hw/gpio/aspeed_gpio.c > @@ -714,11 +714,11 @@ static void aspeed_gpio_write(void *opaque, hwaddr offset, uint64_t data, > static int get_set_idx(AspeedGPIOState *s, const char *group, int *group_idx) > { > AspeedGPIOClass *agc = ASPEED_GPIO_GET_CLASS(s); > - int set_idx, g_idx = *group_idx; > + int set_idx; > > for (set_idx = 0; set_idx < agc->nr_gpio_sets; set_idx++) { > const GPIOSetProperties *set_props = &agc->props[set_idx]; > - for (g_idx = 0; g_idx < ASPEED_GROUPS_PER_SET; g_idx++) { > + for (int g_idx = 0; g_idx < ASPEED_GROUPS_PER_SET; g_idx++) { Is declaring variables here allowed by coding style? Shouldn't you only remove init value from above? Regards, BALATON Zoltan > if (!strncmp(group, set_props->group_label[g_idx], strlen(group))) { > *group_idx = g_idx; > return set_idx; >
On 3/21/20 2:22 PM, BALATON Zoltan wrote: > On Sat, 21 Mar 2020, Philippe Mathieu-Daudé wrote: >> Fix warning reported by Clang static code analyzer: >> >> hw/gpio/aspeed_gpio.c:717:18: warning: Value stored to 'g_idx' during >> its initialization is never read >> int set_idx, g_idx = *group_idx; >> ^~~~~ ~~~~~~~~~~ >> >> Reported-by: Clang Static Analyzer >> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> >> --- >> hw/gpio/aspeed_gpio.c | 4 ++-- >> 1 file changed, 2 insertions(+), 2 deletions(-) >> >> diff --git a/hw/gpio/aspeed_gpio.c b/hw/gpio/aspeed_gpio.c >> index 41e11ea9b0..cc07ab9866 100644 >> --- a/hw/gpio/aspeed_gpio.c >> +++ b/hw/gpio/aspeed_gpio.c >> @@ -714,11 +714,11 @@ static void aspeed_gpio_write(void *opaque, >> hwaddr offset, uint64_t data, >> static int get_set_idx(AspeedGPIOState *s, const char *group, int >> *group_idx) >> { >> AspeedGPIOClass *agc = ASPEED_GPIO_GET_CLASS(s); >> - int set_idx, g_idx = *group_idx; >> + int set_idx; >> >> for (set_idx = 0; set_idx < agc->nr_gpio_sets; set_idx++) { >> const GPIOSetProperties *set_props = &agc->props[set_idx]; >> - for (g_idx = 0; g_idx < ASPEED_GROUPS_PER_SET; g_idx++) { >> + for (int g_idx = 0; g_idx < ASPEED_GROUPS_PER_SET; g_idx++) { > > Is declaring variables here allowed by coding style? Shouldn't you only > remove init value from above? You are right, it is not (yet?) allowed by QEMU coding style. > > Regards, > BALATON Zoltan > >> if (!strncmp(group, set_props->group_label[g_idx], >> strlen(group))) { >> *group_idx = g_idx; >> return set_idx; >>
diff --git a/hw/gpio/aspeed_gpio.c b/hw/gpio/aspeed_gpio.c index 41e11ea9b0..cc07ab9866 100644 --- a/hw/gpio/aspeed_gpio.c +++ b/hw/gpio/aspeed_gpio.c @@ -714,11 +714,11 @@ static void aspeed_gpio_write(void *opaque, hwaddr offset, uint64_t data, static int get_set_idx(AspeedGPIOState *s, const char *group, int *group_idx) { AspeedGPIOClass *agc = ASPEED_GPIO_GET_CLASS(s); - int set_idx, g_idx = *group_idx; + int set_idx; for (set_idx = 0; set_idx < agc->nr_gpio_sets; set_idx++) { const GPIOSetProperties *set_props = &agc->props[set_idx]; - for (g_idx = 0; g_idx < ASPEED_GROUPS_PER_SET; g_idx++) { + for (int g_idx = 0; g_idx < ASPEED_GROUPS_PER_SET; g_idx++) { if (!strncmp(group, set_props->group_label[g_idx], strlen(group))) { *group_idx = g_idx; return set_idx;
Fix warning reported by Clang static code analyzer: hw/gpio/aspeed_gpio.c:717:18: warning: Value stored to 'g_idx' during its initialization is never read int set_idx, g_idx = *group_idx; ^~~~~ ~~~~~~~~~~ Reported-by: Clang Static Analyzer Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> --- hw/gpio/aspeed_gpio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)