replace snprintf with strlcpy
[dpdk.git] / drivers / net / virtio / virtio_user / virtio_user_dev.c
index 07aabb5..8e420bc 100644 (file)
@@ -13,6 +13,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 
+#include <rte_string_fns.h>
 #include <rte_eal_memconfig.h>
 
 #include "vhost.h"
@@ -429,7 +430,7 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues,
                     int server, int mrg_rxbuf, int in_order, int packed_vq)
 {
        pthread_mutex_init(&dev->mutex, NULL);
-       snprintf(dev->path, PATH_MAX, "%s", path);
+       strlcpy(dev->path, path, PATH_MAX);
        dev->started = 0;
        dev->max_queue_pairs = queues;
        dev->queue_pairs = 1; /* mq disabled by default */
@@ -628,8 +629,10 @@ virtio_user_handle_ctrl_msg(struct virtio_user_dev *dev, struct vring *vring,
 static inline int
 desc_is_avail(struct vring_packed_desc *desc, bool wrap_counter)
 {
-       return wrap_counter == !!(desc->flags & VRING_DESC_F_AVAIL(1)) &&
-               wrap_counter != !!(desc->flags & VRING_DESC_F_USED(1));
+       uint16_t flags = desc->flags;
+
+       return wrap_counter == !!(flags & VRING_PACKED_DESC_F_AVAIL) &&
+               wrap_counter != !!(flags & VRING_PACKED_DESC_F_USED);
 }
 
 static uint32_t
@@ -684,7 +687,7 @@ virtio_user_handle_cq_packed(struct virtio_user_dev *dev, uint16_t queue_idx)
 {
        struct virtio_user_queue *vq = &dev->packed_queues[queue_idx];
        struct vring_packed *vring = &dev->packed_vrings[queue_idx];
-       uint16_t n_descs;
+       uint16_t n_descs, flags;
 
        while (desc_is_avail(&vring->desc[vq->used_idx],
                             vq->used_wrap_counter)) {
@@ -692,11 +695,12 @@ virtio_user_handle_cq_packed(struct virtio_user_dev *dev, uint16_t queue_idx)
                n_descs = virtio_user_handle_ctrl_msg_packed(dev, vring,
                                vq->used_idx);
 
+               flags = VRING_DESC_F_WRITE;
+               if (vq->used_wrap_counter)
+                       flags |= VRING_PACKED_DESC_F_AVAIL_USED;
+
                rte_smp_wmb();
-               vring->desc[vq->used_idx].flags =
-                       VRING_DESC_F_WRITE |
-                       VRING_DESC_F_AVAIL(vq->used_wrap_counter) |
-                       VRING_DESC_F_USED(vq->used_wrap_counter);
+               vring->desc[vq->used_idx].flags = flags;
 
                vq->used_idx += n_descs;
                if (vq->used_idx >= dev->queue_size) {