linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] scsi: nsp32: add __printf attribute to logging functions
@ 2017-05-20 11:16 Nicolas Iooss
  2017-05-20 11:16 ` [PATCH 2/2] pcmcia: nsp_cs: " Nicolas Iooss
  2017-05-20 11:35 ` [PATCH 1/2] scsi: nsp32: " Joe Perches
  0 siblings, 2 replies; 4+ messages in thread
From: Nicolas Iooss @ 2017-05-20 11:16 UTC (permalink / raw)
  To: GOTO Masanori, YOKOTA Hiroshi
  Cc: James E.J. Bottomley, Martin K. Petersen, linux-scsi,
	linux-kernel, Nicolas Iooss

nsp32_message() and nsp32_dmessage() use printf format strings in order
to format a message. Adding __printf attributes helps to detect errors
in such format strings at build time, like:

    drivers/scsi/nsp32.c:3314:23: error: format '%ld' expects argument
    of type 'long int', but argument 6 has type 'pm_message_t {aka
    struct pm_message}' [-Werror=format=]
      nsp32_msg(KERN_INFO,
      "pci-suspend: pdev=0x%p, state=%ld, slot=%s, host=0x%p",
      pdev, state, pci_name(pdev), host);

Fix all format string errors which were reported by gcc.

Signed-off-by: Nicolas Iooss <nicolas.iooss_linux@m4x.org>
---
 drivers/scsi/nsp32.c | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/drivers/scsi/nsp32.c b/drivers/scsi/nsp32.c
index 53c84771f0e8..0689b0564fbf 100644
--- a/drivers/scsi/nsp32.c
+++ b/drivers/scsi/nsp32.c
@@ -257,9 +257,11 @@ static        void nsp32_prom_set      (nsp32_hw_data *, int, int);
 static        int  nsp32_prom_get      (nsp32_hw_data *, int);
 
 /* debug/warning/info message */
-static void nsp32_message (const char *, int, char *, char *, ...);
+static __printf(4, 5)
+void nsp32_message (const char *, int, char *, const char *, ...);
 #ifdef NSP32_DEBUG
