From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.warmcat.com (mail.warmcat.com [163.172.24.82]) by dpdk.org (Postfix) with ESMTP id 444D1D08E for ; Mon, 21 May 2018 04:01:32 +0200 (CEST) From: Andy Green To: dev@dpdk.org Cc: thomas@monjalon.net Date: Mon, 21 May 2018 10:01:28 +0800 Message-ID: <152686808848.58694.3396046717951220668.stgit@localhost.localdomain> In-Reply-To: <152686781484.58694.14737673447518527445.stgit@localhost.localdomain> References: <152686781484.58694.14737673447518527445.stgit@localhost.localdomain> User-Agent: StGit/unknown-version Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Subject: [dpdk-dev] [PATCH v6 7/8] rte_mbuf.h: add and subtract explicitly to avoid promotion X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 May 2018 02:01:32 -0000 /projects/lagopus/src/dpdk/build/include/rte_mbuf.h: In function 'rte_pktmbuf_prepend': /projects/lagopus/src/dpdk/build/include/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. - m->data_off -= len; + m->data_off = (uint16_t)(m->data_off - len); The below += or -= changes are solving the same thing. /projects/lagopus/src/dpdk/build/include/rte_mbuf.h: In function 'rte_pktmbuf_adj': /projects/lagopus/src/dpdk/build/include/rte_mbuf.h: 1969:17: warning: conversion from 'int' to 'uint16_t' {aka 'short unsigned int'} may change value [-Wconversion] m->data_off += len; ^~~ /projects/lagopus/src/dpdk/build/include/rte_mbuf.h: In function 'rte_pktmbuf_chain': /projects/lagopus/src/dpdk/build/include/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: 08b563ffb1 ("mbuf: replace data pointer by an offset") Signed-off-by: Andy Green --- lib/librte_mbuf/rte_mbuf.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h index a0423a548..beb104c69 100644 --- a/lib/librte_mbuf/rte_mbuf.h +++ b/lib/librte_mbuf/rte_mbuf.h @@ -1908,7 +1908,7 @@ static inline char *rte_pktmbuf_prepend(struct rte_mbuf *m, if (unlikely(len > rte_pktmbuf_headroom(m))) return NULL; - m->data_off -= len; + 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); @@ -1969,7 +1969,7 @@ static inline char *rte_pktmbuf_adj(struct rte_mbuf *m, uint16_t len) return NULL; 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; } @@ -2082,7 +2082,7 @@ static inline int rte_pktmbuf_chain(struct rte_mbuf *head, struct rte_mbuf *tail cur_tail->next = tail; /* accumulate number of segments and total length. */ - head->nb_segs += tail->nb_segs; + 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 */