[PATCH] usb: gadget: f_fs: Use common error handling code in ffs_build_sg_list()

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

 



From: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 25 Sep 2024 18:03:16 +0200

Add a jump target so that a bit of exception handling can be better reused
at the end of this function implementation.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
---
 drivers/usb/gadget/function/f_fs.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
index 05b52e61a66f..318a74578c3f 100644
--- a/drivers/usb/gadget/function/f_fs.c
+++ b/drivers/usb/gadget/function/f_fs.c
@@ -808,23 +808,23 @@ static void *ffs_build_sg_list(struct sg_table *sgt, size_t sz)

 	n_pages = PAGE_ALIGN(sz) >> PAGE_SHIFT;
 	pages = kvmalloc_array(n_pages, sizeof(struct page *), GFP_KERNEL);
-	if (!pages) {
-		vfree(vaddr);
+	if (!pages)
+		goto free_vaddr;

-		return NULL;
-	}
 	for (i = 0, ptr = vaddr; i < n_pages; ++i, ptr += PAGE_SIZE)
 		pages[i] = vmalloc_to_page(ptr);

 	if (sg_alloc_table_from_pages(sgt, pages, n_pages, 0, sz, GFP_KERNEL)) {
 		kvfree(pages);
-		vfree(vaddr);
-
-		return NULL;
+		goto free_vaddr;
 	}
 	kvfree(pages);

 	return vaddr;
+
+free_vaddr:
+	vfree(vaddr);
+	return NULL;
 }

 static inline void *ffs_alloc_buffer(struct ffs_io_data *io_data,
--
2.46.1






[Index of Archives]     [Kernel Development]     [Kernel Announce]     [Kernel Newbies]     [Linux Networking Development]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Device Mapper]

  Powered by Linux