diff mbox

[5/6] efi_runtime: add label to reduce the number of kfree

Message ID 1471575460-13421-5-git-send-email-ivan.hu@canonical.com
State Accepted
Headers show

Commit Message

Ivan Hu Aug. 19, 2016, 2:57 a.m. UTC
Signed-off-by: Ivan Hu <ivan.hu@canonical.com>
---
 efi_runtime/efi_runtime.c | 38 ++++++++++++++++++++------------------
 1 file changed, 20 insertions(+), 18 deletions(-)

Comments

Colin Ian King Aug. 19, 2016, 8:01 a.m. UTC | #1
On 19/08/16 03:57, Ivan Hu wrote:
> Signed-off-by: Ivan Hu <ivan.hu@canonical.com>
> ---
>  efi_runtime/efi_runtime.c | 38 ++++++++++++++++++++------------------
>  1 file changed, 20 insertions(+), 18 deletions(-)
> 
> diff --git a/efi_runtime/efi_runtime.c b/efi_runtime/efi_runtime.c
> index ceb655d..6f8e096 100644
> --- a/efi_runtime/efi_runtime.c
> +++ b/efi_runtime/efi_runtime.c
> @@ -255,7 +255,7 @@ static long efi_runtime_set_variable(unsigned long arg)
>  	efi_status_t status;
>  	efi_char16_t *name = NULL;
>  	void *data;
> -	int rv;
> +	int rv = 0;
>  
>  	setvariable_user = (struct efi_setvariable __user *)arg;
>  
> @@ -280,21 +280,26 @@ static long efi_runtime_set_variable(unsigned long arg)
>  	}
>  	if (copy_from_user(data, setvariable.data,
>  			   setvariable.data_size)) {
> -		kfree(data);
> -		kfree(name);
> -		return -EFAULT;
> +		rv = -EFAULT;
> +		goto out;
>  	}
>  
>  	status = efi.set_variable(name, &vendor_guid,
>  				setvariable.attributes,
>  				setvariable.data_size, data);
>  
> +	if (put_user(status, setvariable.status)) {
> +		rv = -EFAULT;
> +		goto out;
> +	}
> +
> +	rv = status == EFI_SUCCESS ? 0 : -EINVAL;
> +
> +out:
>  	kfree(data);
>  	kfree(name);
>  
> -	if (put_user(status, setvariable.status))
> -		return -EFAULT;
> -	return status == EFI_SUCCESS ? 0 : -EINVAL;
> +	return rv;
>  }
>  
>  static long efi_runtime_get_time(unsigned long arg)
> @@ -583,7 +588,7 @@ static long efi_runtime_query_capsulecaps(unsigned long arg)
>  	efi_status_t status;
>  	u64 max_size;
>  	int i, reset_type;
> -	int rv;
> +	int rv = 0;
>  
>  	qcaps_user = (struct efi_querycapsulecapabilities __user *)arg;
>  
> @@ -604,12 +609,12 @@ static long efi_runtime_query_capsulecaps(unsigned long arg)
>  		 */
>  		if (get_user(c, qcaps.capsule_header_array + i)) {
>  			rv = -EFAULT;
> -			goto err_exit;
> +			goto out;
>  		}
>  		if (copy_from_user(&capsules[i], c,
>  				sizeof(efi_capsule_header_t))) {
>  			rv = -EFAULT;
> -			goto err_exit;
> +			goto out;
>  		}
>  	}
>  
> @@ -622,28 +627,25 @@ static long efi_runtime_query_capsulecaps(unsigned long arg)
>  
>  	if (put_user(status, qcaps.status)) {
>  		rv = -EFAULT;
> -		goto err_exit;
> +		goto out;
>  	}
>  
>  	if (put_user(max_size, qcaps.maximum_capsule_size)) {
>  		rv = -EFAULT;
> -		goto err_exit;
> +		goto out;
>  	}
>  
>  	if (put_user(reset_type, qcaps.reset_type)) {
>  		rv = -EFAULT;
> -		goto err_exit;
> +		goto out;
>  	}
>  
>  	if (status != EFI_SUCCESS) {
>  		rv = -EINVAL;
> -		goto err_exit;
> +		goto out;
>  	}
>  
> -	kfree(capsules);
> -	return 0;
> -
> -err_exit:
> +out:
>  	kfree(capsules);
>  	return rv;
>  }
> 
Acked-by: Colin Ian King <colin.king@canonical.com>
Alex Hung Aug. 23, 2016, 1:38 a.m. UTC | #2
On 2016-08-19 10:57 AM, Ivan Hu wrote:
> Signed-off-by: Ivan Hu <ivan.hu@canonical.com>
> ---
>  efi_runtime/efi_runtime.c | 38 ++++++++++++++++++++------------------
>  1 file changed, 20 insertions(+), 18 deletions(-)
>
> diff --git a/efi_runtime/efi_runtime.c b/efi_runtime/efi_runtime.c
> index ceb655d..6f8e096 100644
> --- a/efi_runtime/efi_runtime.c
> +++ b/efi_runtime/efi_runtime.c
> @@ -255,7 +255,7 @@ static long efi_runtime_set_variable(unsigned long arg)
>  	efi_status_t status;
>  	efi_char16_t *name = NULL;
>  	void *data;
> -	int rv;
> +	int rv = 0;
>
>  	setvariable_user = (struct efi_setvariable __user *)arg;
>
> @@ -280,21 +280,26 @@ static long efi_runtime_set_variable(unsigned long arg)
>  	}
>  	if (copy_from_user(data, setvariable.data,
>  			   setvariable.data_size)) {
> -		kfree(data);
> -		kfree(name);
> -		return -EFAULT;
> +		rv = -EFAULT;
> +		goto out;
>  	}
>
>  	status = efi.set_variable(name, &vendor_guid,
>  				setvariable.attributes,
>  				setvariable.data_size, data);
>
> +	if (put_user(status, setvariable.status)) {
> +		rv = -EFAULT;
> +		goto out;
> +	}
> +
> +	rv = status == EFI_SUCCESS ? 0 : -EINVAL;
> +
> +out:
>  	kfree(data);
>  	kfree(name);
>
> -	if (put_user(status, setvariable.status))
> -		return -EFAULT;
> -	return status == EFI_SUCCESS ? 0 : -EINVAL;
> +	return rv;
>  }
>
>  static long efi_runtime_get_time(unsigned long arg)
> @@ -583,7 +588,7 @@ static long efi_runtime_query_capsulecaps(unsigned long arg)
>  	efi_status_t status;
>  	u64 max_size;
>  	int i, reset_type;
> -	int rv;
> +	int rv = 0;
>
>  	qcaps_user = (struct efi_querycapsulecapabilities __user *)arg;
>
> @@ -604,12 +609,12 @@ static long efi_runtime_query_capsulecaps(unsigned long arg)
>  		 */
>  		if (get_user(c, qcaps.capsule_header_array + i)) {
>  			rv = -EFAULT;
> -			goto err_exit;
> +			goto out;
>  		}
>  		if (copy_from_user(&capsules[i], c,
>  				sizeof(efi_capsule_header_t))) {
>  			rv = -EFAULT;
> -			goto err_exit;
> +			goto out;
>  		}
>  	}
>
> @@ -622,28 +627,25 @@ static long efi_runtime_query_capsulecaps(unsigned long arg)
>
>  	if (put_user(status, qcaps.status)) {
>  		rv = -EFAULT;
> -		goto err_exit;
> +		goto out;
>  	}
>
>  	if (put_user(max_size, qcaps.maximum_capsule_size)) {
>  		rv = -EFAULT;
> -		goto err_exit;
> +		goto out;
>  	}
>
>  	if (put_user(reset_type, qcaps.reset_type)) {
>  		rv = -EFAULT;
> -		goto err_exit;
> +		goto out;
>  	}
>
>  	if (status != EFI_SUCCESS) {
>  		rv = -EINVAL;
> -		goto err_exit;
> +		goto out;
>  	}
>
> -	kfree(capsules);
> -	return 0;
> -
> -err_exit:
> +out:
>  	kfree(capsules);
>  	return rv;
>  }
>


