On Tue, 29 Oct 2024 21:45:24 +0800
Yong Zhang <zhang.yon...@zte.com.cn> wrote:

> +     /* Init sw_ring */
> +     memset(name, 0, sizeof(name));
> +     snprintf(name, RTE_RAWDEV_NAME_MAX_LEN, "gdma_vq%d_sw_ring", queue_id);
> +     size = queue->queue_size * sizeof(struct zxdh_gdma_job *);
> +     queue->sw_ring.job = rte_zmalloc(name, size, 0);

This works as is, but:
        1. Do not need memset() before snprintf since snprintf will create null 
terminated string
        2. rte_zmalloc() doesn't really care about the name arg
        3. You should be using rte_calloc() if it is an array, because that is 
more common
           and may help some checkers in future when DPDK can tell compiler 
that rte_calloc is functional
           equivalent of calloc().
        4. The name is being used as a memzone name, and not a rawdev name.
                RTE_RAWDEV_NAME_MAX_LEN = 64
                RTE_MEMZONE_NAMESIZE = 32
           so you are at some risk of future bug where memzone names becomes 
too long.


                > +
> +     if (queue->sw_ring.job != NULL)
> +             rte_free(queue->sw_ring.job);
> +
> +     if (queue->ring.ring_mz != NULL)
> +             rte_memzone_free(queue->ring.ring_mz);

Both these function handle NULL as a no-op, so the check for NULL is 
unnecessary.
There is a coccinelle script that finds these.

Reply via email to