linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] platform/x86: surface3-wmi: Balance locking on error path
@ 2016-12-15  1:24 Andy Shevchenko
  2016-12-15  6:38 ` Darren Hart
  2016-12-15  8:14 ` Benjamin Tissoires
  0 siblings, 2 replies; 4+ messages in thread
From: Andy Shevchenko @ 2016-12-15  1:24 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andy Shevchenko, Benjamin Tissoires, Darren Hart,
	open list:X86 PLATFORM DRIVERS

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

Reported-by: kbuild test robot <lkp@intel.com>
Cc: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/platform/x86/surface3-wmi.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/platform/x86/surface3-wmi.c b/drivers/platform/x86/surface3-wmi.c
index 5553b2b85e0a..ed7a3b77a0cc 100644
--- a/drivers/platform/x86/surface3-wmi.c
+++ b/drivers/platform/x86/surface3-wmi.c
@@ -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)
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/1] platform/x86: surface3-wmi: Balance locking on error path
  2016-12-15  1:24 [PATCH 1/1] platform/x86: surface3-wmi: Balance locking on error path Andy Shevchenko
@ 2016-12-15  6:38 ` Darren Hart
  2016-12-15  8:14 ` Benjamin Tissoires
  1 sibling, 0 replies; 4+ messages in thread
From: Darren Hart @ 2016-12-15  6:38 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: linux-kernel, Benjamin Tissoires, open list:X86 PLATFORM DRIVERS

On Thu, Dec 15, 2016 at 03:24:58AM +0200, Andy Shevchenko wrote:
> There is a possibility that lock will be left acquired.
> Consolidate error path under out_free_unlock label.
> 
> Reported-by: kbuild test robot <lkp@intel.com>
> Cc: Benjamin Tissoires <benjamin.tissoires@redhat.com>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/platform/x86/surface3-wmi.c | 11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/platform/x86/surface3-wmi.c b/drivers/platform/x86/surface3-wmi.c
> index 5553b2b85e0a..ed7a3b77a0cc 100644
> --- a/drivers/platform/x86/surface3-wmi.c
> +++ b/drivers/platform/x86/surface3-wmi.c
> @@ -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.

>  
>  	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:

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,

-- 
Darren Hart
Intel Open Source Technology Center

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/1] platform/x86: surface3-wmi: Balance locking on error path
  2016-12-15  1:24 [PATCH 1/1] platform/x86: surface3-wmi: Balance locking on error path Andy Shevchenko
  2016-12-15  6:38 ` Darren Hart
@ 2016-12-15  8:14 ` Benjamin Tissoires
  1 sibling, 0 replies; 4+ messages in thread
From: Benjamin Tissoires @ 2016-12-15  8:14 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: linux-kernel, Darren Hart, open list:X86 PLATFORM DRIVERS

On Dec 15 2016 or thereabouts, Andy Shevchenko wrote:
> There is a possibility that lock will be left acquired.
> Consolidate error path under out_free_unlock label.
> 
> Reported-by: kbuild test robot <lkp@intel.com>
> Cc: Benjamin Tissoires <benjamin.tissoires@redhat.com>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

With Darren's remarks, the patch is:
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>

Sorry for missing this out in the first place.

Cheers,
Benjamin

> ---
>  drivers/platform/x86/surface3-wmi.c | 11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/platform/x86/surface3-wmi.c b/drivers/platform/x86/surface3-wmi.c
> index 5553b2b85e0a..ed7a3b77a0cc 100644
> --- a/drivers/platform/x86/surface3-wmi.c
> +++ b/drivers/platform/x86/surface3-wmi.c
> @@ -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)
> -- 
> 2.11.0
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/1] platform/x86: surface3-wmi: Balance locking on error path
@ 2016-12-15  1:26 Andy Shevchenko
  0 siblings, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2016-12-15  1:26 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andy Shevchenko, Benjamin Tissoires, Darren Hart, platform-driver-x86

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

Reported-by: kbuild test robot <lkp@intel.com>
Cc: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/platform/x86/surface3-wmi.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/platform/x86/surface3-wmi.c b/drivers/platform/x86/surface3-wmi.c
index 5553b2b85e0a..ed7a3b77a0cc 100644
--- a/drivers/platform/x86/surface3-wmi.c
+++ b/drivers/platform/x86/surface3-wmi.c
@@ -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)
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-12-15  8:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-15  1:24 [PATCH 1/1] platform/x86: surface3-wmi: Balance locking on error path Andy Shevchenko
2016-12-15  6:38 ` Darren Hart
2016-12-15  8:14 ` Benjamin Tissoires
2016-12-15  1:26 Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).