Adding -Wextra reveals sign-comparison warnings. Resolve
them.

Signed-off-by: Mark Rustad <[email protected]>
---
 fcoeadm_display.c |    9 +++++----
 fcoemon.c         |   34 +++++++++++++++++++---------------
 fcping.c          |    6 +++---
 fipvlan.c         |    2 +-
 lib/fcoe_utils.c  |    3 ++-
 lib/fip.c         |   10 ++++++----
 lib/rtnetlink.c   |   10 ++++++----
 lib/sa_sys.c      |    6 +++---
 8 files changed, 45 insertions(+), 35 deletions(-)

diff --git a/fcoeadm_display.c b/fcoeadm_display.c
index 215c19e..0b8be4a 100644
--- a/fcoeadm_display.c
+++ b/fcoeadm_display.c
@@ -128,7 +128,7 @@ sa_enum_decode_speed(char *buf, size_t buflen,
                     u_int32_t val)
 {
        char *prefix = "";
-       ssize_t len = 0;
+       size_t len;
        struct sa_nameval *tp = port_speeds;
        char *cp = buf;
 
@@ -136,7 +136,7 @@ sa_enum_decode_speed(char *buf, size_t buflen,
        for (; tp->nv_name != NULL; tp++) {
                if (tp->nv_val & val) {
                        len = snprintf(cp, buflen, "%s%s", prefix, tp->nv_name);
-                       if (len <= 0 || len >= buflen)
+                       if (len == 0 || len >= buflen)
                                break;
                        cp += len;
                        buflen -= len;
@@ -733,7 +733,7 @@ show_full_lun_info(UNUSED HBA_HANDLE hba_handle,
               lp_info->PortFcId);
        printf("        Target FCID:        0x%06X\n",
               rp_info->PortFcId);
-       if (tgt_id == -1)
+       if (tgt_id == 0xFFFFFFFFU)
                printf("        Target ID:          (None)\n");
        else
                printf("        Target ID:          %u\n", tgt_id);
@@ -1310,7 +1310,8 @@ enum fcoe_status display_target_info(const char *ifname,
        HBA_STATUS retval;
        HBA_PORTATTRIBUTES rport_attrs;
        struct hba_name_table_list *hba_table_list = NULL;
-       int i, target_index, num_hbas = 0;
+       int i, num_hbas = 0;
+       unsigned int target_index;
        enum fcoe_status rc = SUCCESS;
        HBA_HANDLE hba_handle;
        HBA_PORTATTRIBUTES *port_attrs;
diff --git a/fcoemon.c b/fcoemon.c
index eeb2903..babba56 100644
--- a/fcoemon.c
+++ b/fcoemon.c
@@ -747,7 +747,7 @@ static void fcm_fc_event_handler(struct fc_nl_event 
*fc_event)
        }
 }
 
-static void log_nlmsg_error(struct nlmsghdr *hp, int rlen, const char *str)
+static void log_nlmsg_error(struct nlmsghdr *hp, size_t rlen, const char *str)
 {
        struct nlmsgerr *ep;
 
@@ -795,7 +795,7 @@ static void fcm_fc_event_log(struct fc_nl_event *fe)
                { FCH_EVT_LINK_UNKNOWN,         "link_unknown" },
                { FCH_EVT_VENDOR_UNIQUE,        "vendor_unique" },
        };
-       int i;
+       unsigned int i;
 
        for (i = 0; i < ARRAY_SIZE(fc_host_event_code_names); i++) {
                if (fe->event_code == fc_host_event_code_names[i].value) {
@@ -816,8 +816,9 @@ static void fcm_fc_event_recv(UNUSED void *arg)
 {
        struct nlmsghdr *hp;
        struct fc_nl_event *fc_event;
-       int plen;
-       int rlen;
+       size_t plen;
+       int rc;
+       size_t rlen;
        char *buf;
 
        buf = malloc(DEF_RX_BUF_SIZE);
@@ -827,16 +828,17 @@ static void fcm_fc_event_recv(UNUSED void *arg)
                return;
        }
 
-       rlen = read(fcm_fc_socket, buf, DEF_RX_BUF_SIZE);
-       if (!rlen)
+       rc = read(fcm_fc_socket, buf, DEF_RX_BUF_SIZE);
+       if (!rc)
                goto free_buf;
 
-       if (rlen < 0) {
+       if (rc < 0) {
                FCM_LOG_ERR(errno, "fc read error");
                goto free_buf;
        }
 
        hp = (struct nlmsghdr *)buf;
+       rlen = rc;
        for (hp = (struct nlmsghdr *)buf; NLMSG_OK(hp, rlen);
             hp = NLMSG_NEXT(hp, rlen)) {
 
@@ -1843,8 +1845,8 @@ static void fcm_link_recv(UNUSED void *arg)
        struct nlmsghdr *hp;
        struct ifinfomsg *ip;
        unsigned type;
-       int plen;
-       int rlen;
+       size_t plen;
+       size_t rlen;
 
        buf = fcm_link_buf;
        rc = read(fcm_link_socket, buf, fcm_link_buf_size);
@@ -2208,7 +2210,7 @@ static void fcm_dcbd_rx(void *arg)
        rc = read(clif->cl_fd, buf, sizeof(buf) - 1);
        if (rc < 0)
                FCM_LOG_ERR(errno, "read");
-       else if ((rc > 0) && (rc < sizeof(buf))) {
+       else if (rc > 0 && rc < (int)sizeof(buf)) {
                buf[rc] = '\0';
                len = strlen(buf);
                ASSERT(len <= rc);
@@ -3469,6 +3471,7 @@ static void fcm_srv_receive(void *arg)
        char ifname[sizeof(data->ifname) + 1];
        enum fcoe_status rc = EFAIL;
        int res, cmd, snum;
+       size_t size;
 
        snum = srv_info->srv_sock;
        res = recvfrom(snum, buf, sizeof(buf) - 1,
@@ -3480,15 +3483,16 @@ static void fcm_srv_receive(void *arg)
        }
 
        data = (struct clif_data *)buf;
-       if (res < sizeof(*data)) {
-               if (res < sizeof(*data) - sizeof(data->flags)) {
+       size = res;
+       if (size < sizeof(*data)) {
+               if (size < sizeof(*data) - sizeof(data->flags)) {
                        FCM_LOG_ERR(EMSGSIZE,
                                    "Message too short from socket %d", snum);
                        rc = EBADCLIFMSG;
                        goto err;
                }
                data->flags = 0;
-       } else if (res > sizeof(*data)) {
+       } else if (size > sizeof(*data)) {
                FCM_LOG_ERR(EMSGSIZE, "Message too long from socket %d", snum);
                rc = EBADCLIFMSG;
                goto err;
@@ -3714,9 +3718,9 @@ int main(int argc, char **argv)
 /*******************************************************
  *         The following are debug routines            *
  *******************************************************/
-static void add_msg_to_buf(char *buf, int maxlen, char *msg, char *prefix)
+static void add_msg_to_buf(char *buf, size_t maxlen, char *msg, char *prefix)
 {
-       int len = strlen(buf);
+       size_t len = strlen(buf);
 
        if (len + strlen(msg) + strlen(prefix) < maxlen)
                sprintf(buf+len, "%s%s", prefix, msg);
diff --git a/fcping.c b/fcping.c
index dcdb081..8e9e7ed 100644
--- a/fcping.c
+++ b/fcping.c
@@ -478,7 +478,8 @@ fp_find_hba(void)
        fc_wwn_t wwn = 0;
        HBA_WWN wwpn;
        char *endptr;
-       int i, found = 0;
+       unsigned int i;
+       int found = 0;
 
        /*
         * Parse HBA spec. if there is one.
@@ -728,7 +729,7 @@ static uint32_t fp_get_max_data_len(fc_fid_t fcid)
 {
        HBA_STATUS retval;
        HBA_PORTATTRIBUTES rport_attrs;
-       int i;
+       unsigned int i;
        uint32_t dlen = 0;
 
        if (!hba_handle) {
@@ -736,7 +737,6 @@ static uint32_t fp_get_max_data_len(fc_fid_t fcid)
                goto out;
        }
 
-
        /* locate targets */
        for (i = 0; i < port_attrs.NumberofDiscoveredPorts; i++) {
                retval = HBA_GetDiscoveredPortAttributes(hba_handle, 0, i,
diff --git a/fipvlan.c b/fipvlan.c
index 10db38e..c6ed7c6 100644
--- a/fipvlan.c
+++ b/fipvlan.c
@@ -278,7 +278,7 @@ static int fip_recv_vlan_note(struct fiphdr *fh, int 
ifindex, bool vn2vn)
        uint16_t vlan;
        unsigned int bitmap, required_tlvs;
        int len;
-       int i;
+       unsigned int i;
 
        FIP_LOG_DBG("received FIP VLAN Notification");
 
diff --git a/lib/fcoe_utils.c b/lib/fcoe_utils.c
index 54b979b..516eac5 100644
--- a/lib/fcoe_utils.c
+++ b/lib/fcoe_utils.c
@@ -22,7 +22,8 @@
 int fcoe_sysfs_read(char *buf, int size, const char *path)
 {
        FILE *fp;
-       int i, rc = -EINVAL;
+       unsigned int i;
+       int rc = -EINVAL;
 
        fp = fopen(path, "r");
        if (fp) {
diff --git a/lib/fip.c b/lib/fip.c
index cd23fd7..73bf03e 100644
--- a/lib/fip.c
+++ b/lib/fip.c
@@ -393,15 +393,17 @@ int fip_recv(int s, fip_handler *fn, void *arg)
                .msg_iovlen = ARRAY_SIZE(iov),
        };
        struct fiphdr *fh;
-       ssize_t len, desc_len;
+       size_t len, desc_len;
+       int rc;
        struct ethhdr *eth = (struct ethhdr *)buf;
 
-       len = recvmsg(s, &msg, MSG_DONTWAIT);
-       if (len < 0) {
+       rc = recvmsg(s, &msg, MSG_DONTWAIT);
+       if (rc < 0) {
                FIP_LOG_ERRNO("packet socket recv error");
-               return len;
+               return rc;
        }
 
+       len = rc;
        if (len < sizeof(*fh)) {
                FIP_LOG_ERR(EINVAL, "received packed smaller that FIP header");
                return -1;
diff --git a/lib/rtnetlink.c b/lib/rtnetlink.c
index ddaeb16..08552bf 100644
--- a/lib/rtnetlink.c
+++ b/lib/rtnetlink.c
@@ -121,17 +121,19 @@ int rtnl_recv(int s, rtnl_handler *fn, void *arg)
 {
        char buf[8192];
        struct nlmsghdr *nh;
-       int len;
+       size_t len;
        int rc = 0;
+       int ret;
        bool more = false;
 
 more:
-       len = recv(s, buf, sizeof(buf), 0);
-       if (len < 0) {
+       ret = recv(s, buf, sizeof(buf), 0);
+       if (ret < 0) {
                RTNL_LOG_ERRNO("netlink recvmsg error");
-               return len;
+               return ret;
        }
 
+       len = ret;
        for (nh = NLMSG(buf); NLMSG_OK(nh, len); nh = NLMSG_NEXT(nh, len)) {
                if (nh->nlmsg_flags & NLM_F_MULTI)
                        more = true;
diff --git a/lib/sa_sys.c b/lib/sa_sys.c
index 86988ca..9c6818f 100644
--- a/lib/sa_sys.c
+++ b/lib/sa_sys.c
@@ -247,7 +247,7 @@ sa_table_destroy(struct sa_table *tp)
 void
 sa_table_destroy_all(struct sa_table *tp)
 {
-       int  i;
+       unsigned int  i;
 
        if (tp->st_table) {
                for (i = 0; i < tp->st_limit; i++) {
@@ -271,7 +271,7 @@ sa_table_iterate(struct sa_table *tp,
                 void (*handler)(void *ep, void *arg),
                 void *arg)
 {
-       int i;
+       unsigned int i;
        void *ep;
 
        for (i = 0; i < tp->st_limit; i++) {
@@ -296,7 +296,7 @@ void *
 sa_table_search(struct sa_table *tp, void *(*match)(void *ep, void *arg),
        void *arg)
 {
-       int i;
+       unsigned int i;
        void *found = NULL;
        void *ep;
 

_______________________________________________
fcoe-devel mailing list
[email protected]
http://lists.open-fcoe.org/mailman/listinfo/fcoe-devel

Reply via email to