LCOV - code coverage report
Current view: top level - drivers/gpio - gpiolib-devprop.c (source / functions) Hit Total Coverage
Test: gcov_data_raspi2_qemu_modules_combined.info Lines: 4 15 26.7 %
Date: 2020-09-30 20:25:01 Functions: 1 1 100.0 %
Branches: 1 10 10.0 %

           Branch data     Line data    Source code
       1                 :            : // SPDX-License-Identifier: GPL-2.0
       2                 :            : /*
       3                 :            :  * Device property helpers for GPIO chips.
       4                 :            :  *
       5                 :            :  * Copyright (C) 2016, Intel Corporation
       6                 :            :  * Author: Mika Westerberg <mika.westerberg@linux.intel.com>
       7                 :            :  */
       8                 :            : 
       9                 :            : #include <linux/property.h>
      10                 :            : #include <linux/slab.h>
      11                 :            : #include <linux/gpio/consumer.h>
      12                 :            : #include <linux/gpio/driver.h>
      13                 :            : #include <linux/export.h>
      14                 :            : 
      15                 :            : #include "gpiolib.h"
      16                 :            : 
      17                 :            : /**
      18                 :            :  * devprop_gpiochip_set_names - Set GPIO line names using device properties
      19                 :            :  * @chip: GPIO chip whose lines should be named, if possible
      20                 :            :  * @fwnode: Property Node containing the gpio-line-names property
      21                 :            :  *
      22                 :            :  * Looks for device property "gpio-line-names" and if it exists assigns
      23                 :            :  * GPIO line names for the chip. The memory allocated for the assigned
      24                 :            :  * names belong to the underlying firmware node and should not be released
      25                 :            :  * by the caller.
      26                 :            :  */
      27                 :        404 : void devprop_gpiochip_set_names(struct gpio_chip *chip,
      28                 :            :                                 const struct fwnode_handle *fwnode)
      29                 :            : {
      30                 :        404 :         struct gpio_device *gdev = chip->gpiodev;
      31                 :            :         const char **names;
      32                 :            :         int ret, i;
      33                 :            :         int count;
      34                 :            : 
      35                 :        404 :         count = fwnode_property_read_string_array(fwnode, "gpio-line-names",
      36                 :            :                                                   NULL, 0);
      37         [ -  + ]:        404 :         if (count < 0)
      38                 :            :                 return;
      39                 :            : 
      40         [ #  # ]:          0 :         if (count > gdev->ngpio)
      41                 :            :                 count = gdev->ngpio;
      42                 :            : 
      43                 :          0 :         names = kcalloc(count, sizeof(*names), GFP_KERNEL);
      44         [ #  # ]:          0 :         if (!names)
      45                 :            :                 return;
      46                 :            : 
      47                 :          0 :         ret = fwnode_property_read_string_array(fwnode, "gpio-line-names",
      48                 :            :                                                 names, count);
      49         [ #  # ]:          0 :         if (ret < 0) {
      50                 :          0 :                 dev_warn(&gdev->dev, "failed to read GPIO line names\n");
      51                 :          0 :                 kfree(names);
      52                 :          0 :                 return;
      53                 :            :         }
      54                 :            : 
      55         [ #  # ]:          0 :         for (i = 0; i < count; i++)
      56                 :          0 :                 gdev->descs[i].name = names[i];
      57                 :            : 
      58                 :          0 :         kfree(names);
      59                 :            : }
      60                 :            : EXPORT_SYMBOL_GPL(devprop_gpiochip_set_names);

Generated by: LCOV version 1.14