Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1563070 > unrolled thread

[PATCH] powerpc/rtas_flash: Move an assignment for the variable "rc" in manage_flash_write()

Started bySF Markus Elfring <elfring@users.sourceforge.net>
First post2017-01-19 21:50 +0100
Last post2017-01-20 01:40 +0100
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] powerpc/rtas_flash: Move an assignment for the variable "rc"  in manage_flash_write() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-19 21:50 +0100
    Re: [PATCH] powerpc/rtas_flash: Move an assignment for the variable  "rc" in manage_flash_write() Tyrel Datwyler <tyreld@linux.vnet.ibm.com> - 2017-01-20 01:40 +0100

#1563070 — [PATCH] powerpc/rtas_flash: Move an assignment for the variable "rc" in manage_flash_write()

FromSF Markus Elfring <elfring@users.sourceforge.net>
Date2017-01-19 21:50 +0100
Subject[PATCH] powerpc/rtas_flash: Move an assignment for the variable "rc" in manage_flash_write()
Message-ID<t1rOG-6hY-3@gated-at.bofh.it>
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 19 Jan 2017 21:20:09 +0100

A local variable was set to an error code before a concrete error situation
was detected. Thus move the corresponding assignment into an if branch
to indicate a software failure there.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 arch/powerpc/kernel/rtas_flash.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kernel/rtas_flash.c b/arch/powerpc/kernel/rtas_flash.c
index db2b482af658..663904beff67 100644
--- a/arch/powerpc/kernel/rtas_flash.c
+++ b/arch/powerpc/kernel/rtas_flash.c
@@ -419,9 +419,10 @@ static ssize_t manage_flash_write(struct file *file, const char __user *buf,
 	op = -1;
 	if (buf) {
 		if (count > 9) count = 9;
-		rc = -EFAULT;
-		if (copy_from_user (stkbuf, buf, count))
+		if (copy_from_user(stkbuf, buf, count)) {
+			rc = -EFAULT;
 			goto error;
+		}
 		if (strncmp(stkbuf, reject_str, strlen(reject_str)) == 0) 
 			op = RTAS_REJECT_TMP_IMG;
 		else if (strncmp(stkbuf, commit_str, strlen(commit_str)) == 0) 
-- 
2.11.0

[toc] | [next] | [standalone]


#1563221 — Re: [PATCH] powerpc/rtas_flash: Move an assignment for the variable "rc" in manage_flash_write()

FromTyrel Datwyler <tyreld@linux.vnet.ibm.com>
Date2017-01-20 01:40 +0100
SubjectRe: [PATCH] powerpc/rtas_flash: Move an assignment for the variable "rc" in manage_flash_write()
Message-ID<t1vpf-bo-9@gated-at.bofh.it>
In reply to#1563070
On 01/19/2017 12:33 PM, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Thu, 19 Jan 2017 21:20:09 +0100
> 
> A local variable was set to an error code before a concrete error situation
> was detected. Thus move the corresponding assignment into an if branch
> to indicate a software failure there.
> 
> This issue was detected by using the Coccinelle software.
> 
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
>  arch/powerpc/kernel/rtas_flash.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/powerpc/kernel/rtas_flash.c b/arch/powerpc/kernel/rtas_flash.c
> index db2b482af658..663904beff67 100644
> --- a/arch/powerpc/kernel/rtas_flash.c
> +++ b/arch/powerpc/kernel/rtas_flash.c
> @@ -419,9 +419,10 @@ static ssize_t manage_flash_write(struct file *file, const char __user *buf,
>  	op = -1;
>  	if (buf) {
>  		if (count > 9) count = 9;
> -		rc = -EFAULT;
> -		if (copy_from_user (stkbuf, buf, count))
> +		if (copy_from_user(stkbuf, buf, count)) {
> +			rc = -EFAULT;
>  			goto error;
> +		}
>  		if (strncmp(stkbuf, reject_str, strlen(reject_str)) == 0) 
>  			op = RTAS_REJECT_TMP_IMG;
>  		else if (strncmp(stkbuf, commit_str, strlen(commit_str)) == 0) 
> 

Taking a closer look at the function in question I see that branching to
the "error" tag on a goto results in the rtas_manage_flash_mutex being
unlocked and the value of rc being returned to the caller.

error:
        mutex_unlock(&rtas_manage_flash_mutex);
        return rc;
}

There are only 2 places in this function that branch to the "error" tag,
and I wonder if it would be cleaner just to get rid of the "rc" variable
altogether and instead unlock the mutex and return the proper -EBADTHING
value at those two branch sites?

-Tyrel

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web