Skip to contentSkip to conversation

dio: return -ENOMEM when kzalloc() fails

PATCH In review Salah Triki 2 participants 2 messages Jul 2, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dio: return -ENOMEM when kzalloc() fails

Return -ENOMEM when kzalloc() fails in order to inform the caller of the failure.

---
 drivers/dio/dio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dio/dio.c +1 -1
index 193b40e7aec0..4c06c93c93d3 100644
@@ -219,7 +219,7 @@ static int __init dio_init(void)
                 /* Found a board, allocate it an entry in the list */
 		dev = kzalloc(sizeof(struct dio_dev), GFP_KERNEL);
 		if (!dev)
-			return 0;
+			return -ENOMEM;
 
 		dev->bus = &dio_bus;
 		dev->dev.parent = &dio_bus.dev;
Signature · 1 line
2.25.1
#1 lore raw
Quoted 13 lines · Salah Triki

Return -ENOMEM when kzalloc() fails in order to inform the caller of the failure.

---
 drivers/dio/dio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dio/dio.c +0 -0
index 193b40e7aec0..4c06c93c93d3 100644

drivers/dio/dio.c static int __init dio_init(void) · line 222

Quoted 5 lines
drivers/dio/dio.c +1 -1
@@ -219,7 +219,7 @@ static int __init dio_init(void)
                 /* Found a board, allocate it an entry in the list */
 		dev = kzalloc(sizeof(struct dio_dev), GFP_KERNEL);
 		if (!dev)
-			return 0;
+			return -ENOMEM;

Do you have this hardware to test with?

While this patch looks correct, it still is leaking lots of resources if this every happens. Can you fix this up "properly" so that all of the resources allocated at this point in time will be correctly freed?

Or, really, this is an impossible error path to hit, given that it is at boot time, so maybe it's just not worth it given that I doubt anyone has this hardware...

thanks,

greg k-h