-static void nsp32_dmessage(const char *, int, int,    char *, ...);
+static __printf(4, 5)
+void nsp32_dmessage(const char *, int, int,    const char *, ...);
 #endif
 
 /*
@@ -321,7 +323,8 @@ static struct scsi_host_template nsp32_template = {
 
 #define NSP32_DEBUG_BUF_LEN		100
 
-static void nsp32_message(const char *func, int line, char *type, char *fmt, ...)
+static __printf(4, 5)
+void nsp32_message(const char *func, int line, char *type, const char *fmt, ...)
 {
 	va_list args;
 	char buf[NSP32_DEBUG_BUF_LEN];
@@ -338,7 +341,8 @@ static void nsp32_message(const char *func, int line, char *type, char *fmt, ...
 }
 
 #ifdef NSP32_DEBUG
-static void nsp32_dmessage(const char *func, int line, int mask, char *fmt, ...)
+static __printf(4, 5)
+void nsp32_dmessage(const char *func, int line, int mask, const char *fmt, ...)
 {
 	va_list args;
 	char buf[NSP32_DEBUG_BUF_LEN];
@@ -697,7 +701,7 @@ static int nsp32_selection_autoscsi(struct scsi_cmnd *SCpnt)
 	nsp32_write1(base, ACK_WIDTH, data->cur_target->ackwidth);
 
 	nsp32_dbg(NSP32_DEBUG_AUTOSCSI,
-		  "syncreg=0x%x, ackwidth=0x%x, sgtpaddr=0x%x, id=0x%x",
+		  "syncreg=0x%x, ackwidth=0x%x, sgtpaddr=0x%lx, id=0x%x",
 		  nsp32_read1(base, SYNC_REG), nsp32_read1(base, ACK_WIDTH),
 		  nsp32_read4(base, SGT_ADR), nsp32_read1(base, SCSI_OUT_LATCH_TARGET_ID));
 	nsp32_dbg(NSP32_DEBUG_AUTOSCSI, "msgout_len=%d, msgout=0x%x",
@@ -888,11 +892,11 @@ static int nsp32_setup_sg_table(struct scsi_cmnd *SCpnt)
 
 			if (le32_to_cpu(sgt[i].len) > 0x10000) {
 				nsp32_msg(KERN_ERR,
-					"can't transfer over 64KB at a time, size=0x%lx", le32_to_cpu(sgt[i].len));
+					"can't transfer over 64KB at a time, size=0x%x", le32_to_cpu(sgt[i].len));
 				return FALSE;
 			}
 			nsp32_dbg(NSP32_DEBUG_SGLIST,
-				  "num 0x%x : addr 0x%lx len 0x%lx",
+				  "num 0x%x : addr 0x%x len 0x%x",
 				  i,
 				  le32_to_cpu(sgt[i].addr),
 				  le32_to_cpu(sgt[i].len ));
@@ -915,7 +919,7 @@ static int nsp32_queuecommand_lck(struct scsi_cmnd *SCpnt, void (*done)(struct s
 
 	nsp32_dbg(NSP32_DEBUG_QUEUECOMMAND,
 		  "enter. target: 0x%x LUN: 0x%llx cmnd: 0x%x cmndlen: 0x%x "
-		  "use_sg: 0x%x reqbuf: 0x%lx reqlen: 0x%x",
+		  "use_sg: 0x%x reqbuf: %p reqlen: 0x%x",
 		  SCpnt->device->id, SCpnt->device->lun, SCpnt->cmnd[0], SCpnt->cmd_len,
 		  scsi_sg_count(SCpnt), scsi_sglist(SCpnt), scsi_bufflen(SCpnt));
 
@@ -2742,7 +2746,7 @@ static int nsp32_detect(struct pci_dev *pdev)
 	res = request_region(host->io_port, host->n_io_port, "nsp32");
 	if (res == NULL) {
 		nsp32_msg(KERN_ERR, 
-			  "I/O region 0x%lx+0x%lx is already used",
+			  "I/O region 0x%x+0x%x is already used",
 			  data->BaseAddress, data->NumAddress);
 		goto free_irq;
         }
@@ -2853,7 +2857,7 @@ static int nsp32_eh_bus_reset(struct scsi_cmnd *SCpnt)
 	spin_lock_irq(SCpnt->device->host->host_lock);
 
 	nsp32_msg(KERN_INFO, "Bus Reset");	
-	nsp32_dbg(NSP32_DEBUG_BUSRESET, "SCpnt=0x%x", SCpnt);
+	nsp32_dbg(NSP32_DEBUG_BUSRESET, "SCpnt=%p", SCpnt);
 
 	nsp32_write2(base, IRQ_CONTROL, IRQ_CONTROL_ALL_IRQ_MASK);
 	nsp32_do_bus_reset(data);
@@ -2912,7 +2916,7 @@ static int nsp32_eh_host_reset(struct scsi_cmnd *SCpnt)
 	nsp32_hw_data    *data = (nsp32_hw_data *)host->hostdata;
 
 	nsp32_msg(KERN_INFO, "Host Reset");	
-	nsp32_dbg(NSP32_DEBUG_BUSRESET, "SCpnt=0x%x", SCpnt);
+	nsp32_dbg(NSP32_DEBUG_BUSRESET, "SCpnt=%p", SCpnt);
 
 	spin_lock_irq(SCpnt->device->host->host_lock);
 
@@ -3307,7 +3311,7 @@ static int nsp32_suspend(struct pci_dev *pdev, pm_message_t state)
 {
 	struct Scsi_Host *host = pci_get_drvdata(pdev);
 
-	nsp32_msg(KERN_INFO, "pci-suspend: pdev=0x%p, state=%ld, slot=%s, host=0x%p", pdev, state, pci_name(pdev), host);
+	nsp32_msg(KERN_INFO, "pci-suspend: pdev=0x%p, state=%d, slot=%s, host=0x%p", pdev, state.event, pci_name(pdev), host);
 
 	pci_save_state     (pdev);
 	pci_disable_device (pdev);
-- 
2.12.2

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] pcmcia: nsp_cs: add __printf attribute to logging functions
  2017-05-20 11:16 [PATCH 1/2] scsi: nsp32: add __printf attribute to logging functions Nicolas Iooss
@ 2017-05-20 11:16 ` Nicolas Iooss
  2017-05-20 11:35 ` [PATCH 1/2] scsi: nsp32: " Joe Perches
  1 sibling, 0 replies; 4+ messages in thread
From: Nicolas Iooss @ 2017-05-20 11:16 UTC (permalink / raw)
  To: GOTO Masanori, YOKOTA Hiroshi
  Cc: James E.J. Bottomley, Martin K. Petersen, linux-scsi,
	linux-kernel, Nicolas Iooss

Adding __printf attributes helps to detect errors in printf format
strings at build time.

Signed-off-by: Nicolas Iooss <nicolas.iooss_linux@m4x.org>
---
 drivers/scsi/pcmcia/nsp_cs.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/pcmcia/nsp_cs.c b/drivers/scsi/pcmcia/nsp_cs.c
index 5fb6eefc6541..33b982be9763 100644
--- a/drivers/scsi/pcmcia/nsp_cs.c
+++ b/drivers/scsi/pcmcia/nsp_cs.c
@@ -136,7 +136,8 @@ static inline void nsp_inc_resid(struct scsi_cmnd *SCpnt, int residInc)
 	scsi_set_resid(SCpnt, scsi_get_resid(SCpnt) + residInc);
 }
 
-static void nsp_cs_message(const char *func, int line, char *type, char *fmt, ...)
+static __printf(4, 5)
+void nsp_cs_message(const char *func, int line, char *type, const char *fmt, ...)
 {
 	va_list args;
 	char buf[NSP_DEBUG_BUF_LEN];
@@ -153,7 +154,8 @@ static void nsp_cs_message(const char *func, int line, char *type, char *fmt, ..
 }
 
 #ifdef NSP_DEBUG
-static void nsp_cs_dmessage(const char *func, int line, int mask, char *fmt, ...)
+static __printf(4, 5)
+void nsp_cs_dmessage(const char *func, int line, int mask, const char *fmt, ...)
 {
 	va_list args;
 	char buf[NSP_DEBUG_BUF_LEN];
-- 
2.12.2

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] scsi: nsp32: add __printf attribute to logging functions
  2017-05-20 11:16 [PATCH 1/2] scsi: nsp32: add __printf attribute to logging functions Nicolas Iooss
  2017-05-20 11:16 ` [PATCH 2/2] pcmcia: nsp_cs: " Nicolas Iooss
@ 2017-05-20 11:35 ` Joe Perches
  2017-05-24  2:02   ` Martin K. Petersen
  1 sibling, 1 reply; 4+ messages in thread
From: Joe Perches @ 2017-05-20 11:35 UTC (permalink / raw)
  To: Nicolas Iooss, GOTO Masanori, YOKOTA Hiroshi
  Cc: James E.J. Bottomley, Martin K. Petersen, linux-scsi, linux-kernel

On Sat, 2017-05-20 at 13:16 +0200, Nicolas Iooss wrote:
> nsp32_message() and nsp32_dmessage() use printf format strings in order
> to format a message. Adding __printf attributes helps to detect errors
> in such format strings at build time, like:
> 
>     drivers/scsi/nsp32.c:3314:23: error: format '%ld' expects argument
>     of type 'long int', but argument 6 has type 'pm_message_t {aka
>     struct pm_message}' [-Werror=format=]
>       nsp32_msg(KERN_INFO,
>       "pci-suspend: pdev=0x%p, state=%ld, slot=%s, host=0x%p",
>       pdev, state, pci_name(pdev), host);
> 
> Fix all format string errors which were reported by gcc.
[]
> diff --git a/drivers/scsi/nsp32.c b/drivers/scsi/nsp32.c
[]
> @@ -321,7 +323,8 @@ static struct scsi_host_template nsp32_template = {
>  
>  #define NSP32_DEBUG_BUF_LEN		100
>  
> -static void nsp32_message(const char *func, int line, char *type, char *fmt, ...)
> +static __printf(4, 5)
> +void nsp32_message(const char *func, int line, char *type, const char *fmt, ...)
>  {
>  	va_list args;
>  	char buf[NSP32_DEBUG_BUF_LEN];

These could also use vsprintf extension %pV instead of
vsnprintf to a
temporary buffer and then using "%s, <tmp>"

etc...

Does anyone actually have or use these cards any longer?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] scsi: nsp32: add __printf attribute to logging functions
  2017-05-20 11:35 ` [PATCH 1/2] scsi: nsp32: " Joe Perches
@ 2017-05-24  2:02   ` Martin K. Petersen
  0 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2017-05-24  2:02 UTC (permalink / raw)
  To: Joe Perches
  Cc: Nicolas Iooss, GOTO Masanori, YOKOTA Hiroshi,
	James E.J. Bottomley, Martin K. Petersen, linux-scsi,
	linux-kernel


Joe,

> On Sat, 2017-05-20 at 13:16 +0200, Nicolas Iooss wrote:
>> nsp32_message() and nsp32_dmessage() use printf format strings in order
>> to format a message. Adding __printf attributes helps to detect errors
>> in such format strings at build time, like:

> Does anyone actually have or use these cards any longer?

I doubt it.

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-05-24  2:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-20 11:16 [PATCH 1/2] scsi: nsp32: add __printf attribute to logging functions Nicolas Iooss
2017-05-20 11:16 ` [PATCH 2/2] pcmcia: nsp_cs: " Nicolas Iooss
2017-05-20 11:35 ` [PATCH 1/2] scsi: nsp32: " Joe Perches
2017-05-24  2:02   ` Martin K. Petersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).