[dpdk-dev,v4] Fixes following error on gcc 4.4.7:

Message ID 1449663630-83289-1-git-send-email-pablo.de.lara.guarch@intel.com (mailing list archive)
State Superseded, archived
Headers

Commit Message

De Lara Guarch, Pablo Dec. 9, 2015, 12:20 p.m. UTC
  make: Entering directory `/tmp/dpdk-tmp/examples/vhost'
  CC main.o
cc1: warnings being treated as errors
/tmp/dpdk-tmp/examples/vhost/main.c: In function ‘new_device’:
/tmp/dpdk-tmp/x86_64-native-linuxapp-gcc/include/rte_ring.h:740: error:
    dereferencing pointer ‘mbuf.486’ does break strict-aliasing rules
/tmp/dpdk-tmp/examples/vhost/main.c:1503: note: initialized from here
...
/tmp/dpdk-tmp/examples/vhost/main.c:1503: note: initialized from here
/tmp/dpdk-tmp/x86_64-native-linuxapp-gcc/include/rte_ring.h:740: error:
    dereferencing pointer ‘({anonymous})’ does break strict-aliasing rules
/tmp/dpdk-tmp/examples/vhost/main.c:1804: note: initialized from here
make[1]: *** [main.o] Error 1

Fixes: d19533e8 ("examples/vhost: copy old vhost example")

Reported-by: Qian Xu <qian.q.xu@intel.com>
Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
---
Changes in v4:
- Simplify patch, just casting to void *, without using new variables

Changes in v3:
- Remove even more unnecessary castings

Changes in v2:
- Remove unnecessary casting

 examples/vhost/main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

Huawei Xie Dec. 9, 2015, 1:28 p.m. UTC | #1
On 12/9/2015 8:20 PM, De Lara Guarch, Pablo wrote:
> make: Entering directory `/tmp/dpdk-tmp/examples/vhost'
>   CC main.o
[...]
> -	rte_ring_sc_dequeue(vpool->ring, (void **)&mbuf);
> +	rte_ring_sc_dequeue(vpool->ring, (void *)mbuf);
Here we are expecting the address of &mbuf, not mbuf, which is NULL.
>  	if (unlikely(mbuf == NULL)) {
>  		LOG_DEBUG(VHOST_DATA,
>  			"(%"PRIu64") in attach_rxmbuf_zcp: "
> @@ -1801,7 +1801,7 @@ virtio_tx_route_zcp(struct virtio_net *dev, struct rte_mbuf *m,
>  
>  	/* Allocate an mbuf and populate the structure. */
>  	vpool = &vpool_array[MAX_QUEUES + vmdq_rx_q];
> -	rte_ring_sc_dequeue(vpool->ring, (void **)&mbuf);
> +	rte_ring_sc_dequeue(vpool->ring, (void *)mbuf);
Same as above.
>  	if (unlikely(mbuf == NULL)) {
>  		struct vhost_virtqueue *vq = dev->virtqueue[VIRTIO_TXQ];
>  		RTE_LOG(ERR, VHOST_DATA,
  
De Lara Guarch, Pablo Dec. 9, 2015, 2:01 p.m. UTC | #2
> -----Original Message-----
> From: Xie, Huawei
> Sent: Wednesday, December 09, 2015 1:29 PM
> To: De Lara Guarch, Pablo; dev@dpdk.org
> Cc: yuanhan.liu@linux.intel.com
> Subject: Re: [PATCH v4] Fixes following error on gcc 4.4.7:
> 
> On 12/9/2015 8:20 PM, De Lara Guarch, Pablo wrote:
> > make: Entering directory `/tmp/dpdk-tmp/examples/vhost'
> >   CC main.o
> [...]
> > -	rte_ring_sc_dequeue(vpool->ring, (void **)&mbuf);
> > +	rte_ring_sc_dequeue(vpool->ring, (void *)mbuf);
> Here we are expecting the address of &mbuf, not mbuf, which is NULL.
> >  	if (unlikely(mbuf == NULL)) {
> >  		LOG_DEBUG(VHOST_DATA,
> >  			"(%"PRIu64") in attach_rxmbuf_zcp: "
> > @@ -1801,7 +1801,7 @@ virtio_tx_route_zcp(struct virtio_net *dev,
> struct rte_mbuf *m,
> >
> >  	/* Allocate an mbuf and populate the structure. */
> >  	vpool = &vpool_array[MAX_QUEUES + vmdq_rx_q];
> > -	rte_ring_sc_dequeue(vpool->ring, (void **)&mbuf);
> > +	rte_ring_sc_dequeue(vpool->ring, (void *)mbuf);
> Same as above.
> >  	if (unlikely(mbuf == NULL)) {
> >  		struct vhost_virtqueue *vq = dev->virtqueue[VIRTIO_TXQ];
> >  		RTE_LOG(ERR, VHOST_DATA,

Right, I will revert to v3 (and fix the title as well, sorry about that).
  
Huawei Xie Dec. 9, 2015, 2:12 p.m. UTC | #3
On 12/9/2015 10:01 PM, De Lara Guarch, Pablo wrote:
>
>> -----Original Message-----
>> From: Xie, Huawei
>> Sent: Wednesday, December 09, 2015 1:29 PM
>> To: De Lara Guarch, Pablo; dev@dpdk.org
>> Cc: yuanhan.liu@linux.intel.com
>> Subject: Re: [PATCH v4] Fixes following error on gcc 4.4.7:
>>
>> On 12/9/2015 8:20 PM, De Lara Guarch, Pablo wrote:
>>> make: Entering directory `/tmp/dpdk-tmp/examples/vhost'
>>>   CC main.o
>> [...]
>>> -	rte_ring_sc_dequeue(vpool->ring, (void **)&mbuf);
>>> +	rte_ring_sc_dequeue(vpool->ring, (void *)mbuf);
>> Here we are expecting the address of &mbuf, not mbuf, which is NULL.
>>>  	if (unlikely(mbuf == NULL)) {
>>>  		LOG_DEBUG(VHOST_DATA,
>>>  			"(%"PRIu64") in attach_rxmbuf_zcp: "
>>> @@ -1801,7 +1801,7 @@ virtio_tx_route_zcp(struct virtio_net *dev,
>> struct rte_mbuf *m,
>>>  	/* Allocate an mbuf and populate the structure. */
>>>  	vpool = &vpool_array[MAX_QUEUES + vmdq_rx_q];
>>> -	rte_ring_sc_dequeue(vpool->ring, (void **)&mbuf);
>>> +	rte_ring_sc_dequeue(vpool->ring, (void *)mbuf);
>> Same as above.
>>>  	if (unlikely(mbuf == NULL)) {
>>>  		struct vhost_virtqueue *vq = dev->virtqueue[VIRTIO_TXQ];
>>>  		RTE_LOG(ERR, VHOST_DATA,
> Right, I will revert to v3 (and fix the title as well, sorry about that).
Actually we could try defining mbufs[1], and use (void **)mbufs as
parameter, like in examples/qos_sched to save a variable, but weird it
failed. For the time being, this fix is OK.
Another thing is would you fix examples/ip_pipeline as well?
>
  

Patch

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index dc3a012..f3c50c5 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -1500,7 +1500,7 @@  attach_rxmbuf_zcp(struct virtio_net *dev)
 		}
 	} while (unlikely(phys_addr == 0));
 
-	rte_ring_sc_dequeue(vpool->ring, (void **)&mbuf);
+	rte_ring_sc_dequeue(vpool->ring, (void *)mbuf);
 	if (unlikely(mbuf == NULL)) {
 		LOG_DEBUG(VHOST_DATA,
 			"(%"PRIu64") in attach_rxmbuf_zcp: "
@@ -1801,7 +1801,7 @@  virtio_tx_route_zcp(struct virtio_net *dev, struct rte_mbuf *m,
 
 	/* Allocate an mbuf and populate the structure. */
 	vpool = &vpool_array[MAX_QUEUES + vmdq_rx_q];
-	rte_ring_sc_dequeue(vpool->ring, (void **)&mbuf);
+	rte_ring_sc_dequeue(vpool->ring, (void *)mbuf);
 	if (unlikely(mbuf == NULL)) {
 		struct vhost_virtqueue *vq = dev->virtqueue[VIRTIO_TXQ];
 		RTE_LOG(ERR, VHOST_DATA,