[libgpiod] [PATCH] iter: remove unnecessary indirection in free_dirs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



It is not necessary to pass the address of the 'dirs' variable to
dirs_free(), so this commit removes the unnecessary indirection.

Signed-off-by: Chris Nisbet <chris@xxxxxxxxxxxxxx>
---
 lib/iter.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/lib/iter.c b/lib/iter.c
index a4d883a..bfd2852 100644
--- a/lib/iter.c
+++ b/lib/iter.c
@@ -28,13 +28,13 @@ static int dir_filter(const struct dirent *dir)
     return !strncmp(dir->d_name, "gpiochip", 8);
 }

-static void free_dirs(struct dirent ***dirs, unsigned int num_dirs)
+static void free_dirs(struct dirent **dirs, unsigned int num_dirs)
 {
     unsigned int i;

     for (i = 0; i < num_dirs; i++)
-        free((*dirs)[i]);
-    free(*dirs);
+        free(dirs[i]);
+    free(dirs);
 }

 struct gpiod_chip_iter *gpiod_chip_iter_new(void)
@@ -69,7 +69,7 @@ struct gpiod_chip_iter *gpiod_chip_iter_new(void)
             goto err_close_chips;
     }

-    free_dirs(&dirs, num_chips);
+    free_dirs(dirs, num_chips);

     return iter;

@@ -85,7 +85,7 @@ err_free_iter:
     free(iter);

 err_free_dirs:
-    free_dirs(&dirs, num_chips);
+    free_dirs(dirs, num_chips);

     return NULL;
 }
--
2.7.4

Please consider this small patch. There should be no functional change.

When I first noticed this I wondered if I was missing something obvious that required the extra indirection, but I'm pretty convinced there isn't any good reason. I initially wondered if the intention might have been to set the caller's variable to NULL once the memory it pointed to was freed, but I hadn't noticed this technique anywhere else in the library.

Regards

Chris Nisbet




[Index of Archives]     [Linux SPI]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux