[PATCH v2] i2c-core: One function call less in acpi_i2c_space_handler() after error detection

From: SF Markus Elfring
Date: Sat Dec 26 2015 - 02:09:32 EST


From: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 26 Dec 2015 08:00:52 +0100

The kfree() function was called in one case by the
acpi_i2c_space_handler() function during error handling
even if the passed variable "client" contained a null pointer.

Implementation details could be improved by the adjustment of jump targets
according to the Linux coding style convention.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
---
drivers/i2c/i2c-core.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 7349b00..9996531 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -313,18 +313,18 @@ acpi_i2c_space_handler(u32 function, acpi_physical_address command,
client = kzalloc(sizeof(*client), GFP_KERNEL);
if (!client) {
ret = AE_NO_MEMORY;
- goto err;
+ goto free_ares;
}

if (!value64 || ares->type != ACPI_RESOURCE_TYPE_SERIAL_BUS) {
ret = AE_BAD_PARAMETER;
- goto err;
+ goto free_client;
}

sb = &ares->data.i2c_serial_bus;
if (sb->type != ACPI_RESOURCE_SERIAL_TYPE_I2C) {
ret = AE_BAD_PARAMETER;
- goto err;
+ goto free_client;
}

client->adapter = adapter;
@@ -401,13 +401,13 @@ acpi_i2c_space_handler(u32 function, acpi_physical_address command,
default:
pr_info("protocol(0x%02x) is not supported.\n", accessor_type);
ret = AE_BAD_PARAMETER;
- goto err;
+ goto free_client;
}

gsb->status = status;
-
- err:
+free_client:
kfree(client);
+free_ares:
ACPI_FREE(ares);
return ret;
}
--
2.6.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/