All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] staging: gasket Create a memory allocation path
@ 2018-10-29 14:07 Ioannis Valasakis
  2018-10-29 14:09 ` [Outreachy kernel] " Vaishali Thakkar
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Ioannis Valasakis @ 2018-10-29 14:07 UTC (permalink / raw)
  To: outreachy-kernel; +Cc: gregkh, rspringer

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




^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-10-30 13:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-10-29 14:07 [PATCH] staging: gasket Create a memory allocation path Ioannis Valasakis
2018-10-29 14:09 ` [Outreachy kernel] " 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

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.