[stgt] isns.c: fix compiler warnings

FUJITA Tomonori fujita.tomonori at lab.ntt.co.jp
Wed Apr 4 21:23:28 CEST 2012


On Wed, 04 Apr 2012 02:32:45 +0900 (JST)
FUJITA Tomonori <fujita.tomonori at lab.ntt.co.jp> wrote:

> On Mon, 2 Apr 2012 21:58:52 +0200
> Arne Redlich <arne.redlich at googlemail.com> wrote:
> 
> > 2012/4/2 FUJITA Tomonori <fujita.tomonori at lab.ntt.co.jp>:
> >> On Sat, 31 Mar 2012 23:56:00 +0200
> >> Arne Redlich <arne.redlich at googlemail.com> wrote:
> >>
> >>> The get_hdr_param macro is used exuberantly, leading to variables
> >>> that are defined and set but never actually used, as pointed out by
> >>> gcc-4.6.
> >>>
> >>> Signed-off-by: Arne Redlich <arne.redlich at googlemail.com>
> >>> ---
> >>>
> >>> Tomo, list,
> >>>
> >>> This patch is a rather mechanic translation from IET's isns code, and merely compile tested.
> >>>
> >>> Cheers,
> >>> Arne
> >>>
> >>>  usr/iscsi/isns.c |   20 ++++++++------------
> >>>  1 files changed, 8 insertions(+), 12 deletions(-)
> >>>
> >>>
> >>> diff --git a/usr/iscsi/isns.c b/usr/iscsi/isns.c
> >>> index 1f1852c..452c7af 100644
> >>> --- a/usr/iscsi/isns.c
> >>> +++ b/usr/iscsi/isns.c
> >>> @@ -638,12 +638,10 @@ static int recv_pdu(int fd, struct isns_io *rx, struct isns_hdr *hdr)
> >>>  static char *print_scn_pdu(struct isns_hdr *hdr)
> >>>  {
> >>>       struct isns_tlv *tlv = (struct isns_tlv *) hdr->pdu;
> >>> -     uint16_t function, length, flags, transaction, sequence;
> >>> +     uint16_t length = ntohs(hdr->length);
> >>>       char *name = NULL;
> >>>       static char iscsi_name[224];
> >>>
> >>> -     get_hdr_param(hdr, function, length, flags, transaction, sequence);
> >>
> >> I think that the point of get_hdr_param is putting how to get extract
> >> values from a header into one place. That is, I like to avoid putting
> >> ntohs everywhere.
> >>
> >> I guess we had better to drop -Wall?
> > 
> > I don't think this is a good idea for any project as -Wall (and
> > various other "-W"s) has (have) proven to be quite invaluable to me.
> 
> I would agree in general but I'm not sure "-Wunused-but-set-variable"
> warning is useful.
> 
> > If you think abstractions are useful there (I'm not convinced, as it's
> > all internal to isns.c), how about getters per header field?
> 
> Ok, just put dprintf in get_hdr_param macro.

I've applied the following simple patch:

From f38c30a9b9fcdc16ec0234c9a75fb0b40b797921 Mon Sep 17 00:00:00 2001
From: FUJITA Tomonori <fujita.tomonori at lab.ntt.co.jp>
Date: Thu, 5 Apr 2012 04:18:10 +0900
Subject: [PATCH] iscsi: silence gcc 4.6 unused-but-set-variable warnings in isns.c

Signed-off-by: FUJITA Tomonori <fujita.tomonori at lab.ntt.co.jp>
---
 usr/iscsi/isns.c |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/usr/iscsi/isns.c b/usr/iscsi/isns.c
index 1f1852c..78ba13e 100644
--- a/usr/iscsi/isns.c
+++ b/usr/iscsi/isns.c
@@ -578,6 +578,8 @@ static int recv_hdr(int fd, struct isns_io *rx, struct isns_hdr *hdr)
 	flags = ntohs(hdr->flags);						\
 	transaction = ntohs(hdr->transaction);					\
 	sequence = ntohs(hdr->sequence);					\
+	dprintf("got a header %x %u %x %u %u\n", function, length, flags,	\
+		transaction, sequence);						\
 }
 
 static int recv_pdu(int fd, struct isns_io *rx, struct isns_hdr *hdr)
@@ -591,8 +593,6 @@ static int recv_pdu(int fd, struct isns_io *rx, struct isns_hdr *hdr)
 
 	/* Now we got a complete header */
 	get_hdr_param(hdr, function, length, flags, transaction, sequence);
-	dprintf("got a header %x %u %x %u %u\n", function, length, flags,
-		transaction, sequence);
 
 	if (length + sizeof(*hdr) > BUFSIZE) {
 		eprintf("FIXME we cannot handle this yet %u!\n", length);
@@ -774,7 +774,6 @@ static void isns_handle(int fd, int events, void *data)
 	int err;
 	struct isns_io *rx = &isns_rx;
 	struct isns_hdr *hdr = (struct isns_hdr *) rx->buf;
-	uint32_t result;
 	uint16_t function, length, flags, transaction, sequence;
 	char *name = NULL;
 
@@ -790,7 +789,6 @@ static void isns_handle(int fd, int events, void *data)
 	}
 
 	get_hdr_param(hdr, function, length, flags, transaction, sequence);
-	result = ntohl((uint32_t) hdr->pdu[0]);
 
 	switch (function) {
 	case ISNS_FUNC_DEV_ATTR_REG_RSP:
-- 
1.7.2.5



More information about the stgt mailing list