summaryrefslogtreecommitdiff
path: root/lib/librte_mbuf
diff options
context:
space:
mode:
authorAndy Green <andy@warmcat.com>2018-05-22 09:24:42 +0800
committerThomas Monjalon <thomas@monjalon.net>2018-05-22 16:32:36 +0200
commit9d0b59f84e1170b12a128cdcccab5711f25b5dd8 (patch)
tree6f18730b4dedcba528a85cebf0889a063aceccb2 /lib/librte_mbuf
parentef5092e16b137fd5e23d19b4b17b32f330d4a4ad (diff)
downloaddpdk-9d0b59f84e1170b12a128cdcccab5711f25b5dd8.zip
dpdk-9d0b59f84e1170b12a128cdcccab5711f25b5dd8.tar.gz
dpdk-9d0b59f84e1170b12a128cdcccab5711f25b5dd8.tar.xz
mbuf: avoid integer promotion in prepend/adj/chain
GCC 8.1 warned: In function 'rte_pktmbuf_prepend': rte_mbuf.h:1908:17: warning: conversion from 'int' to 'uint16_t' {aka 'short unsigned int'} may change value [-Wconversion] m->data_off -= len; ^~~ m->data_off is a uint16_t uint16_t data_off; len (a uint16_t) is promoted to an int using -=. Do the subtraction explicitly and cast the result to uint16_t. The below += or -= changes are solving the same thing. In function 'rte_pktmbuf_adj': rte_mbuf.h:1969:17: warning: conversion from 'int' to 'uint16_t' {aka 'short unsigned int'} may change value [-Wconversion] m->data_off += len; ^~~ In function 'rte_pktmbuf_chain': rte_mbuf.h:2082:19: warning: conversion from 'int' to 'uint16_t' {aka 'short unsigned int'} may change value [-Wconversion] head->nb_segs += tail->nb_segs; ^~~~ Also uint16_t uint16_t nb_segs; /**< Number of segments. */ Fixes: 08b563ffb19d ("mbuf: replace data pointer by an offset") Fixes: 1a60a0daa6e4 ("mbuf: fix segments number type increase") Cc: stable@dpdk.org Signed-off-by: Andy Green <andy@warmcat.com> Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Diffstat (limited to 'lib/librte_mbuf')
-rw-r--r--lib/librte_mbuf/rte_mbuf.h17
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h
index 0e89a69..e136d12 100644
--- a/lib/librte_mbuf/rte_mbuf.h
+++ b/lib/librte_mbuf/rte_mbuf.h
@@ -1908,7 +1908,10 @@ static inline char *rte_pktmbuf_prepend(struct rte_mbuf *m,
if (unlikely(len > rte_pktmbuf_headroom(m)))
return NULL;
- m->data_off -= len;
+ /* NB: elaborating the subtraction like this instead of using
+ * -= allows us to ensure the result type is uint16_t
+ * avoiding compiler warnings on gcc 8.1 at least */
+ m->data_off = (uint16_t)(m->data_off - len);
m->data_len = (uint16_t)(m->data_len + len);
m->pkt_len = (m->pkt_len + len);
@@ -1968,8 +1971,11 @@ static inline char *rte_pktmbuf_adj(struct rte_mbuf *m, uint16_t len)
if (unlikely(len > m->data_len))
return NULL;
+ /* NB: elaborating the addition like this instead of using
+ * += allows us to ensure the result type is uint16_t
+ * avoiding compiler warnings on gcc 8.1 at least */
m->data_len = (uint16_t)(m->data_len - len);
- m->data_off += len;
+ m->data_off = (uint16_t)(m->data_off + len);
m->pkt_len = (m->pkt_len - len);
return (char *)m->buf_addr + m->data_off;
}
@@ -2081,8 +2087,11 @@ static inline int rte_pktmbuf_chain(struct rte_mbuf *head, struct rte_mbuf *tail
cur_tail = rte_pktmbuf_lastseg(head);
cur_tail->next = tail;
- /* accumulate number of segments and total length. */
- head->nb_segs += tail->nb_segs;
+ /* accumulate number of segments and total length.
+ * NB: elaborating the addition like this instead of using
+ * -= allows us to ensure the result type is uint16_t
+ * avoiding compiler warnings on gcc 8.1 at least */
+ head->nb_segs = (uint16_t)(head->nb_segs + tail->nb_segs);
head->pkt_len += tail->pkt_len;
/* pkt_len is only set in the head */