Merge tag 'io_uring-5.11-2021-01-16' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / leds / leds-gpio-register.c
blobb9187e71e0cf2dd63d086fd78aba81e83969b99b
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (C) 2011 Pengutronix
4 * Uwe Kleine-Koenig <u.kleine-koenig@pengutronix.de>
5 */
6 #include <linux/err.h>
7 #include <linux/leds.h>
8 #include <linux/platform_device.h>
9 #include <linux/slab.h>
11 /**
12 * gpio_led_register_device - register a gpio-led device
13 * @pdata: the platform data used for the new device
15 * Makes a copy of pdata and pdata->leds and registers a new leds-gpio device
16 * with the result. This allows to have pdata and pdata-leds in .init.rodata
17 * and so saves some bytes compared to a static struct platform_device with
18 * static platform data.
20 * Returns the registered device or an error pointer.
22 struct platform_device *__init gpio_led_register_device(
23 int id, const struct gpio_led_platform_data *pdata)
25 struct platform_device *ret;
26 struct gpio_led_platform_data _pdata = *pdata;
28 if (!pdata->num_leds)
29 return ERR_PTR(-EINVAL);
31 _pdata.leds = kmemdup(pdata->leds,
32 pdata->num_leds * sizeof(*pdata->leds), GFP_KERNEL);
33 if (!_pdata.leds)
34 return ERR_PTR(-ENOMEM);
36 ret = platform_device_register_resndata(NULL, "leds-gpio", id,
37 NULL, 0, &_pdata, sizeof(_pdata));
38 if (IS_ERR(ret))
39 kfree(_pdata.leds);
41 return ret;