From: Markus Elfring <Markus.Elfring@web.de>
To: linux-usb@vger.kernel.org,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jeff Johnson <quic_jjohnson@quicinc.com>
Cc: LKML <linux-kernel@vger.kernel.org>, kernel-janitors@vger.kernel.org
Subject: [PATCH] usb: gadget: eem: Use common error handling code in eem_unwrap()
Date: Wed, 25 Sep 2024 17:38:39 +0200 [thread overview]
Message-ID: <59fadd5a-6574-4379-98ac-cc4f11b675cc@web.de> (raw)
From: Markus Elfring <elfring@users.sourceforge.net>
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@users.sourceforge.net>
---
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
next reply other threads:[~2024-09-25 15:38 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-25 15:38 Markus Elfring [this message]
2024-09-26 5:27 ` kernel test robot
2024-09-26 6:44 ` Markus Elfring
2024-09-26 9:03 ` kernel test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=59fadd5a-6574-4379-98ac-cc4f11b675cc@web.de \
--to=markus.elfring@web.de \
--cc=gregkh@linuxfoundation.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=quic_jjohnson@quicinc.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®