From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id 84D557CD6 for ; Mon, 21 May 2018 15:11:00 +0200 (CEST) X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 May 2018 06:10:58 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,426,1520924400"; d="scan'208";a="201117720" Received: from bricha3-mobl.ger.corp.intel.com ([10.237.221.55]) by orsmga004.jf.intel.com with SMTP; 21 May 2018 06:10:56 -0700 Received: by (sSMTP sendmail emulation); Mon, 21 May 2018 14:10:55 +0100 Date: Mon, 21 May 2018 14:10:55 +0100 From: Bruce Richardson To: Andy Green Cc: dev@dpdk.org, thomas@monjalon.net Message-ID: <20180521131055.GG22944@bricha3-MOBL.ger.corp.intel.com> References: <152686781484.58694.14737673447518527445.stgit@localhost.localdomain> <152686808848.58694.3396046717951220668.stgit@localhost.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <152686808848.58694.3396046717951220668.stgit@localhost.localdomain> Organization: Intel Research and Development Ireland Ltd. User-Agent: Mutt/1.9.4 (2018-02-28) Subject: Re: [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 13:11:00 -0000 On Mon, May 21, 2018 at 10:01:28AM +0800, Andy Green wrote: > /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); > Code change looks ok to me, again it wouldn't hurt to have a comment explaining the absense of -=, but otherwise: Acked-by: Bruce Richardson