kernel: leds-ws2812b: use devm functions
authorRosen Penev <rosenp@gmail.com>
Fri, 2 Aug 2024 22:13:43 +0000 (15:13 -0700)
committerRobert Marko <robimarko@gmail.com>
Sun, 6 Oct 2024 10:21:51 +0000 (12:21 +0200)
Avoids having to free manually.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/16587
Signed-off-by: Robert Marko <robimarko@gmail.com>
package/kernel/leds-ws2812b/src/leds-ws2812b.c

index 0dba128c1f08ef667523bcaa34249bd59871a482..69bc575ba28bc8cd443a5c09a139e958e2007566 100644 (file)
@@ -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)