public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: SF Markus Elfring <elfring@users.sourceforge.net>
To: linux-usb@vger.kernel.org,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Shuah Khan <shuah@kernel.org>,
	Valentina Manea <valentina.manea.m@gmail.com>
Cc: LKML <linux-kernel@vger.kernel.org>, kernel-janitors@vger.kernel.org
Subject: [PATCH 2/2] usbip: Use common error handling code in stub_recv_cmd_submit()
Date: Tue, 5 Dec 2017 22:52:03 +0100	[thread overview]
Message-ID: <32b1d0d7-8a48-a960-c666-b0ea187ecdcc@users.sourceforge.net> (raw)
In-Reply-To: <6a84f1e4-a5c1-84da-bd14-de28e306991b@users.sourceforge.net>

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 5 Dec 2017 22:40:30 +0100

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

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/usb/usbip/stub_rx.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/drivers/usb/usbip/stub_rx.c b/drivers/usb/usbip/stub_rx.c
index a70eb81823a3..f46d71abd2f9 100644
--- a/drivers/usb/usbip/stub_rx.c
+++ b/drivers/usb/usbip/stub_rx.c
@@ -445,29 +445,23 @@ static void stub_recv_cmd_submit(struct stub_device *sdev,
 	else
 		priv->urb = usb_alloc_urb(0, GFP_KERNEL);
 
-	if (!priv->urb) {
-		usbip_event_add(ud, SDEV_EVENT_ERROR_MALLOC);
-		return;
-	}
+	if (!priv->urb)
+		goto add_event_malloc_failure;
 
 	/* allocate urb transfer buffer, if needed */
 	if (pdu->u.cmd_submit.transfer_buffer_length > 0) {
 		priv->urb->transfer_buffer =
 			kzalloc(pdu->u.cmd_submit.transfer_buffer_length,
 				GFP_KERNEL);
-		if (!priv->urb->transfer_buffer) {
-			usbip_event_add(ud, SDEV_EVENT_ERROR_MALLOC);
-			return;
-		}
+		if (!priv->urb->transfer_buffer)
+			goto add_event_malloc_failure;
 	}
 
 	/* copy urb setup packet */
 	priv->urb->setup_packet = kmemdup(&pdu->u.cmd_submit.setup, 8,
 					  GFP_KERNEL);
-	if (!priv->urb->setup_packet) {
-		usbip_event_add(ud, SDEV_EVENT_ERROR_MALLOC);
-		return;
-	}
+	if (!priv->urb->setup_packet)
+		goto add_event_malloc_failure;
 
 	/* set other members from the base header of pdu */
 	priv->urb->context                = (void *) priv;
@@ -507,6 +501,10 @@ static void stub_recv_cmd_submit(struct stub_device *sdev,
 	}
 
 	usbip_dbg_stub_rx("Leave\n");
+	return;
+
+add_event_malloc_failure:
+	usbip_event_add(ud, SDEV_EVENT_ERROR_MALLOC);
 }
 
 /* recv a pdu */
-- 
2.15.1

  parent reply	other threads:[~2017-12-05 21:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-05 21:48 [PATCH 0/2] usbip: Adjustments for two function implementations SF Markus Elfring
2017-12-05 21:49 ` [PATCH 1/2] usbip: Delete an error message for a failed memory allocation in two functions SF Markus Elfring
2017-12-05 22:14   ` Shuah Khan
2017-12-06  9:10     ` SF Markus Elfring
2017-12-05 21:52 ` SF Markus Elfring [this message]
2017-12-05 22:21   ` [PATCH 2/2] usbip: Use common error handling code in stub_recv_cmd_submit() Shuah Khan

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=32b1d0d7-8a48-a960-c666-b0ea187ecdcc@users.sourceforge.net \
    --to=elfring@users.sourceforge.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=shuah@kernel.org \
    --cc=valentina.manea.m@gmail.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