mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] fix check warnings in drivers/macintosh
@ 2003-06-07 11:46 Paul Mackerras
  2003-06-07 20:05 ` Linus Torvalds
  0 siblings, 1 reply; 2+ messages in thread
From: Paul Mackerras @ 2003-06-07 11:46 UTC (permalink / raw)
  To: torvalds; +Cc: benh, linux-kernel

Linus,

This patch removes the warnings that the `check' program came up with
in drivers/macintosh.  This involves adding __user in various places
and fixing some non-ANSI function definitions for functions that take
no arguments.

Please apply.

Thanks,
Paul.

diff -urN linux-2.5/drivers/macintosh/adb.c pmac-2.5/drivers/macintosh/adb.c
--- linux-2.5/drivers/macintosh/adb.c	2003-05-08 16:27:25.000000000 +1000
+++ pmac-2.5/drivers/macintosh/adb.c	2003-06-07 17:45:03.000000000 +1000
@@ -749,7 +749,7 @@
 	return 0;
 }
 
-static ssize_t adb_read(struct file *file, char *buf,
+static ssize_t adb_read(struct file *file, char __user *buf,
 			size_t count, loff_t *ppos)
 {
 	int ret;
@@ -810,7 +810,7 @@
 	return ret;
 }
 
-static ssize_t adb_write(struct file *file, const char *buf,
+static ssize_t adb_write(struct file *file, const char __user *buf,
 			 size_t count, loff_t *ppos)
 {
 	int ret/*, i*/;
diff -urN linux-2.5/drivers/macintosh/apm_emu.c pmac-2.5/drivers/macintosh/apm_emu.c
--- linux-2.5/drivers/macintosh/apm_emu.c	2003-05-23 14:58:26.000000000 +1000
+++ pmac-2.5/drivers/macintosh/apm_emu.c	2003-06-07 14:38:16.000000000 +1000
@@ -180,7 +180,7 @@
 	return 0;
 }
 
-static ssize_t do_read(struct file *fp, char *buf, size_t count, loff_t *ppos)
+static ssize_t do_read(struct file *fp, char __user *buf, size_t count, loff_t *ppos)
 {
 	struct apm_user *	as;
 	size_t			i;
diff -urN linux-2.5/drivers/macintosh/macserial.c pmac-2.5/drivers/macintosh/macserial.c
--- linux-2.5/drivers/macintosh/macserial.c	2003-06-07 08:57:42.000000000 +1000
+++ pmac-2.5/drivers/macintosh/macserial.c	2003-06-07 14:35:34.000000000 +1000
@@ -1496,7 +1496,7 @@
 			if (c <= 0)
 				break;
 
-			c -= copy_from_user(tmp_buf, buf, c);
+			c -= copy_from_user(tmp_buf, (void __user *) buf, c);
 			if (!c) {
 				if (!ret)
 					ret = -EFAULT;
@@ -1694,7 +1694,7 @@
  */
 
 static int get_serial_info(struct mac_serial * info,
-			   struct serial_struct * retinfo)
+			   struct serial_struct __user * retinfo)
 {
 	struct serial_struct tmp;
   
@@ -1716,7 +1716,7 @@
 }
 
 static int set_serial_info(struct mac_serial * info,
-			   struct serial_struct * new_info)
+			   struct serial_struct __user * new_info)
 {
 	struct serial_struct new_serial;
 	struct mac_serial old_info;
@@ -1876,15 +1876,15 @@
 			return set_modem_info(info, cmd, (unsigned int *) arg);
 		case TIOCGSERIAL:
 			return get_serial_info(info,
-					       (struct serial_struct *) arg);
+					(struct serial_struct __user *) arg);
 		case TIOCSSERIAL:
 			return set_serial_info(info,
-					       (struct serial_struct *) arg);
+					(struct serial_struct __user *) arg);
 		case TIOCSERGETLSR: /* Get line status register */
 			return get_lsr_info(info, (unsigned int *) arg);
 
 		case TIOCSERGSTRUCT:
-			if (copy_to_user((struct mac_serial *) arg,
+			if (copy_to_user((struct mac_serial __user *) arg,
 					 info, sizeof(struct mac_serial)))
 				return -EFAULT;
 			return 0;
@@ -2432,7 +2432,7 @@
 
 /* Ask the PROM how many Z8530s we have and initialize their zs_channels */
 static void
-probe_sccs()
+probe_sccs(void)
 {
 	struct device_node *dev, *ch;
 	struct mac_serial **pp;
diff -urN linux-2.5/drivers/macintosh/nvram.c pmac-2.5/drivers/macintosh/nvram.c
--- linux-2.5/drivers/macintosh/nvram.c	2002-12-06 13:56:46.000000000 +1100
+++ pmac-2.5/drivers/macintosh/nvram.c	2003-06-07 17:46:01.000000000 +1000
@@ -39,11 +39,11 @@
 	return file->f_pos;
 }
 
-static ssize_t read_nvram(struct file *file, char *buf,
+static ssize_t read_nvram(struct file *file, char __user *buf,
 			  size_t count, loff_t *ppos)
 {
 	unsigned int i;
-	char *p = buf;
+	char __user *p = buf;
 
 	if (verify_area(VERIFY_WRITE, buf, count))
 		return -EFAULT;
@@ -56,11 +56,11 @@
 	return p - buf;
 }
 
-static ssize_t write_nvram(struct file *file, const char *buf,
+static ssize_t write_nvram(struct file *file, const char __user *buf,
 			   size_t count, loff_t *ppos)
 {
 	unsigned int i;
-	const char *p = buf;
+	const char __user *p = buf;
 	char c;
 
 	if (verify_area(VERIFY_READ, buf, count))
@@ -83,12 +83,12 @@
 		case PMAC_NVRAM_GET_OFFSET:
 		{
 			int part, offset;
-			if (copy_from_user(&part,(void*)arg,sizeof(part))!=0)
+			if (copy_from_user(&part, (void __user*)arg, sizeof(part)) != 0)
 				return -EFAULT;
 			if (part < pmac_nvram_OF || part > pmac_nvram_NR)
 				return -EINVAL;
 			offset = pmac_get_partition(part);
-			if (copy_to_user((void*)arg,&offset,sizeof(offset))!=0)
+			if (copy_to_user((void __user*)arg, &offset, sizeof(offset)) != 0)
 				return -EFAULT;
 			break;
 		}
diff -urN linux-2.5/drivers/macintosh/via-cuda.c pmac-2.5/drivers/macintosh/via-cuda.c
--- linux-2.5/drivers/macintosh/via-cuda.c	2003-04-28 08:28:50.000000000 +1000
+++ pmac-2.5/drivers/macintosh/via-cuda.c	2003-06-07 14:38:00.000000000 +1000
@@ -213,7 +213,7 @@
 
 #ifdef CONFIG_ADB
 static int
-cuda_probe()
+cuda_probe(void)
 {
 #ifdef CONFIG_PPC
     if (sys_ctrler != SYS_CTRLER_CUDA)
@@ -258,7 +258,7 @@
     } while (0)
 
 static int
-cuda_init_via()
+cuda_init_via(void)
 {
     out_8(&via[DIRB], (in_8(&via[DIRB]) | TACK | TIP) & ~TREQ);	/* TACK & TIP out */
     out_8(&via[B], in_8(&via[B]) | TACK | TIP);			/* negate them */
@@ -407,7 +407,7 @@
 }
 
 static void
-cuda_start()
+cuda_start(void)
 {
     struct adb_request *req;
 
@@ -427,7 +427,7 @@
 }
 
 void
-cuda_poll()
+cuda_poll(void)
 {
     unsigned long flags;
 
diff -urN linux-2.5/drivers/macintosh/via-pmu.c pmac-2.5/drivers/macintosh/via-pmu.c
--- linux-2.5/drivers/macintosh/via-pmu.c	2003-06-05 22:27:37.000000000 +1000
+++ pmac-2.5/drivers/macintosh/via-pmu.c	2003-06-07 17:46:48.000000000 +1000
@@ -195,7 +195,7 @@
 #endif /* CONFIG_PMAC_PBOOK */
 static int proc_read_options(char *page, char **start, off_t off,
 			int count, int *eof, void *data);
-static int proc_write_options(struct file *file, const char *buffer,
+static int proc_write_options(struct file *file, const char __user *buffer,
 			unsigned long count, void *data);
 
 #ifdef CONFIG_ADB
@@ -290,7 +290,7 @@
 #endif /* CONFIG_PMAC_BACKLIGHT */
 
 int __openfirmware
-find_via_pmu()
+find_via_pmu(void)
 {
 	if (via != 0)
 		return 1;
@@ -371,7 +371,7 @@
 
 #ifdef CONFIG_ADB
 static int __openfirmware
-pmu_probe()
+pmu_probe(void)
 {
 	return vias == NULL? -ENODEV: 0;
 }
@@ -510,7 +510,7 @@
 device_initcall(via_pmu_dev_init);
 
 static int __openfirmware
-init_pmu()
+init_pmu(void)
 {
 	int timeout;
 	struct adb_request req;
@@ -815,7 +815,7 @@
 }
 			
 static int __pmac
-proc_write_options(struct file *file, const char *buffer,
+proc_write_options(struct file *file, const char __user *buffer,
 			unsigned long count, void *data)
 {
 	char tmp[33];
@@ -1112,7 +1112,7 @@
 }
 
 static void __pmac
-pmu_start()
+pmu_start(void)
 {
 	struct adb_request *req;
 
@@ -1136,7 +1136,7 @@
 }
 
 void __openfirmware
-pmu_poll()
+pmu_poll(void)
 {
 	if (!via)
 		return;
@@ -2402,7 +2402,7 @@
 }
 
 static ssize_t  __pmac
-pmu_read(struct file *file, char *buf,
+pmu_read(struct file *file, char __user *buf,
 			size_t count, loff_t *ppos)
 {
 	struct pmu_private *pp = file->private_data;
@@ -2455,7 +2455,7 @@
 }
 
 static ssize_t __pmac
-pmu_write(struct file *file, const char *buf,
+pmu_write(struct file *file, const char __user *buf,
 			 size_t count, loff_t *ppos)
 {
 	return 0;

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

* Re: [PATCH] fix check warnings in drivers/macintosh
  2003-06-07 11:46 [PATCH] fix check warnings in drivers/macintosh Paul Mackerras
@ 2003-06-07 20:05 ` Linus Torvalds
  0 siblings, 0 replies; 2+ messages in thread
From: Linus Torvalds @ 2003-06-07 20:05 UTC (permalink / raw)
  To: Paul Mackerras; +Cc: benh, linux-kernel


On Sat, 7 Jun 2003, Paul Mackerras wrote:
> 
> This patch removes the warnings that the `check' program came up with
> in drivers/macintosh.  This involves adding __user in various places
> and fixing some non-ANSI function definitions for functions that take
> no arguments.

Thanks, but please avoid doing things like this:

> diff -urN linux-2.5/drivers/macintosh/macserial.c pmac-2.5/drivers/macintosh/macserial.c
> --- linux-2.5/drivers/macintosh/macserial.c	2003-06-07 08:57:42.000000000 +1000
> +++ pmac-2.5/drivers/macintosh/macserial.c	2003-06-07 14:35:34.000000000 +1000
> @@ -1496,7 +1496,7 @@
>  			if (c <= 0)
>  				break;
>  
> -			c -= copy_from_user(tmp_buf, buf, c);
> +			c -= copy_from_user(tmp_buf, (void __user *) buf, c);

The problem here is that "buf" has the wrong type, and you're hiding it 
with a cast.

That's pointless - yes, it avoids a warning from "check", but the thing 
is, that warning was _correct_, and you just hid the problem.

If "buf" really is a user pointer, then it should have been marked that 
way in the first place.

I understand why you did it the way you did: the tty functions are badly 
designed, and the same function is used for both user and kernel pointers.

And that's something that check does and _should_ warn about. The function 
definition is crap, and I'd rather have the warning there and hope some 
tty layer person comes along and makes the user/kernel case into separate 
functions (they don't share that much code anyway, since most of the 
function is

	if (from_user) {
		user case
	} else {
		kernel case
	}

anyway.

I hate these kinds of "flag" arguments anyway. If a function does two
different things, it should be two different functions. Yeah, I know, the
"gfp_mask" thing for the memory allocators are the same way, and yeah,
that was a design mistake too.

		Linus


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

end of thread, other threads:[~2003-06-07 19:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-06-07 11:46 [PATCH] fix check warnings in drivers/macintosh Paul Mackerras
2003-06-07 20:05 ` Linus Torvalds

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®