Skip to contentSkip to conversation

platform/x86: surface3-wmi: Balance locking on error path

PATCH In review Andy Shevchenko 3 participants 3 messages Dec 15, 2016 x86 platform drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 platform/x86: surface3-wmi: Balance locking on error path

There is a possibility that lock will be left acquired. Consolidate error path under out_free_unlock label.

---
 drivers/platform/x86/surface3-wmi.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/platform/x86/surface3-wmi.c +6 -5
index 5553b2b85e0a..ed7a3b77a0cc 100644
@@ -60,10 +60,10 @@ static DEFINE_MUTEX(s3_wmi_lock);
 
 static int s3_wmi_query_block(const char *guid, int instance, int *ret)
 {
+	struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
 	acpi_status status;
 	union acpi_object *obj;
-
-	struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
+	int error = 0;
 
 	mutex_lock(&s3_wmi_lock);
 	status = wmi_query_block(guid, instance, &output);
@@ -77,13 +77,14 @@ static int s3_wmi_query_block(const char *guid, int instance, int *ret)
 			       obj->type == ACPI_TYPE_BUFFER ?
 						obj->buffer.length : 0);
 		}
-		kfree(obj);
-		return -EINVAL;
+		error = -EINVAL;
+		goto out_free_unlock;
 	}
 	*ret = obj->integer.value;
+out_free_unlock:
 	kfree(obj);
 	mutex_unlock(&s3_wmi_lock);
-	return 0;
+	return error;
 }
 
 static inline int s3_wmi_query_lid(int *ret)
Signature · 1 line
2.11.0
#1 lore raw
Quoted 15 lines · Andy Shevchenko

There is a possibility that lock will be left acquired. Consolidate error path under out_free_unlock label.

---
 drivers/platform/x86/surface3-wmi.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/platform/x86/surface3-wmi.c +0 -0
index 5553b2b85e0a..ed7a3b77a0cc 100644

drivers/platform/x86/surface3-wmi.c static DEFINE_MUTEX(s3_wmi_lock); · line 66

Quoted 9 lines
drivers/platform/x86/surface3-wmi.c +2 -2
@@ -60,10 +60,10 @@ static DEFINE_MUTEX(s3_wmi_lock);
 
 static int s3_wmi_query_block(const char *guid, int instance, int *ret)
 {
+	struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
 	acpi_status status;
 	union acpi_object *obj;
-
-	struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
+	int error = 0;

I'd prefer ret throughout for consistency with the kernel in general, but as error is used already, it's better to be self-consistent.

Quoted 4 lines
drivers/platform/x86/surface3-wmi.c +0 -0
 	mutex_lock(&s3_wmi_lock);
 	status = wmi_query_block(guid, instance, &output);

drivers/platform/x86/surface3-wmi.c static int s3_wmi_query_block(const char *guid, int instance, int *ret) · line 84

Quoted 10 lines
drivers/platform/x86/surface3-wmi.c +3 -2
@@ -77,13 +77,14 @@ static int s3_wmi_query_block(const char *guid, int instance, int *ret)
 			       obj->type == ACPI_TYPE_BUFFER ?
 						obj->buffer.length : 0);
 		}
-		kfree(obj);
-		return -EINVAL;
+		error = -EINVAL;
+		goto out_free_unlock;
 	}
 	*ret = obj->integer.value;
+out_free_unlock:

Please lead labels with a space:

out_free_unlock:

This makes diffs a bit nicer as the label isn't used in lieu of the function name. This is also consistent with the rest of the file.

Thanks,

Signature · 2 lines
Darren Hart
Intel Open Source Technology Center
Reviewed-by on v1 1/1
#2 lore raw
In reply to Andy Shevchenko
Quoted 6 lines · Andy Shevchenko

There is a possibility that lock will be left acquired. Consolidate error path under out_free_unlock label.

With Darren's remarks, the patch is:

Sorry for missing this out in the first place.

Cheers,
Benjamin

Quoted 42 lines
---
 drivers/platform/x86/surface3-wmi.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/platform/x86/surface3-wmi.c +6 -5
index 5553b2b85e0a..ed7a3b77a0cc 100644
@@ -60,10 +60,10 @@ static DEFINE_MUTEX(s3_wmi_lock);
 
 static int s3_wmi_query_block(const char *guid, int instance, int *ret)
 {
+	struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
 	acpi_status status;
 	union acpi_object *obj;
-
-	struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
+	int error = 0;
 
 	mutex_lock(&s3_wmi_lock);
 	status = wmi_query_block(guid, instance, &output);
@@ -77,13 +77,14 @@ static int s3_wmi_query_block(const char *guid, int instance, int *ret)
 			       obj->type == ACPI_TYPE_BUFFER ?
 						obj->buffer.length : 0);
 		}
-		kfree(obj);
-		return -EINVAL;
+		error = -EINVAL;
+		goto out_free_unlock;
 	}
 	*ret = obj->integer.value;
+out_free_unlock:
 	kfree(obj);
 	mutex_unlock(&s3_wmi_lock);
-	return 0;
+	return error;
 }
 
 static inline int s3_wmi_query_lid(int *ret)
Signature · 1 line
2.11.0