[dpdk-dev,3/3] virtio: fix possible NULL dereference
Commit Message
Found by Coverity. In virtio_dev_queue_release if the queue pointer is
NULL, then driver is dereferencing it to get hw pointer.
Also, don't do useless assignment
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
drivers/net/virtio/virtio_ethdev.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
Comments
> -----Original Message-----
> From: Stephen Hemminger [mailto:stephen@networkplumber.org]
> Sent: Saturday, August 29, 2015 12:24 AM
> To: Xie, Huawei; Ouyang, Changchun
> Cc: dev@dpdk.org; Stephen Hemminger
> Subject: [PATCH 3/3] virtio: fix possible NULL dereference
>
> Found by Coverity. In virtio_dev_queue_release if the queue pointer is NULL,
> then driver is dereferencing it to get hw pointer.
> Also, don't do useless assignment
>
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Changchun Ouyang <changchun.ouyang@intel.com>
> ---
> drivers/net/virtio/virtio_ethdev.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/virtio/virtio_ethdev.c
> b/drivers/net/virtio/virtio_ethdev.c
> index 338d891..914c73d 100644
> --- a/drivers/net/virtio/virtio_ethdev.c
> +++ b/drivers/net/virtio/virtio_ethdev.c
> @@ -239,15 +239,15 @@ virtio_set_multiple_queues(struct rte_eth_dev
> *dev, uint16_t nb_queues)
>
> void
> virtio_dev_queue_release(struct virtqueue *vq) {
> - struct virtio_hw *hw = vq->hw;
>
> if (vq) {
> + struct virtio_hw *hw = vq->hw;
> +
> /* Select and deactivate the queue */
> VIRTIO_WRITE_REG_2(hw, VIRTIO_PCI_QUEUE_SEL, vq-
> >queue_id);
> VIRTIO_WRITE_REG_4(hw, VIRTIO_PCI_QUEUE_PFN, 0);
>
> rte_free(vq);
> - vq = NULL;
> }
> }
>
> --
> 2.1.4
@@ -239,15 +239,15 @@ virtio_set_multiple_queues(struct rte_eth_dev *dev, uint16_t nb_queues)
void
virtio_dev_queue_release(struct virtqueue *vq) {
- struct virtio_hw *hw = vq->hw;
if (vq) {
+ struct virtio_hw *hw = vq->hw;
+
/* Select and deactivate the queue */
VIRTIO_WRITE_REG_2(hw, VIRTIO_PCI_QUEUE_SEL, vq->queue_id);
VIRTIO_WRITE_REG_4(hw, VIRTIO_PCI_QUEUE_PFN, 0);
rte_free(vq);
- vq = NULL;
}
}