public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Dan Carpenter <error27@gmail.com>
Cc: R.E.Wolff@BitWizard.nl, linux-kernel@vger.kernel.org
Subject: Re: [patch] unlock_kernel() on error path in sx_fw_ioctl()
Date: Tue, 3 Feb 2009 20:58:57 -0800	[thread overview]
Message-ID: <20090203205857.a2b4b1c1.akpm@linux-foundation.org> (raw)
In-Reply-To: <alpine.DEB.2.00.0902030829580.31813@bikeee>

On Tue, 3 Feb 2009 11:14:21 +0300 (EAT) Dan Carpenter <error27@gmail.com> wrote:

> If we return directly with -EPERM then lock_kernel() is still held.
> 
> This was found with a code checker (http://repo.or.cz/w/smatch.git/). 
> Compile tested only, sorry.
> 
> regards,
> dan carpenter
> 
> Signed-off-by: Dan Carpenter <error27@gmail.com>
> 
> --- orig/drivers/char/sx.c	2009-02-03 08:27:59.000000000 +0300
> +++ devel/drivers/char/sx.c	2009-02-03 08:28:31.000000000 +0300
> @@ -1747,7 +1747,8 @@
>   		break;
>   	case SXIO_DO_RAMTEST:
>   		if (sx_initialized)	/* Already initialized: better not ramtest the board.  */
> -			return -EPERM;
> +			rc = -EPERM;
> +			break;
>   		if (IS_SX_BOARD(board)) {
>   			rc = do_memtest(board, 0, 0x7000);
>   			if (!rc)

Yawn.  return-deep-inside-a-large-function strikes again.

We might as well fix the other one while we're there:

From: Andrew Morton <akpm@linux-foundation.org>

fix another such path - missed func_exit().

Cc: Dan Carpenter <error27@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 drivers/char/sx.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff -puN drivers/char/sx.c~sxc-fix-missed-unlock_kernel-on-error-path-in-sx_fw_ioctl-fix drivers/char/sx.c
--- a/drivers/char/sx.c~sxc-fix-missed-unlock_kernel-on-error-path-in-sx_fw_ioctl-fix
+++ a/drivers/char/sx.c
@@ -1713,8 +1713,8 @@ static long sx_fw_ioctl(struct file *fil
 		for (i = 0; i < SX_NBOARDS; i++)
 			sx_dprintk(SX_DEBUG_FIRMWARE, "<%x> ", boards[i].flags);
 		sx_dprintk(SX_DEBUG_FIRMWARE, "\n");
-		unlock_kernel();
-		return -EIO;
+		rc = -EIO;
+		goto out;
 	}
 
 	switch (cmd) {
@@ -1845,6 +1845,7 @@ static long sx_fw_ioctl(struct file *fil
 		rc = -ENOTTY;
 		break;
 	}
+out:
 	unlock_kernel();
 	func_exit();
 	return rc;
_


  reply	other threads:[~2009-02-04  5:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-03  8:14 [patch] unlock_kernel() on error path in sx_fw_ioctl() Dan Carpenter
2009-02-04  4:58 ` Andrew Morton [this message]
2009-02-04  9:49   ` Rogier Wolff

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090203205857.a2b4b1c1.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=R.E.Wolff@BitWizard.nl \
    --cc=error27@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox