[PATCH 11/16] file_list: make freeing a NULL pointer a no-op

Ahmad Fatoum a.fatoum at pengutronix.de
Mon May 3 04:48:56 PDT 2021


This makes code added into usbgadget in a later commit less verbose.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 common/file-list.c         | 3 +++
 drivers/usb/gadget/multi.c | 6 ++----
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/common/file-list.c b/common/file-list.c
index 580423aef72d..55e6f0e6b6c0 100644
--- a/common/file-list.c
+++ b/common/file-list.c
@@ -161,6 +161,9 @@ void file_list_free(struct file_list *files)
 {
 	struct file_list_entry *entry, *tmp;
 
+	if (!files)
+		return;
+
 	list_for_each_entry_safe(entry, tmp, &files->list, list) {
 		free(entry->name);
 		free(entry->filename);
diff --git a/drivers/usb/gadget/multi.c b/drivers/usb/gadget/multi.c
index 95f5b90c88b5..da4a7591175c 100644
--- a/drivers/usb/gadget/multi.c
+++ b/drivers/usb/gadget/multi.c
@@ -268,10 +268,8 @@ void usb_multi_unregister(void)
 
 void usb_multi_opts_release(struct f_multi_opts *opts)
 {
-	if (opts->fastboot_opts.files)
-		file_list_free(opts->fastboot_opts.files);
-	if (opts->dfu_opts.files)
-		file_list_free(opts->dfu_opts.files);
+	file_list_free(opts->fastboot_opts.files);
+	file_list_free(opts->dfu_opts.files);
 
 	free(opts);
 }
-- 
2.29.2




More information about the barebox mailing list