powerpc/mm: Drop the unnecessary region check
[linux-2.6-block.git] / drivers / gpio / gpiolib-devprop.c
CommitLineData
dae5f0af 1// SPDX-License-Identifier: GPL-2.0
9427ecbe
MW
2/*
3 * Device property helpers for GPIO chips.
4 *
5 * Copyright (C) 2016, Intel Corporation
6 * Author: Mika Westerberg <mika.westerberg@linux.intel.com>
9427ecbe
MW
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
14#include "gpiolib.h"
15
16/**
17 * devprop_gpiochip_set_names - Set GPIO line names using device properties
18 * @chip: GPIO chip whose lines should be named, if possible
82270335 19 * @fwnode: Property Node containing the gpio-line-names property
9427ecbe
MW
20 *
21 * Looks for device property "gpio-line-names" and if it exists assigns
22 * GPIO line names for the chip. The memory allocated for the assigned
23 * names belong to the underlying firmware node and should not be released
24 * by the caller.
25 */
82270335
CL
26void devprop_gpiochip_set_names(struct gpio_chip *chip,
27 const struct fwnode_handle *fwnode)
9427ecbe
MW
28{
29 struct gpio_device *gdev = chip->gpiodev;
30 const char **names;
31 int ret, i;
8dc19697 32 int count;
9427ecbe 33
8dc19697
CB
34 count = fwnode_property_read_string_array(fwnode, "gpio-line-names",
35 NULL, 0);
36 if (count < 0)
9427ecbe
MW
37 return;
38
8dc19697
CB
39 if (count > gdev->ngpio)
40 count = gdev->ngpio;
9427ecbe 41
8dc19697 42 names = kcalloc(count, sizeof(*names), GFP_KERNEL);
9427ecbe
MW
43 if (!names)
44 return;
45
82270335 46 ret = fwnode_property_read_string_array(fwnode, "gpio-line-names",
8dc19697 47 names, count);
9427ecbe 48 if (ret < 0) {
82270335 49 dev_warn(&gdev->dev, "failed to read GPIO line names\n");
9427ecbe
MW
50 kfree(names);
51 return;
52 }
53
8dc19697 54 for (i = 0; i < count; i++)
9427ecbe
MW
55 gdev->descs[i].name = names[i];
56
57 kfree(names);
58}