scsi: pm8001: Avoid -Wrestrict warning
authorArnd Bergmann <arnd@arndb.de>
Tue, 23 Mar 2021 12:54:23 +0000 (13:54 +0100)
committerMartin K. Petersen <martin.petersen@oracle.com>
Thu, 25 Mar 2021 03:16:14 +0000 (23:16 -0400)
commitc2255ece2be2454dff0b549e2ceb234bfe798181
tree04e70bf0a3b9a04435ef8288036a245d179e0448
parentf1891f9bbc46f83099cbd0911b81b7225258ac03
scsi: pm8001: Avoid -Wrestrict warning

On some configurations, gcc warns about overlapping source and destination
arguments to snprintf:

drivers/scsi/pm8001/pm8001_init.c: In function 'pm8001_request_msix':
drivers/scsi/pm8001/pm8001_init.c:977:3: error: 'snprintf' argument 4 may overlap destination object 'pm8001_ha' [-Werror=restrict]
  977 |   snprintf(drvname, len, "%s-%d", pm8001_ha->name, i);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/scsi/pm8001/pm8001_init.c:962:56: note: destination object referenced by 'restrict'-qualified argument 1 was declared here
  962 | static u32 pm8001_request_msix(struct pm8001_hba_info *pm8001_ha)
      |                                ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~

I first assumed this was a gcc bug, as that should not happen, but a
reduced test case makes it clear that this happens when the loop counter is
not bounded by the array size.

Help the compiler out by adding an explicit limit here to make the code
slightly more robust and avoid the warning.

Link: https://godbolt.org/z/6T1qPM
Link: https://lore.kernel.org/r/20210323125458.1825564-1-arnd@kernel.org
Acked-by: Jack Wang <jinpu.wang@ionos.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/pm8001/pm8001_init.c