Acked-by: Alex Hung <alex.hung@canonical.com>
diff mbox

Patch

diff --git a/efi_runtime/efi_runtime.c b/efi_runtime/efi_runtime.c
index ceb655d..6f8e096 100644
--- a/efi_runtime/efi_runtime.c
+++ b/efi_runtime/efi_runtime.c
@@ -255,7 +255,7 @@  static long efi_runtime_set_variable(unsigned long arg)
 	efi_status_t status;
 	efi_char16_t *name = NULL;
 	void *data;
-	int rv;
+	int rv = 0;
 
 	setvariable_user = (struct efi_setvariable __user *)arg;
 
@@ -280,21 +280,26 @@  static long efi_runtime_set_variable(unsigned long arg)
 	}
 	if (copy_from_user(data, setvariable.data,
 			   setvariable.data_size)) {
-		kfree(data);
-		kfree(name);
-		return -EFAULT;
+		rv = -EFAULT;
+		goto out;
 	}
 
 	status = efi.set_variable(name, &vendor_guid,
 				setvariable.attributes,
 				setvariable.data_size, data);
 
+	if (put_user(status, setvariable.status)) {
+		rv = -EFAULT;
+		goto out;
+	}
+
+	rv = status == EFI_SUCCESS ? 0 : -EINVAL;
+
+out:
 	kfree(data);
 	kfree(name);
 
-	if (put_user(status, setvariable.status))
-		return -EFAULT;
-	return status == EFI_SUCCESS ? 0 : -EINVAL;
+	return rv;
 }
 
 static long efi_runtime_get_time(unsigned long arg)
@@ -583,7 +588,7 @@  static long efi_runtime_query_capsulecaps(unsigned long arg)
 	efi_status_t status;
 	u64 max_size;
 	int i, reset_type;
-	int rv;
+	int rv = 0;
 
 	qcaps_user = (struct efi_querycapsulecapabilities __user *)arg;
 
@@ -604,12 +609,12 @@  static long efi_runtime_query_capsulecaps(unsigned long arg)
 		 */
 		if (get_user(c, qcaps.capsule_header_array + i)) {
 			rv = -EFAULT;
-			goto err_exit;
+			goto out;
 		}
 		if (copy_from_user(&capsules[i], c,
 				sizeof(efi_capsule_header_t))) {
 			rv = -EFAULT;
-			goto err_exit;
+			goto out;
 		}
 	}
 
@@ -622,28 +627,25 @@  static long efi_runtime_query_capsulecaps(unsigned long arg)
 
 	if (put_user(status, qcaps.status)) {
 		rv = -EFAULT;
-		goto err_exit;
+		goto out;
 	}
 
 	if (put_user(max_size, qcaps.maximum_capsule_size)) {
 		rv = -EFAULT;
-		goto err_exit;
+		goto out;
 	}
 
 	if (put_user(reset_type, qcaps.reset_type)) {
 		rv = -EFAULT;
-		goto err_exit;
+		goto out;
 	}
 
 	if (status != EFI_SUCCESS) {
 		rv = -EINVAL;
-		goto err_exit;
+		goto out;
 	}
 
-	kfree(capsules);
-	return 0;
-
-err_exit:
+out:
 	kfree(capsules);
 	return rv;
 }