On Thu, 17 Oct 2024 17:22:02 +0800
Hanxiao Li <li.hanx...@zte.com.cn> wrote:

> +static int
> +zsda_get_queue_cfg_by_id(const struct zsda_pci_device *zsda_pci_dev,
> +                      const uint8_t qid, struct qinfo *qcfg)
> +{
> +     struct zsda_admin_req_qcfg req = {0};
> +     struct zsda_admin_resp_qcfg resp = {0};
> +     int ret = 0;
> +     struct rte_pci_device *pci_dev =
> +             zsda_devs[zsda_pci_dev->zsda_dev_id].pci_dev;
> +
> +     if (qid >= MAX_QPS_ON_FUNCTION) {
> +             ZSDA_LOG(ERR, "qid beyond limit!");
> +             return ZSDA_FAILED;
> +     }
> +
> +     zsda_admin_msg_init(pci_dev);
> +     req.msg_type = ZSDA_ADMIN_QUEUE_CFG_REQ;
> +     req.qid = qid;
> +
> +     ret = zsda_send_admin_msg(pci_dev, &req, sizeof(req));
> +     if (ret) {
> +             ZSDA_LOG(ERR, "Failed! Send msg");
> +             return ret;
> +     }
> +
> +     ret = zsda_recv_admin_msg(pci_dev, &resp, sizeof(resp));
> +     if (ret) {
> +             ZSDA_LOG(ERR, "Failed! Receive msg");
> +             return ret;
> +     }
> +
> +     memcpy(qcfg, &resp.qcfg, sizeof(*qcfg));

Could this just be a structure assignment and keep type safety.

        *qcfg = resp.qcfg;

> +static int
> +zsda_cookie_init(const uint32_t dev_id, struct zsda_qp **qp_addr,
> +         const uint16_t queue_pair_id,
> +         const struct zsda_qp_config *zsda_qp_conf)
> +{
> +     struct zsda_qp *qp = *qp_addr;
> +     struct rte_pci_device *pci_dev = zsda_devs[dev_id].pci_dev;
> +     char op_cookie_pool_name[RTE_RING_NAMESIZE];
> +     uint32_t i;
> +     enum zsda_service_type type = zsda_qp_conf->service_type;
> +
> +     if (zsda_qp_conf->nb_descriptors != ZSDA_MAX_DESC)
> +             ZSDA_LOG(ERR, "Can't create qp for %u descriptors",
> +                      zsda_qp_conf->nb_descriptors);
> +
> +     qp->srv[type].nb_descriptors = zsda_qp_conf->nb_descriptors;
> +
> +     qp->srv[type].op_cookies = rte_zmalloc_socket(
> +             "zsda PMD op cookie pointer",
> +             zsda_qp_conf->nb_descriptors *
> +                     sizeof(*qp->srv[type].op_cookies),
> +             RTE_CACHE_LINE_SIZE, zsda_qp_conf->socket_id);
> +
> +     if (qp->srv[type].op_cookies == NULL) {
> +             ZSDA_LOG(ERR, E_MALLOC);
> +             return -ENOMEM;
> +     }
> +
> +     snprintf(op_cookie_pool_name, RTE_RING_NAMESIZE, "%s%d_cks_%s_qp%hu",
> +              pci_dev->driver->driver.name, dev_id,
> +              zsda_qp_conf->service_str, queue_pair_id);
> +
> +     qp->srv[type].op_cookie_pool = rte_mempool_lookup(op_cookie_pool_name);
> +     if (qp->srv[type].op_cookie_pool == NULL)
> +             qp->srv[type].op_cookie_pool = rte_mempool_create(
> +                     op_cookie_pool_name, qp->srv[type].nb_descriptors,
> +                     zsda_qp_conf->cookie_size, 64, 0, NULL, NULL, NULL,
> +                     NULL, (int)(rte_socket_id() & 0xfff), 0);
> +     if (!qp->srv[type].op_cookie_pool) {
> +             ZSDA_LOG(ERR, E_CREATE);
> +             goto exit;
> +     }
> +
> +     for (i = 0; i < qp->srv[type].nb_descriptors; i++) {
> +             if (rte_mempool_get(qp->srv[type].op_cookie_pool,
> +                                 &qp->srv[type].op_cookies[i])) {
> +                     ZSDA_LOG(ERR, "ZSDA PMD Cannot get op_cookie");
> +                     goto exit;
> +             }
> +             memset(qp->srv[type].op_cookies[i], 0,
> +                    zsda_qp_conf->cookie_size);
> +     }
> +     return 0;
> +
> +exit:
> +     if (qp->srv[type].op_cookie_pool)
> +             rte_mempool_free(qp->srv[type].op_cookie_pool);

No need to check for null with rte_mempool_free. The cocci/nullfree script
modifies this

Reply via email to