LKML Archive mirror
 help / color / mirror / Atom feed
* wdt285: fix sparse warnings
@ 2008-09-14 21:34 Ben Dooks
  2008-09-15  8:05 ` Wim Van Sebroeck
  0 siblings, 1 reply; 4+ messages in thread
From: Ben Dooks @ 2008-09-14 21:34 UTC (permalink / raw
  To: linux-kernel, wim; +Cc: Ben Dooks

[-- Attachment #1: simtec/simtec-cats-sparse-wdt285.patch --]
[-- Type: text/plain, Size: 2810 bytes --]

The wdt285.c watchdog driver is producing a number of
sparse errors due to missing __user attributes to calls
to put_user and copy_to_user, as well as in the prototype
of watchdog_write.

wdt285.c:144:21: warning: incorrect type in argument 1 (different address spaces)
wdt285.c:144:21:    expected void [noderef] <asn:1>*to
wdt285.c:144:21:    got void *<noident>
wdt285.c:150:9: warning: incorrect type in initializer (different address spaces)
wdt285.c:150:9:    expected int const [noderef] <asn:1>*register __p
wdt285.c:150:9:    got int *<noident>
wdt285.c:159:9: warning: incorrect type in initializer (different address spaces)
wdt285.c:159:9:    expected int const [noderef] <asn:1>*register __p
wdt285.c:159:9:    got int *<noident>
wdt285.c:174:9: warning: incorrect type in initializer (different address spaces)
wdt285.c:174:9:    expected int const [noderef] <asn:1>*register __p
wdt285.c:174:9:    got int *<noident>
wdt285.c:183:12: warning: incorrect type in initializer (incompatible argument 2 (different address spaces))
wdt285.c:183:12:    expected int ( *write )( ... )
wdt285.c:183:12:    got int ( static [toplevel] *<noident> )( ... )

Signed-off-by: Ben Dooks <ben-linux@fluff.org>

Index: linux-2.6.27-rc6-cats2/drivers/watchdog/wdt285.c
===================================================================
--- linux-2.6.27-rc6-cats2.orig/drivers/watchdog/wdt285.c	2008-09-14 22:29:13.000000000 +0100
+++ linux-2.6.27-rc6-cats2/drivers/watchdog/wdt285.c	2008-09-14 22:31:14.000000000 +0100
@@ -115,8 +115,8 @@ static int watchdog_release(struct inode
 	return 0;
 }
 
-static ssize_t watchdog_write(struct file *file, const char *data,
-						size_t len, loff_t *ppos)
+static ssize_t watchdog_write(struct file *file, const char __user *data,
+			      size_t len, loff_t *ppos)
 {
 	/*
 	 *	Refresh the timer.
@@ -141,13 +141,13 @@ static long watchdog_ioctl(struct file *
 	switch (cmd) {
 	case WDIOC_GETSUPPORT:
 		ret = 0;
-		if (copy_to_user((void *)arg, &ident, sizeof(ident)))
+		if (copy_to_user((void __user *)arg, &ident, sizeof(ident)))
 			ret = -EFAULT;
 		break;
 
 	case WDIOC_GETSTATUS:
 	case WDIOC_GETBOOTSTATUS:
-		ret = put_user(0, (int *)arg);
+		ret = put_user(0, (int __user *)arg);
 		break;
 
 	case WDIOC_KEEPALIVE:
@@ -156,7 +156,7 @@ static long watchdog_ioctl(struct file *
 		break;
 
 	case WDIOC_SETTIMEOUT:
-		ret = get_user(new_margin, (int *)arg);
+		ret = get_user(new_margin, (int __user *)arg);
 		if (ret)
 			break;
 
@@ -171,7 +171,7 @@ static long watchdog_ioctl(struct file *
 		watchdog_ping();
 		/* Fall */
 	case WDIOC_GETTIMEOUT:
-		ret = put_user(soft_margin, (int *)arg);
+		ret = put_user(soft_margin, (int __user *)arg);
 		break;
 	}
 	return ret;

-- 
Ben (ben@fluff.org, http://www.fluff.org/)

  'a smiley only costs 4 bytes'

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

* Re: wdt285: fix sparse warnings
  2008-09-14 21:34 wdt285: fix sparse warnings Ben Dooks
@ 2008-09-15  8:05 ` Wim Van Sebroeck
  2008-09-16 10:31   ` Ben Dooks
  0 siblings, 1 reply; 4+ messages in thread
From: Wim Van Sebroeck @ 2008-09-15  8:05 UTC (permalink / raw
  To: Ben Dooks; +Cc: linux-kernel

Ben,

...
> @@ -141,13 +141,13 @@ static long watchdog_ioctl(struct file *
>  	switch (cmd) {
>  	case WDIOC_GETSUPPORT:
>  		ret = 0;
> -		if (copy_to_user((void *)arg, &ident, sizeof(ident)))
> +		if (copy_to_user((void __user *)arg, &ident, sizeof(ident)))
>  			ret = -EFAULT;
>  		break;
>  
...

Isn't it better to fix this like we did with the other watchdog drivers:
        void __user *argp = (void __user *)arg;
        int __user *p = argp;
	...
		if (copy_to_user(argp, &ident, sizeof(ident)))
	...

Regards,
Wim.


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

* wdt285: fix sparse warnings
@ 2008-09-16 10:31 Ben Dooks
  0 siblings, 0 replies; 4+ messages in thread
From: Ben Dooks @ 2008-09-16 10:31 UTC (permalink / raw
  To: linux-kernel, wim; +Cc: Ben Dooks

[-- Attachment #1: simtec/simtec-cats-sparse-wdt285.patch --]
[-- Type: text/plain, Size: 3003 bytes --]

The wdt285.c watchdog driver is producing a number of
sparse errors due to missing __user attributes to calls
to put_user and copy_to_user, as well as in the prototype
of watchdog_write.

wdt285.c:144:21: warning: incorrect type in argument 1 (different address spaces)
wdt285.c:144:21:    expected void [noderef] <asn:1>*to
wdt285.c:144:21:    got void *<noident>
wdt285.c:150:9: warning: incorrect type in initializer (different address spaces)
wdt285.c:150:9:    expected int const [noderef] <asn:1>*register __p
wdt285.c:150:9:    got int *<noident>
wdt285.c:159:9: warning: incorrect type in initializer (different address spaces)
wdt285.c:159:9:    expected int const [noderef] <asn:1>*register __p
wdt285.c:159:9:    got int *<noident>
wdt285.c:174:9: warning: incorrect type in initializer (different address spaces)
wdt285.c:174:9:    expected int const [noderef] <asn:1>*register __p
wdt285.c:174:9:    got int *<noident>
wdt285.c:183:12: warning: incorrect type in initializer (incompatible argument 2 (different address spaces))
wdt285.c:183:12:    expected int ( *write )( ... )
wdt285.c:183:12:    got int ( static [toplevel] *<noident> )( ... )

Signed-off-by: Ben Dooks <ben-linux@fluff.org>

Index: linux-2.6.27-rc6-quilt3/drivers/watchdog/wdt285.c
===================================================================
--- linux-2.6.27-rc6-quilt3.orig/drivers/watchdog/wdt285.c	2008-09-15 00:00:51.000000000 +0100
+++ linux-2.6.27-rc6-quilt3/drivers/watchdog/wdt285.c	2008-09-16 10:37:38.000000000 +0100
@@ -115,8 +115,8 @@ static int watchdog_release(struct inode
 	return 0;
 }
 
-static ssize_t watchdog_write(struct file *file, const char *data,
-						size_t len, loff_t *ppos)
+static ssize_t watchdog_write(struct file *file, const char __user *data,
+			      size_t len, loff_t *ppos)
 {
 	/*
 	 *	Refresh the timer.
@@ -133,21 +133,22 @@ static const struct watchdog_info ident 
 };
 
 static long watchdog_ioctl(struct file *file, unsigned int cmd,
-							unsigned long arg)
+			   unsigned long arg)
 {
 	unsigned int new_margin;
+	int __user *int_arg = (int __user *)arg;
 	int ret = -ENOTTY;
 
 	switch (cmd) {
 	case WDIOC_GETSUPPORT:
 		ret = 0;
-		if (copy_to_user((void *)arg, &ident, sizeof(ident)))
+		if (copy_to_user((void __user *)arg, &ident, sizeof(ident)))
 			ret = -EFAULT;
 		break;
 
 	case WDIOC_GETSTATUS:
 	case WDIOC_GETBOOTSTATUS:
-		ret = put_user(0, (int *)arg);
+		ret = put_user(0, int_arg);
 		break;
 
 	case WDIOC_KEEPALIVE:
@@ -156,7 +157,7 @@ static long watchdog_ioctl(struct file *
 		break;
 
 	case WDIOC_SETTIMEOUT:
-		ret = get_user(new_margin, (int *)arg);
+		ret = get_user(new_margin, int_arg);
 		if (ret)
 			break;
 
@@ -171,7 +172,7 @@ static long watchdog_ioctl(struct file *
 		watchdog_ping();
 		/* Fall */
 	case WDIOC_GETTIMEOUT:
-		ret = put_user(soft_margin, (int *)arg);
+		ret = put_user(soft_margin, int_arg);
 		break;
 	}
 	return ret;

-- 
Ben (ben@fluff.org, http://www.fluff.org/)

  'a smiley only costs 4 bytes'

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

* Re: wdt285: fix sparse warnings
  2008-09-15  8:05 ` Wim Van Sebroeck
