Skip to contentSkip to conversation

drivers/acpi/ec.c fix a small memory leak

PATCH NAK Darren Jenkins 4 participants 5 messages Feb 2, 2010 – Feb 3, 2010

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

PATCH 1/1 drivers/acpi/ec.c fix a small memory leak

Plug a very small leak in acpi_ec_ecdt_probe()

Coverity CID: 13319

acpi/ec.c +3 -1
index d6471bb..13061dc 100644
@@ -1009,8 +1009,10 @@ int __init acpi_ec_ecdt_probe(void)
 	/* fall through */
 	}
 
-	if (EC_FLAGS_SKIP_DSDT_SCAN)
+	if (EC_FLAGS_SKIP_DSDT_SCAN) {
+		kfree(saved_ec);
 		return -ENODEV;
+	}
 
 	/* This workaround is needed only on some broken machines,
 	 * which require early EC, but fail to provide ECDT */
#1 lore raw

NAK

saved_ec is allocated if flag EC_FLAGS_VALIDATE_ECDT is true. EC_FLAGS_SKIP_DSDT_SCAN have no sense in such case, thus this new code path is never executed.
On the other hand, unconditionally freeing pointer, which is might be NULL, is not right either.
So, this patch introduced more problems as it tries to solve...

Regards,
Alex.

Darren Jenkins пишет:

Quoted 24 lines

Plug a very small leak in acpi_ec_ecdt_probe()

Coverity CID: 13319

acpi/ec.c +3 -1
index d6471bb..13061dc 100644
@@ -1009,8 +1009,10 @@ int __init acpi_ec_ecdt_probe(void)
 	/* fall through */
 	}
 
-	if (EC_FLAGS_SKIP_DSDT_SCAN)
+	if (EC_FLAGS_SKIP_DSDT_SCAN) {
+		kfree(saved_ec);
 		return -ENODEV;
+	}
 
 	/* This workaround is needed only on some broken machines,
 	 * which require early EC, but fail to provide ECDT */
#2 lore raw
Quoted 7 lines · Alexey Starikovskiy

NAK

saved_ec is allocated if flag EC_FLAGS_VALIDATE_ECDT is true. EC_FLAGS_SKIP_DSDT_SCAN have no sense in such case, thus this new code path is never executed.
On the other hand, unconditionally freeing pointer, which is might be NULL, is not right either.

As near as I can tell you are right that the code cannot leak memory. But Darren is right to think that it's calling kfree() on a NULL pointer is OK. His patch does not introduce any errors.

The logic here is basically spaghetti. Every person who looks at it is going to think it's a leak. Lots of people are going to look at it, because the static checkers all think it's a leak too. Someone could send a cleanup patch that makes it readable.

regards,
dan carpenter

Quoted 35 lines

So, this patch introduced more problems as it tries to solve...

Regards,
Alex.

Darren Jenkins пишет:

Quoted 14 lines

Plug a very small leak in acpi_ec_ecdt_probe()

Coverity CID: 13319

acpi/ec.c +0 -0
index d6471bb..13061dc 100644
@@ -1009,8 +1009,10 @@ int __init acpi_ec_ecdt_probe(void)
 	/* fall through */

acpi/ec.c int __init acpi_ec_ecdt_probe(void) · line 1018

Quoted 10 lines
acpi/ec.c +3 -1
 	}
 
-	if (EC_FLAGS_SKIP_DSDT_SCAN)
+	if (EC_FLAGS_SKIP_DSDT_SCAN) {
+		kfree(saved_ec);
 		return -ENODEV;
+	}
 
 	/* This workaround is needed only on some broken machines,
 	 * which require early EC, but fail to provide ECDT */

--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw
In reply to Alexey Starikovskiy
Quoted 7 lines · Alexey Starikovskiy

NAK

saved_ec is allocated if flag EC_FLAGS_VALIDATE_ECDT is true. EC_FLAGS_SKIP_DSDT_SCAN have no sense in such case, thus this new code path is never executed.
On the other hand, unconditionally freeing pointer, which is might be NULL, is not right either.

Why that?
"kfree(NULL);" works (and in the user-space "free(NULL)" too FWIW).

Quoted 1 line

So, this patch introduced more problems as it tries to solve...

Bernd

Signature · 2 lines
Bernd Petrovitsch                  Email : [email protected]
                     LUGA : http://www.luga.at
#4 lore raw
In reply to Alexey Starikovskiy

Hello Alexey,

Quoted 5 lines · Alexey Starikovskiy

NAK

saved_ec is allocated if flag EC_FLAGS_VALIDATE_ECDT is true. EC_FLAGS_SKIP_DSDT_SCAN have no sense in such case, thus this new code path is never executed.

From what I can tell this is not guaranteed by the code, it is relying on DMI data not matching two of the stings at once.
However I don't know anything about DMI, so if you say this makes no sense and will never happen I am happy.

I will mark this as ignore in the Coverity databse.

Quoted 2 lines

On the other hand, unconditionally freeing pointer, which is might be NULL, is not right either.

Nowadays this is the preferred method actually.

Quoted 2 lines

Regards,
Alex.

Thanks for the feedback.

Darren J