All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ioannis Valasakis <code@wizofe.uk>
To: outreachy-kernel@googlegroups.com
Cc: gregkh@linuxfoundation.org, rspringer@google.com
Subject: [PATCH] staging: gasket Create a memory allocation path
Date: Mon, 29 Oct 2018 14:07:31 +0000	[thread overview]
Message-ID: <20181029140731.GA18826@kvasir.local> (raw)

toddpoynor@google.com, benchan@chromium.org
Bcc: 
Subject: [PATCH] staging: gasket: Create a memory allocation  error handling
 path
Reply-To: 

Create an error handling path for memory allocation. It avoid repeating
the same assignments and returns the respective ENOMEM.

Signed-off-by: Ioannis Valasakis <code@wizofe.uk>
---
 drivers/staging/gasket/gasket_interrupt.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/gasket/gasket_interrupt.c b/drivers/staging/gasket/gasket_interrupt.c
index 1cfbc120f228..cdfb72af1c52 100644
--- a/drivers/staging/gasket/gasket_interrupt.c
+++ b/drivers/staging/gasket/gasket_interrupt.c
@@ -348,27 +348,21 @@ int gasket_interrupt_init(struct gasket_dev *gasket_dev, const char *name,
 					       sizeof(struct msix_entry),
 					       GFP_KERNEL);
 	if (!interrupt_data->msix_entries) {
-		kfree(interrupt_data);
-		return -ENOMEM;
+		goto err_alloc;
 	}
 
 	interrupt_data->eventfd_ctxs = kcalloc(num_interrupts,
 					       sizeof(struct eventfd_ctx *),
 					       GFP_KERNEL);
 	if (!interrupt_data->eventfd_ctxs) {
-		kfree(interrupt_data->msix_entries);
-		kfree(interrupt_data);
-		return -ENOMEM;
+		goto err_alloc;
 	}
 
 	interrupt_data->interrupt_counts = kcalloc(num_interrupts,
 						   sizeof(ulong),
 						   GFP_KERNEL);
 	if (!interrupt_data->interrupt_counts) {
-		kfree(interrupt_data->eventfd_ctxs);
-		kfree(interrupt_data->msix_entries);
-		kfree(interrupt_data);
-		return -ENOMEM;
+		goto err_alloc;
 	}
 
 	switch (interrupt_data->type) {
@@ -402,6 +396,12 @@ int gasket_interrupt_init(struct gasket_dev *gasket_dev, const char *name,
 				    interrupt_sysfs_attrs);
 
 	return 0;
+
+err_alloc:
+	kfree(interrupt_data);
+	kfree(interrupt_data->msix_entries);
+	kfree(interrupt_data->eventfd_ctxs);
+	return -ENOMEM;
 }
 
 static void
-- 
2.19.1




             reply	other threads:[~2018-10-29 14:07 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-29 14:07 Ioannis Valasakis [this message]
2018-10-29 14:09 ` [Outreachy kernel] [PATCH] staging: gasket Create a memory allocation path Vaishali Thakkar
2018-10-29 14:14 ` Julia Lawall
2018-10-29 21:31   ` Sasha Levin
2018-10-29 14:31 ` Greg KH
2018-10-30 13:41   ` Ioannis Valasakis

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=20181029140731.GA18826@kvasir.local \
    --to=code@wizofe.uk \
    --cc=gregkh@linuxfoundation.org \
    --cc=outreachy-kernel@googlegroups.com \
    --cc=rspringer@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.