1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2011 Pengutronix
4 * Uwe Kleine-Koenig <u.kleine-koenig@pengutronix.de>
7 #include <linux/leds.h>
8 #include <linux/platform_device.h>
9 #include <linux/slab.h>
12 * gpio_led_register_device - register a gpio-led device
14 * @pdata: the platform data used for the new device
16 * Makes a copy of pdata and pdata->leds and registers a new leds-gpio device
17 * with the result. This allows to have pdata and pdata-leds in .init.rodata
18 * and so saves some bytes compared to a static struct platform_device with
19 * static platform data.
21 * Returns the registered device or an error pointer.
23 struct platform_device
*__init
gpio_led_register_device(
24 int id
, const struct gpio_led_platform_data
*pdata
)
26 struct platform_device
*ret
;
27 struct gpio_led_platform_data _pdata
= *pdata
;
30 return ERR_PTR(-EINVAL
);
32 _pdata
.leds
= kmemdup(pdata
->leds
,
33 pdata
->num_leds
* sizeof(*pdata
->leds
), GFP_KERNEL
);
35 return ERR_PTR(-ENOMEM
);
37 ret
= platform_device_register_resndata(NULL
, "leds-gpio", id
,
38 NULL
, 0, &_pdata
, sizeof(_pdata
));