LCOV - code coverage report
Current view: top level - drivers/bus/vdev - vdev_params.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 11 15 73.3 %
Date: 2024-12-01 18:57:19 Functions: 2 2 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 4 10 40.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright 2018 Gaƫtan Rivet
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <errno.h>
       6                 :            : #include <string.h>
       7                 :            : 
       8                 :            : #include <dev_driver.h>
       9                 :            : #include <rte_kvargs.h>
      10                 :            : #include <rte_errno.h>
      11                 :            : 
      12                 :            : #include "vdev_logs.h"
      13                 :            : #include "vdev_private.h"
      14                 :            : 
      15                 :            : enum vdev_params {
      16                 :            :         RTE_VDEV_PARAM_NAME,
      17                 :            :         RTE_VDEV_PARAM_MAX,
      18                 :            : };
      19                 :            : 
      20                 :            : static const char * const vdev_params_keys[] = {
      21                 :            :         [RTE_VDEV_PARAM_NAME] = "name",
      22                 :            :         [RTE_VDEV_PARAM_MAX] = NULL,
      23                 :            : };
      24                 :            : 
      25                 :            : static int
      26                 :          2 : vdev_dev_match(const struct rte_device *dev,
      27                 :            :                const void *_kvlist)
      28                 :            : {
      29                 :            :         const struct rte_kvargs *kvlist = _kvlist;
      30                 :            :         const char *key = vdev_params_keys[RTE_VDEV_PARAM_NAME];
      31                 :            :         const char *name;
      32                 :            : 
      33                 :            :         /* no kvlist arg, all devices match */
      34         [ +  - ]:          2 :         if (kvlist == NULL)
      35                 :            :                 return 0;
      36                 :            : 
      37                 :            :         /* if key is present in kvlist and does not match, filter device */
      38                 :          2 :         name = rte_kvargs_get(kvlist, key);
      39   [ -  +  -  - ]:          2 :         if (name != NULL && strcmp(name, dev->name))
      40                 :          0 :                 return -1;
      41                 :            : 
      42                 :            :         return 0;
      43                 :            : }
      44                 :            : 
      45                 :            : void *
      46                 :          3 : rte_vdev_dev_iterate(const void *start,
      47                 :            :                      const char *str,
      48                 :            :                      const struct rte_dev_iterator *it __rte_unused)
      49                 :            : {
      50                 :            :         struct rte_kvargs *kvargs = NULL;
      51                 :            :         struct rte_device *dev;
      52                 :            : 
      53         [ +  - ]:          3 :         if (str != NULL) {
      54                 :          3 :                 kvargs = rte_kvargs_parse(str, vdev_params_keys);
      55         [ -  + ]:          3 :                 if (kvargs == NULL) {
      56                 :          0 :                         VDEV_LOG(ERR, "cannot parse argument list");
      57                 :          0 :                         rte_errno = EINVAL;
      58                 :          0 :                         return NULL;
      59                 :            :                 }
      60                 :            :         }
      61                 :          3 :         dev = rte_vdev_find_device(start, vdev_dev_match, kvargs);
      62                 :          3 :         rte_kvargs_free(kvargs);
      63                 :          3 :         return dev;
      64                 :            : }

Generated by: LCOV version 1.14