Path: blob/master/drivers/leds/leds-gpio-register.c
15112 views
/*1* Copyright (C) 2011 Pengutronix2* Uwe Kleine-Koenig <[email protected]>3*4* This program is free software; you can redistribute it and/or modify it under5* the terms of the GNU General Public License version 2 as published by the6* Free Software Foundation.7*/8#include <linux/err.h>9#include <linux/platform_device.h>10#include <linux/slab.h>11#include <linux/leds.h>1213/**14* gpio_led_register_device - register a gpio-led device15* @pdata: the platform data used for the new device16*17* Makes a copy of pdata and pdata->leds and registers a new leds-gpio device18* with the result. This allows to have pdata and pdata-leds in .init.rodata19* and so saves some bytes compared to a static struct platform_device with20* static platform data.21*22* Returns the registered device or an error pointer.23*/24struct platform_device *__init gpio_led_register_device(25int id, const struct gpio_led_platform_data *pdata)26{27struct platform_device *ret;28struct gpio_led_platform_data _pdata = *pdata;2930_pdata.leds = kmemdup(pdata->leds,31pdata->num_leds * sizeof(*pdata->leds), GFP_KERNEL);32if (!_pdata.leds)33return ERR_PTR(-ENOMEM);3435ret = platform_device_register_resndata(NULL, "leds-gpio", id,36NULL, 0, &_pdata, sizeof(_pdata));37if (IS_ERR(ret))38kfree(_pdata.leds);3940return ret;41}424344