diff mbox

scsi: lpfc: avoid false-positive gcc-8 warning

Message ID 20170823150143.2746796-1-arnd@arndb.de
State New
Headers show

Commit Message

Arnd Bergmann Aug. 23, 2017, 3:01 p.m. UTC
This is an interesting regression with gcc-8, showing a harmless
warning for correct code:

In file included from include/linux/kernel.h:13:0,
                 ...
                 from drivers/scsi/lpfc/lpfc_debugfs.c:23:
include/linux/printk.h:301:2: error: 'eq' may be used uninitialized in this function [-Werror=maybe-uninitialized]
  printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
  ^~~~~~
In file included from drivers/scsi/lpfc/lpfc_debugfs.c:58:0:
drivers/scsi/lpfc/lpfc_debugfs.h:451:31: note: 'eq' was declared here

I tried to come up with a reduced test case for gcc here
a few times, but every time ended up with code that is actually
wrong with older gcc versions missing the bug and gcc-8 finding
it. As this is the only false-positive -Wmaybe-uninitialized
warnign I got with gcc-8 randconfig builds, I'd suggest we
work around it.

Making the index variable 'unsigned' is enough to shut up
the warning, as gcc can then see that comparing eqidx to
phba->io_channel_irqs is fine here.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>

---
 drivers/scsi/lpfc/lpfc_debugfs.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

-- 
2.9.0

Comments

James Smart Aug. 23, 2017, 4:20 p.m. UTC | #1
On 8/23/2017 8:01 AM, Arnd Bergmann wrote:
> This is an interesting regression with gcc-8, showing a harmless

> warning for correct code:

>

> In file included from include/linux/kernel.h:13:0,

>                   ...

>                   from drivers/scsi/lpfc/lpfc_debugfs.c:23:

> include/linux/printk.h:301:2: error: 'eq' may be used uninitialized in this function [-Werror=maybe-uninitialized]

>    printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)

>    ^~~~~~

> In file included from drivers/scsi/lpfc/lpfc_debugfs.c:58:0:

> drivers/scsi/lpfc/lpfc_debugfs.h:451:31: note: 'eq' was declared here

>

> I tried to come up with a reduced test case for gcc here

> a few times, but every time ended up with code that is actually

> wrong with older gcc versions missing the bug and gcc-8 finding

> it. As this is the only false-positive -Wmaybe-uninitialized

> warnign I got with gcc-8 randconfig builds, I'd suggest we

> work around it.

>

> Making the index variable 'unsigned' is enough to shut up

> the warning, as gcc can then see that comparing eqidx to

> phba->io_channel_irqs is fine here.

>

> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

> ---

>   drivers/scsi/lpfc/lpfc_debugfs.h | 2 +-

>   1 file changed, 1 insertion(+), 1 deletion(-)

>

>

looks good. Thanks

Signed-off-by: James Smart <james.smart@broadcom.com>


-- james
diff mbox

Patch

diff --git a/drivers/scsi/lpfc/lpfc_debugfs.h b/drivers/scsi/lpfc/lpfc_debugfs.h
index 7b7d314af0e0..7b7f53a37fd8 100644
--- a/drivers/scsi/lpfc/lpfc_debugfs.h
+++ b/drivers/scsi/lpfc/lpfc_debugfs.h
@@ -450,7 +450,7 @@  lpfc_debug_dump_cq(struct lpfc_hba *phba, int qtype, int wqidx)
 {
 	struct lpfc_queue *wq, *cq, *eq;
 	char *qtypestr;
-	int eqidx;
+	unsigned int eqidx;
 
 	/* fcp/nvme wq and cq are 1:1, thus same indexes */