[openwrt/openwrt] kernel: leds-ws2812b: use devm functions

LEDE Commits lede-commits at lists.infradead.org
Sun Oct 6 03:21:56 PDT 2024


robimarko pushed a commit to openwrt/openwrt.git, branch main:
https://git.openwrt.org/63a92188fb3b044991f990484432ef4372040eb5

commit 63a92188fb3b044991f990484432ef4372040eb5
Author: Rosen Penev <rosenp at gmail.com>
AuthorDate: Fri Aug 2 15:13:43 2024 -0700

    kernel: leds-ws2812b: use devm functions
    
    Avoids having to free manually.
    
    Signed-off-by: Rosen Penev <rosenp at gmail.com>
    Link: https://github.com/openwrt/openwrt/pull/16587
    Signed-off-by: Robert Marko <robimarko at gmail.com>
---
 package/kernel/leds-ws2812b/src/leds-ws2812b.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/package/kernel/leds-ws2812b/src/leds-ws2812b.c b/package/kernel/leds-ws2812b/src/leds-ws2812b.c
index 0dba128c1f..69bc575ba2 100644
--- a/package/kernel/leds-ws2812b/src/leds-ws2812b.c
+++ b/package/kernel/leds-ws2812b/src/leds-ws2812b.c
@@ -117,7 +117,7 @@ static int ws2812b_probe(struct spi_device *spi)
 	priv->data_len =
 		num_leds * WS2812B_BYTES_PER_COLOR * WS2812B_NUM_COLORS +
 		WS2812B_RESET_LEN;
-	priv->data_buf = kzalloc(priv->data_len, GFP_KERNEL);
+	priv->data_buf = devm_kzalloc(dev, priv->data_len, GFP_KERNEL);
 	if (!priv->data_buf)
 		return -ENOMEM;
 
@@ -171,7 +171,7 @@ static int ws2812b_probe(struct spi_device *spi)
 
 		priv->leds[cur_led].cascade = cascade;
 
-		ret = led_classdev_multicolor_register_ext(
+		ret = devm_led_classdev_multicolor_register_ext(
 			dev, &priv->leds[cur_led].mc_cdev, &init_data);
 		if (ret) {
 			dev_err(dev, "registration of %s failed.",
@@ -185,10 +185,7 @@ static int ws2812b_probe(struct spi_device *spi)
 
 	return 0;
 ERR_UNREG_LEDS:
-	for (; cur_led >= 0; cur_led--)
-		led_classdev_multicolor_unregister(&priv->leds[cur_led].mc_cdev);
 	mutex_destroy(&priv->mutex);
-	kfree(priv->data_buf);
 	return ret;
 }
 
@@ -199,11 +196,7 @@ static int ws2812b_remove(struct spi_device *spi)
 #endif
 {
 	struct ws2812b_priv *priv = spi_get_drvdata(spi);
-	int cur_led;
 
-	for (cur_led = priv->num_leds - 1; cur_led >= 0; cur_led--)
-		led_classdev_multicolor_unregister(&priv->leds[cur_led].mc_cdev);
-	kfree(priv->data_buf);
 	mutex_destroy(&priv->mutex);
 
 #if LINUX_VERSION_CODE < KERNEL_VERSION(5,18,0)




More information about the lede-commits mailing list