summaryrefslogtreecommitdiffstats
path: root/drivers/leds
diff options
context:
space:
mode:
authorGustavo A. R. Silva <gustavoars@kernel.org>2020-06-17 18:07:57 -0500
committerPavel Machek <pavel@ucw.cz>2020-07-12 10:26:10 +0200
commita7ad53cb6687069024efbd3af734c7811f63d2a5 (patch)
treeb0169dface24e6e9648ae16139eb27927fffb7d5 /drivers/leds
parentc4e94413922b8d5dd251cffd732b349772d22973 (diff)
downloadlinux-a7ad53cb6687069024efbd3af734c7811f63d2a5.tar.gz
linux-a7ad53cb6687069024efbd3af734c7811f63d2a5.tar.bz2
linux-a7ad53cb6687069024efbd3af734c7811f63d2a5.zip
leds: ns2: 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_ns2_led_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>
Diffstat (limited to 'drivers/leds')
-rw-r--r--drivers/leds/leds-ns2.c9
1 files changed, 1 insertions, 8 deletions
diff --git a/drivers/leds/leds-ns2.c b/drivers/leds/leds-ns2.c
index 538ca5755602..bd806e7c8017 100644
--- a/drivers/leds/leds-ns2.c
+++ b/drivers/leds/leds-ns2.c
@@ -348,12 +348,6 @@ struct ns2_led_priv {
struct ns2_led_data leds_data[];
};
-static inline int sizeof_ns2_led_priv(int num_leds)
-{
- return sizeof(struct ns2_led_priv) +
- (sizeof(struct ns2_led_data) * num_leds);
-}
-
static int ns2_led_probe(struct platform_device *pdev)
{
struct ns2_led_platform_data *pdata = dev_get_platdata(&pdev->dev);
@@ -378,8 +372,7 @@ static int ns2_led_probe(struct platform_device *pdev)
return -EINVAL;
#endif /* CONFIG_OF_GPIO */
- priv = devm_kzalloc(&pdev->dev,
- sizeof_ns2_led_priv(pdata->num_leds), GFP_KERNEL);
+ priv = devm_kzalloc(&pdev->dev, struct_size(priv, leds_data, pdata->num_leds), GFP_KERNEL);
if (!priv)
return -ENOMEM;
priv->num_leds = pdata->num_leds;