spi: spi-s3c64xx.c: Remove of_node_put for auto cleanup
authorShivani Gupta <shivani07g@gmail.com>
Thu, 18 Apr 2024 00:05:05 +0000 (00:05 +0000)
committerMark Brown <broonie@kernel.org>
Wed, 24 Apr 2024 01:27:16 +0000 (10:27 +0900)
Use the scope based of_node_put() cleanup in s3c64xx_spi_csinfo to
automatically release the device node with the __free() cleanup handler
Initialize data_np at the point of declaration for clarity of scope.

This change reduces the risk of memory leaks and simplifies the code by
removing manual node put call.

Suggested-by: Julia Lawall <julia.lawall@inria.fr>
Signed-off-by: Shivani Gupta <shivani07g@gmail.com>
Link: https://lore.kernel.org/r/20240418000505.731724-1-shivani07g@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spi-s3c64xx.c

index f726d86704287e56b5cffba6ed40d8f7e1ca4956..833c58c88e4086cf8761520df8b6db637eee1794 100644 (file)
@@ -950,7 +950,7 @@ static struct s3c64xx_spi_csinfo *s3c64xx_get_target_ctrldata(
                                struct spi_device *spi)
 {
        struct s3c64xx_spi_csinfo *cs;
-       struct device_node *target_np, *data_np = NULL;
+       struct device_node *target_np;
        u32 fb_delay = 0;
 
        target_np = spi->dev.of_node;
@@ -963,7 +963,8 @@ static struct s3c64xx_spi_csinfo *s3c64xx_get_target_ctrldata(
        if (!cs)
                return ERR_PTR(-ENOMEM);
 
-       data_np = of_get_child_by_name(target_np, "controller-data");
+       struct device_node *data_np __free(device_node) =
+                       of_get_child_by_name(target_np, "controller-data");
        if (!data_np) {
                dev_info(&spi->dev, "feedback delay set to default (0)\n");
                return cs;
@@ -971,7 +972,6 @@ static struct s3c64xx_spi_csinfo *s3c64xx_get_target_ctrldata(
 
        of_property_read_u32(data_np, "samsung,spi-feedback-delay", &fb_delay);
        cs->fb_delay = fb_delay;
-       of_node_put(data_np);
        return cs;
 }