The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Harvey Harrison <harvey.harrison@gmail.com>
Cc: David Woodhouse <dwmw2@infradead.org>,
	Al Viro <viro@ZenIV.linux.org.uk>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/2] mtd: mtdchar.c silence sparse warning
Date: Wed, 14 May 2008 18:38:37 -0700	[thread overview]
Message-ID: <20080514183837.460ba848.akpm@linux-foundation.org> (raw)
In-Reply-To: <1210814530.6191.52.camel@brick>

On Wed, 14 May 2008 18:22:10 -0700 Harvey Harrison <harvey.harrison@gmail.com> wrote:

> The copy_to_user was casting away the address space to get the offset
> of the length member.  Use offsetof() instead and add it to the void __user *argp.
> 
> drivers/mtd/mtdchar.c:527:23: warning: cast removes address space of expression
> drivers/mtd/mtdchar.c:527:23: warning: incorrect type in argument 1 (different address spaces)
> drivers/mtd/mtdchar.c:527:23:    expected void [noderef] <asn:1>*to
> drivers/mtd/mtdchar.c:527:23:    got unsigned int *<noident>
> 
> Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
> ---
>  drivers/mtd/mtdchar.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
> index 5d3ac51..3522d4a 100644
> --- a/drivers/mtd/mtdchar.c
> +++ b/drivers/mtd/mtdchar.c
> @@ -524,7 +524,7 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
>  		if (ops.oobretlen > 0xFFFFFFFFU)
>  			ret = -EOVERFLOW;
>  		retlen = ops.oobretlen;
> -		if (copy_to_user(&((struct mtd_oob_buf *)argp)->length,
> +		if (copy_to_user(argp + offsetof(struct mtd_oob_buf, length),
>  				 &retlen, sizeof(buf.length)))
>  			ret = -EFAULT;

Cleaner would be:

	struct mtd_oob_buf __user *user_mtd_oob_buf = argp;

	if (copy_to_user(&user_mtd_oob_buf->length, ...

?

(cleaner, faster and shorter would be put_user(), but that's off-topic).

  reply	other threads:[~2008-05-15  1:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-15  1:22 [PATCH 1/2] mtd: mtdchar.c silence sparse warning Harvey Harrison
2008-05-15  1:38 ` Andrew Morton [this message]
2008-05-15  1:46   ` Al Viro

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=20080514183837.460ba848.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=dwmw2@infradead.org \
    --cc=harvey.harrison@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@ZenIV.linux.org.uk \
    /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