Skip to contentSkip to conversation

staging: gasket: Create a free memory error path

PATCH In review Ioannis Valasakis 2 participants 2 messages Nov 1, 2018 – Nov 5, 2018 Staging

lore
Share & tools
lore
#0 lore raw

PATCH v6 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 v5:
- Correct label names to reflect freed 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..4dbcac4c8e22 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_data;
 	}
 
 	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_eventfd;
 	}
 
 	switch (interrupt_data->type) {
@@ -379,6 +376,12 @@ int gasket_interrupt_init(struct gasket_dev *gasket_dev)
 				    interrupt_sysfs_attrs);
 
 	return 0;
+
+err_free_eventfd:
+	kfree(interrupt_data->eventfd_ctxs);
+err_free_data:
+	kfree(interrupt_data);
+	return -ENOMEM;
 }
 
 static void
Signature · 1 line
2.19.1
maintainer
#1 lore raw
Quoted 7 lines · Ioannis Valasakis

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

---
Changes in v5:
- Correct label names to reflect freed memory

This is v6, what changed here?

And what about all of the previous versions, what was their history? No need to drop it, putting it here is good to see.

v7? :)

thanks,

greg k-h