Skip to contentSkip to conversation

staging: gasket: Create a free memory error path

PATCH Superseded Ioannis Valasakis 2 participants 2 messages Oct 31, 2018 Staging

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 staging: gasket: Create a free memory error path

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

---
Changes in v4:
- Rebase against gregkh staging source tree
- Modified the error handling paths to correctly free the respective memory

drivers/staging/gasket/gasket_interrupt.c | 13 ++++++++-----

 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/staging/gasket/gasket_interrupt.c +8 -5
index 49d47afad64f..721d590e7c34 100644
@@ -340,17 +340,14 @@ int gasket_interrupt_init(struct gasket_dev *gasket_dev)
 					       sizeof(struct eventfd_ctx *),
 					       GFP_KERNEL);
 	if (!interrupt_data->eventfd_ctxs) {
-		kfree(interrupt_data);
-		return -ENOMEM;
+		goto err_free_ctxs;
 	}
 
 	interrupt_data->interrupt_counts = kcalloc(driver_desc->num_interrupts,
 						   sizeof(ulong),
 						   GFP_KERNEL);
 	if (!interrupt_data->interrupt_counts) {
-		kfree(interrupt_data->eventfd_ctxs);
-		kfree(interrupt_data);
-		return -ENOMEM;
+		goto err_free_all;
 	}
 
 	switch (interrupt_data->type) {
@@ -379,6 +376,12 @@ int gasket_interrupt_init(struct gasket_dev *gasket_dev)
 				    interrupt_sysfs_attrs);
 
 	return 0;
+
+err_free_counts:
+	kfree(interrupt_data->eventfd_ctxs);
+err_free_ctxs:
+	kfree(interrupt_data);
+	return -ENOMEM;
 }
 
 static void
Signature · 1 line
2.19.1
#1 lore raw
Quoted 24 lines · Ioannis Valasakis

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

---
Changes in v4:
- Rebase against gregkh staging source tree
- Modified the error handling paths to correctly free the respective memory

drivers/staging/gasket/gasket_interrupt.c | 13 ++++++++-----

 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/staging/gasket/gasket_interrupt.c +1 -2
index 49d47afad64f..721d590e7c34 100644
@@ -340,17 +340,14 @@ int gasket_interrupt_init(struct gasket_dev *gasket_dev)
 					       sizeof(struct eventfd_ctx *),
 					       GFP_KERNEL);
 	if (!interrupt_data->eventfd_ctxs) {
-		kfree(interrupt_data);
-		return -ENOMEM;
+		goto err_free_ctxs;

drivers/staging/gasket/gasket_interrupt.c int gasket_interrupt_init(struct gasket_dev *gasket_dev) · line 350

Quoted 10 lines
drivers/staging/gasket/gasket_interrupt.c +1 -3
 	}
 
 	interrupt_data->interrupt_counts = kcalloc(driver_desc->num_interrupts,
 						   sizeof(ulong),
 						   GFP_KERNEL);
 	if (!interrupt_data->interrupt_counts) {
-		kfree(interrupt_data->eventfd_ctxs);
-		kfree(interrupt_data);
-		return -ENOMEM;
+		goto err_free_all;

Does this label exist?

julia

Quoted 27 lines
drivers/staging/gasket/gasket_interrupt.c +6 -1
 	}
 
 	switch (interrupt_data->type) {
@@ -379,6 +376,12 @@ int gasket_interrupt_init(struct gasket_dev *gasket_dev)
 				    interrupt_sysfs_attrs);
 
 	return 0;
+
+err_free_counts:
+	kfree(interrupt_data->eventfd_ctxs);
+err_free_ctxs:
+	kfree(interrupt_data);
+	return -ENOMEM;
 }
 
 static void
--

2.19.1

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20181031212220.GA24472%40kvasir.local.
For more options, visit https://groups.google.com/d/optout.