Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932823AbcKVPQ6 (ORCPT ); Tue, 22 Nov 2016 10:16:58 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55132 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932592AbcKVPQ5 (ORCPT ); Tue, 22 Nov 2016 10:16:57 -0500 Subject: Re: [PATCH 2/2] virtio_ring: fix complaint by sparse To: "Michael S. Tsirkin" , Gonglei References: <1479793910-120188-1-git-send-email-arei.gonglei@huawei.com> <1479793910-120188-3-git-send-email-arei.gonglei@huawei.com> <20161122170346-mutt-send-email-mst@kernel.org> Cc: david@gibson.dropbear.id.au, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, Andy Lutomirski From: Thomas Huth Message-ID: <63a3cd15-76a9-8286-fa26-ebb9029427aa@redhat.com> Date: Tue, 22 Nov 2016 16:16:54 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <20161122170346-mutt-send-email-mst@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 22 Nov 2016 15:16:57 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2348 Lines: 47 On 22.11.2016 16:04, Michael S. Tsirkin wrote: > On Tue, Nov 22, 2016 at 01:51:50PM +0800, Gonglei wrote: >> # make C=2 CF="-D__CHECK_ENDIAN__" ./drivers/virtio/ >> >> drivers/virtio/virtio_ring.c:423:19: warning: incorrect type in assignment (different base types) >> drivers/virtio/virtio_ring.c:423:19: expected unsigned int [unsigned] [assigned] i >> drivers/virtio/virtio_ring.c:423:19: got restricted __virtio16 [usertype] next >> drivers/virtio/virtio_ring.c:423:19: warning: incorrect type in assignment (different base types) >> drivers/virtio/virtio_ring.c:423:19: expected unsigned int [unsigned] [assigned] i >> drivers/virtio/virtio_ring.c:423:19: got restricted __virtio16 [usertype] next >> drivers/virtio/virtio_ring.c:423:19: warning: incorrect type in assignment (different base types) >> drivers/virtio/virtio_ring.c:423:19: expected unsigned int [unsigned] [assigned] i >> drivers/virtio/virtio_ring.c:423:19: got restricted __virtio16 [usertype] next >> drivers/virtio/virtio_ring.c:604:39: warning: incorrect type in initializer (different base types) >> drivers/virtio/virtio_ring.c:604:39: expected unsigned short [unsigned] [usertype] nextflag >> drivers/virtio/virtio_ring.c:604:39: got restricted __virtio16 >> drivers/virtio/virtio_ring.c:612:33: warning: restricted __virtio16 degrades to integer >> >> Signed-off-by: Gonglei >> --- >> drivers/virtio/virtio_ring.c | 4 ++-- >> 1 file changed, 2 insertions(+), 2 deletions(-) >> >> diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c >> index 489bfc6..d2863c3 100644 >> --- a/drivers/virtio/virtio_ring.c >> +++ b/drivers/virtio/virtio_ring.c >> @@ -420,7 +420,7 @@ static inline int virtqueue_add(struct virtqueue *_vq, >> if (i == err_idx) >> break; >> vring_unmap_one(vq, &desc[i]); >> - i = vq->vring.desc[i].next; >> + i = virtio16_to_cpu(_vq->vdev, vq->vring.desc[i].next); >> } >> >> vq->vq.num_free += total_sg; [...] > Wow are you saying endian-ness is all wrong for the next field? > How do things ever work then? The above code is only in the error cleanup path (after the "unmap_release" label, introduced by commit 780bc7903), so it likely has never been exercised in the field. I think Gonlei's patch is right, there should be a virtio16_to_cpu() here. Thomas