All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] mtd: mtdchar.c silence sparse warning
@ 2008-05-15  1:22 Harvey Harrison
  2008-05-15  1:38 ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Harvey Harrison @ 2008-05-15  1:22 UTC (permalink / raw)
  To: David Woodhouse; +Cc: Andrew Morton, Al Viro, LKML

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;
 
-- 
1.5.5.1.482.g0f174



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] mtd: mtdchar.c silence sparse warning
  2008-05-15  1:22 [PATCH 1/2] mtd: mtdchar.c silence sparse warning Harvey Harrison
@ 2008-05-15  1:38 ` Andrew Morton
  2008-05-15  1:46   ` Al Viro
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2008-05-15  1:38 UTC (permalink / raw)
  To: Harvey Harrison; +Cc: David Woodhouse, Al Viro, LKML

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).

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] mtd: mtdchar.c silence sparse warning
  2008-05-15  1:38 ` Andrew Morton
@ 2008-05-15  1:46   ` Al Viro
  0 siblings, 0 replies; 3+ messages in thread
From: Al Viro @ 2008-05-15  1:46 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Harvey Harrison, David Woodhouse, LKML

On Wed, May 14, 2008 at 06:38:37PM -0700, Andrew Morton wrote:
> > -		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, ...

Yup.  BTW, &((type __user *)p)->field) would work just fine too, but yeah,
local variable like that would be cleaner.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-05-15  1:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-15  1:22 [PATCH 1/2] mtd: mtdchar.c silence sparse warning Harvey Harrison
2008-05-15  1:38 ` Andrew Morton
2008-05-15  1:46   ` Al Viro

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.