Skip to contentSkip to conversation

ACPI / LPSS: set an error code

PATCH In review Dan Carpenter 2 participants 3 messages Jul 3, 2015 – Jul 7, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ACPI / LPSS: set an error code

We should return -ENOMEM if ioremap() fails.

Fixes 4483d59e29fe ('ACPI / LPSS: check the result of ioremap()')
drivers/acpi/acpi_lpss.c +3 -1
index 569ee09..10bf5c7 100644
@@ -352,8 +352,10 @@ static int acpi_lpss_create_device(struct acpi_device *adev,
 				pdata->mmio_size = resource_size(rentry->res);
 			pdata->mmio_base = ioremap(rentry->res->start,
 						   pdata->mmio_size);
-			if (!pdata->mmio_base)
+			if (!pdata->mmio_base) {
+				ret = -ENOMEM;
 				goto err_out;
+			}
 			break;
 		}
 
#1 lore raw
Quoted 10 lines · Dan Carpenter

We should return -ENOMEM if ioremap() fails.

Fixes 4483d59e29fe ('ACPI / LPSS: check the result of ioremap()')
drivers/acpi/acpi_lpss.c +0 -0
index 569ee09..10bf5c7 100644

drivers/acpi/acpi_lpss.c static int acpi_lpss_create_device(struct acpi_device *adev, · line 360

Quoted 10 lines
drivers/acpi/acpi_lpss.c +3 -1
@@ -352,8 +352,10 @@ static int acpi_lpss_create_device(struct acpi_device *adev,
 				pdata->mmio_size = resource_size(rentry->res);
 			pdata->mmio_base = ioremap(rentry->res->start,
 						   pdata->mmio_size);
-			if (!pdata->mmio_base)
+			if (!pdata->mmio_base) {
+				ret = -ENOMEM;
 				goto err_out;
+			}
 			break;
 		}

This looks insufficient to my eyes, as we leak memory here too.

What about the following instead?

---
From: Rafael J. Wysocki <[email protected]>
Subject: ACPI / LPSS: Fix up acpi_lpss_create_device()

Fix a return value (which should be a negative error code) and a memory leak (the list allocated by acpi_dev_get_resources() needs to be freed on ioremap() errors too) in acpi_lpss_create_device() introduced by commit 4483d59e29fe 'ACPI / LPSS: check the result of ioremap()'.

Fixes 4483d59e29fe 'ACPI / LPSS: check the result of ioremap()'
Cc 4.0+ <[email protected]> # 4.0+
---
 drivers/acpi/acpi_lpss.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/acpi/acpi_lpss.c +5 -2
Index: linux-pm/drivers/acpi/acpi_lpss.c
===================================================================
@@ -352,13 +352,16 @@ static int acpi_lpss_create_device(struc
 				pdata->mmio_size = resource_size(rentry->res);
 			pdata->mmio_base = ioremap(rentry->res->start,
 						   pdata->mmio_size);
-			if (!pdata->mmio_base)
-				goto err_out;
 			break;
 		}
 
 	acpi_dev_free_resource_list(&resource_list);
 
+	if (!pdata->mmio_base) {
+		ret = -ENOMEM;
+		goto err_out;
+	}
+
 	pdata->dev_desc = dev_desc;
 
 	if (dev_desc->setup)
#2 lore raw
Quoted 3 lines · Rafael J. Wysocki

This looks insufficient to my eyes, as we leak memory here too.

What about the following instead?

Yeah. You are, of course, correct.

regards,
dan carpenter