[PATCH] usb: gadget: eem: Use common error handling code in eem_unwrap()

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

 



From: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 25 Sep 2024 17:26:40 +0200

Add jump targets 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_eem.c | 30 ++++++++++++++---------------
 1 file changed, 14 insertions(+), 16 deletions(-)

diff --git a/drivers/usb/gadget/function/f_eem.c b/drivers/usb/gadget/function/f_eem.c
index 6de81ea17274..b1be23e947dc 100644
--- a/drivers/usb/gadget/function/f_eem.c
+++ b/drivers/usb/gadget/function/f_eem.c
@@ -450,24 +450,17 @@ static int eem_unwrap(struct gether *port,

 				ep = port->in_ep;
 				req = usb_ep_alloc_request(ep, GFP_ATOMIC);
-				if (!req) {
-					dev_kfree_skb_any(skb2);
-					goto next;
-				}
+				if (!req)
+					goto free_skb;

 				req->buf = kmalloc(skb2->len, GFP_KERNEL);
-				if (!req->buf) {
-					usb_ep_free_request(ep, req);
-					dev_kfree_skb_any(skb2);
-					goto next;
-				}
+				if (!req->buf)
+					goto free_request;

 				ctx = kmalloc(sizeof(*ctx), GFP_KERNEL);
 				if (!ctx) {
 					kfree(req->buf);
-					usb_ep_free_request(ep, req);
-					dev_kfree_skb_any(skb2);
-					goto next;
+					goto free_request;
 				}
 				ctx->skb = skb2;
 				ctx->ep = ep;
@@ -536,10 +529,9 @@ static int eem_unwrap(struct gether *port,
 						NET_IP_ALIGN,
 						0,
 						GFP_ATOMIC);
-			if (unlikely(!skb3)) {
-				dev_kfree_skb_any(skb2);
-				goto next;
-			}
+			if (unlikely(!skb3))
+				goto free_skb;
+
 			dev_kfree_skb_any(skb2);
 			skb_queue_tail(list, skb3);
 		}
@@ -550,6 +542,12 @@ static int eem_unwrap(struct gether *port,
 error:
 	dev_kfree_skb_any(skb);
 	return status;
+
+free_request:
+	usb_ep_free_request(ep, req);
+free_skb:
+	dev_kfree_skb_any(skb2);
+	goto next;
 }

 static inline struct f_eem_opts *to_f_eem_opts(struct config_item *item)
--
2.46.1






[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux