leds: gpio: Use struct_size() in devm_kzalloc()
Make use of the struct_size() helper instead of an open-coded version in order to avoid any potential type mistakes. Also, remove unnecessary function sizeof_gpio_leds_priv(). This code was detected with the help of Coccinelle and, audited and fixed manually. Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> Signed-off-by: Pavel Machek <pavel@ucw.cz>
This commit is contained in:
parent
a7ad53cb66
commit
cf1a1a6a7d
|
@ -125,12 +125,6 @@ struct gpio_leds_priv {
|
||||||
struct gpio_led_data leds[];
|
struct gpio_led_data leds[];
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline int sizeof_gpio_leds_priv(int num_leds)
|
|
||||||
{
|
|
||||||
return sizeof(struct gpio_leds_priv) +
|
|
||||||
(sizeof(struct gpio_led_data) * num_leds);
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct gpio_leds_priv *gpio_leds_create(struct platform_device *pdev)
|
static struct gpio_leds_priv *gpio_leds_create(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
struct device *dev = &pdev->dev;
|
struct device *dev = &pdev->dev;
|
||||||
|
@ -142,7 +136,7 @@ static struct gpio_leds_priv *gpio_leds_create(struct platform_device *pdev)
|
||||||
if (!count)
|
if (!count)
|
||||||
return ERR_PTR(-ENODEV);
|
return ERR_PTR(-ENODEV);
|
||||||
|
|
||||||
priv = devm_kzalloc(dev, sizeof_gpio_leds_priv(count), GFP_KERNEL);
|
priv = devm_kzalloc(dev, struct_size(priv, leds, count), GFP_KERNEL);
|
||||||
if (!priv)
|
if (!priv)
|
||||||
return ERR_PTR(-ENOMEM);
|
return ERR_PTR(-ENOMEM);
|
||||||
|
|
||||||
|
@ -260,9 +254,8 @@ static int gpio_led_probe(struct platform_device *pdev)
|
||||||
int i, ret = 0;
|
int i, ret = 0;
|
||||||
|
|
||||||
if (pdata && pdata->num_leds) {
|
if (pdata && pdata->num_leds) {
|
||||||
priv = devm_kzalloc(&pdev->dev,
|
priv = devm_kzalloc(&pdev->dev, struct_size(priv, leds, pdata->num_leds),
|
||||||
sizeof_gpio_leds_priv(pdata->num_leds),
|
GFP_KERNEL);
|
||||||
GFP_KERNEL);
|
|
||||||
if (!priv)
|
if (!priv)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue