mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Jörn Engel" <joern@wohnheim.fh-wedel.de>
To: "Randy.Dunlap" <rddunlap@osdl.org>
Cc: lkml <linux-kernel@vger.kernel.org>, arrays@hp.com, steve.cameron@hp.com
Subject: Re: [PATCH] reduce stack in cpqarray.c::ida_ioctl()
Date: Fri, 4 Apr 2003 02:30:44 +0200	[thread overview]
Message-ID: <20030404003044.GB16832@wohnheim.fh-wedel.de> (raw)
In-Reply-To: <20030403120308.620e5a14.rddunlap@osdl.org>

On Thu, 3 April 2003 12:03:08 +0000, Randy.Dunlap wrote:
> 
> Comments on the patch?

Your patch looks just fine. The original code is a bit odd, though.
If you want to change that in one go, read on. If not, please ignore
this.

> diff -Naur ./drivers/block/cpqarray.c%IDAIOC ./drivers/block/cpqarray.c
> --- ./drivers/block/cpqarray.c%IDAIOC	2003-03-24 14:00:03.000000000 -0800
> +++ ./drivers/block/cpqarray.c	2003-04-02 20:05:57.000000000 -0800
> @@ -1021,7 +1021,7 @@
>  	int diskinfo[4];
>  	struct hd_geometry *geo = (struct hd_geometry *)arg;
>  	ida_ioctl_t *io = (ida_ioctl_t*)arg;
> -	ida_ioctl_t my_io;
> +	ida_ioctl_t *my_io;
>  
>  	switch(cmd) {
>  	case HDIO_GETGEO:
> @@ -1046,11 +1046,19 @@
>  		return 0;
>  	case IDAPASSTHRU:
>  		if (!capable(CAP_SYS_RAWIO)) return -EPERM;
> -		if (copy_from_user(&my_io, io, sizeof(my_io)))
> -			return -EFAULT;
> -		error = ida_ctlr_ioctl(ctlr, dsk, &my_io);
> -		if (error) return error;
> -		return copy_to_user(io, &my_io, sizeof(my_io)) ? -EFAULT : 0;
> +		my_io = kmalloc(sizeof(ida_ioctl_t), GFP_KERNEL);
> +		if (!my_io)
> +			return -ENOMEM;
> +		if (copy_from_user(my_io, io, sizeof(*my_io))) {
> +			error = -EFAULT;
> +			goto iocfree;
> +		}
> +		error = ida_ctlr_ioctl(ctlr, dsk, my_io);
> +		if (error) goto iocfree;

Wouldn't an extra line be nicer?

> +		error = copy_to_user(io, my_io, sizeof(*my_io)) ? -EFAULT : 0;

copy_to_user returns the bytes successfully copied.
error is set to -EFAULT, if there was actually data transferred?

How about:
+		error = copy_to_user(io, my_io, sizeof(*my_io)) < sizeof(*my_io) ? -EFAULT : 0;

> +  iocfree:
> +		kfree(my_io);
> +		return error;
>  	case IDAGETCTLRSIG:
>  		if (!arg) return -EINVAL;
>  		put_user(hba[ctlr]->ctlr_sig, (int*)arg);

Jörn

-- 
Good warriors cause others to come to them and do not go to others.
-- Sun Tzu

  reply	other threads:[~2003-04-04  0:19 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-04-03 12:03 Randy.Dunlap
2003-04-04  0:30 ` Jörn Engel [this message]
2003-04-03 17:33   ` Randy.Dunlap
2003-04-04  7:56     ` Jörn Engel
2003-04-04  8:44       ` Randy.Dunlap
2003-04-04 16:54         ` Jörn Engel
2003-04-04  8:09   ` Jens Axboe
2003-04-04  9:51     ` Jörn Engel
2003-04-03 20:18 Cameron, Steve
2003-04-03 13:21 ` Randy.Dunlap
2003-04-03 21:35 Cameron, Steve

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=20030404003044.GB16832@wohnheim.fh-wedel.de \
    --to=joern@wohnheim.fh-wedel.de \
    --cc=arrays@hp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rddunlap@osdl.org \
    --cc=steve.cameron@hp.com \
    /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

all inboxes | Powered by JetHome®