Re: [patch] unlock_kernel() on error path in sx_fw_ioctl()

From: Andrew Morton
Date: Wed Feb 04 2009 - 00:04:49 EST


On Tue, 3 Feb 2009 11:14:21 +0300 (EAT) Dan Carpenter <error27@xxxxxxxxx> 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@xxxxxxxxx>
>
> --- 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@xxxxxxxxxxxxxxxxxxxx>

fix another such path - missed func_exit().

Cc: Dan Carpenter <error27@xxxxxxxxx>
Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
---

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;
_

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/