@ 2008-09-16 10:31   ` Ben Dooks
  0 siblings, 0 replies; 4+ messages in thread
From: Ben Dooks @ 2008-09-16 10:31 UTC (permalink / raw
  To: Wim Van Sebroeck; +Cc: Ben Dooks, linux-kernel

On Mon, Sep 15, 2008 at 10:05:56AM +0200, Wim Van Sebroeck wrote:
> Ben,
> 
> ...
> > @@ -141,13 +141,13 @@ static long watchdog_ioctl(struct file *
> >  	switch (cmd) {
> >  	case WDIOC_GETSUPPORT:
> >  		ret = 0;
> > -		if (copy_to_user((void *)arg, &ident, sizeof(ident)))
> > +		if (copy_to_user((void __user *)arg, &ident, sizeof(ident)))
> >  			ret = -EFAULT;
> >  		break;
> >  
> ...
> 
> Isn't it better to fix this like we did with the other watchdog drivers:
>         void __user *argp = (void __user *)arg;
>         int __user *p = argp;

I've changed the int pointer, as it is used numerous times, but left
the void as it is only used in the copy_to_user.
 	...
> 		if (copy_to_user(argp, &ident, sizeof(ident)))
> 	...
> 
> Regards,
> Wim.
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

-- 
Ben (ben@fluff.org, http://www.fluff.org/)

  'a smiley only costs 4 bytes'

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

end of thread, other threads:[~2008-09-16 10:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-14 21:34 wdt285: fix sparse warnings Ben Dooks
2008-09-15  8:05 ` Wim Van Sebroeck
2008-09-16 10:31   ` Ben Dooks
  -- strict thread matches above, loose matches on Subject: below --
2008-09-16 10:31 Ben Dooks

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).