Skip to contentSkip to conversation

platform/x86: x86-android-tablets: Fix GPIO lookup leak on error-exit

PATCH In review Hans de Goede 1 participant 2 messages Jan 8, 2022 x86 platform drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 platform/x86: x86-android-tablets: Fix GPIO lookup leak on error-exit

Fix leaking the registered gpiod_lookup tables when the kcalloc() for the i2c_clients array fails.

Fixes ef2ac11493e2 ("platform/x86: x86-android-tablets: Add support for registering GPIO lookup tables")
---
 drivers/platform/x86/x86-android-tablets.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/platform/x86/x86-android-tablets.c +3 -1
index d39da5fca6c5..3ba63ad91b28 100644
@@ -815,8 +815,10 @@ static __init int x86_android_tablet_init(void)
 		gpiod_add_lookup_table(gpiod_lookup_tables[i]);
 
 	i2c_clients = kcalloc(dev_info->i2c_client_count, sizeof(*i2c_clients), GFP_KERNEL);
-	if (!i2c_clients)
+	if (!i2c_clients) {
+		x86_android_tablet_cleanup();
 		return -ENOMEM;
+	}
 
 	i2c_client_count = dev_info->i2c_client_count;
 	for (i = 0; i < i2c_client_count; i++) {
Signature · 1 line
2.33.1
#1 lore raw

Hi,

Quoted 5 lines · Hans de Goede

Fix leaking the registered gpiod_lookup tables when the kcalloc() for the i2c_clients array fails.

Fixes ef2ac11493e2 ("platform/x86: x86-android-tablets: Add support for registering GPIO lookup tables")

I've added this to my review-hans (soon to be for-next) branch now.

Regards,

Hans

Quoted 21 lines
---
 drivers/platform/x86/x86-android-tablets.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/platform/x86/x86-android-tablets.c +3 -1
index d39da5fca6c5..3ba63ad91b28 100644
@@ -815,8 +815,10 @@ static __init int x86_android_tablet_init(void)
 		gpiod_add_lookup_table(gpiod_lookup_tables[i]);
 
 	i2c_clients = kcalloc(dev_info->i2c_client_count, sizeof(*i2c_clients), GFP_KERNEL);
-	if (!i2c_clients)
+	if (!i2c_clients) {
+		x86_android_tablet_cleanup();
 		return -ENOMEM;
+	}
 
 	i2c_client_count = dev_info->i2c_client_count;
 	for (i = 0; i < i2c_client_count; i++) {