patch-2.0.21-2.1.0 linux/drivers/char/random.c

Next file: linux/drivers/char/selection.h
Previous file: linux/drivers/char/pty.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file lx2.0/v2.0.21/linux/drivers/char/random.c linux/drivers/char/random.c
@@ -328,14 +328,14 @@
 static struct timer_rand_state *blkdev_timer_state[MAX_BLKDEV];
 static struct wait_queue *random_wait;
 
-static int random_read(struct inode * inode, struct file * file,
-		       char * buf, int nbytes);
-static int random_read_unlimited(struct inode * inode, struct file * file,
-				 char * buf, int nbytes);
+static long random_read(struct inode * inode, struct file * file,
+		       char * buf, unsigned long nbytes);
+static long random_read_unlimited(struct inode * inode, struct file * file,
+				 char * buf, unsigned long nbytes);
 static int random_select(struct inode *inode, struct file *file,
 			 int sel_type, select_table * wait);
-static int random_write(struct inode * inode, struct file * file,
-			const char * buffer, int count);
+static long random_write(struct inode * inode, struct file * file,
+			const char * buffer, unsigned long count);
 static int random_ioctl(struct inode * inode, struct file * file,
 			unsigned int cmd, unsigned long arg);
 
@@ -1022,8 +1022,8 @@
 	extract_entropy(&random_state, (char *) buf, nbytes, 0);
 }
 
-static int
-random_read(struct inode * inode, struct file * file, char * buf, int nbytes)
+static long
+random_read(struct inode * inode, struct file * file, char * buf, unsigned long nbytes)
 {
 	struct wait_queue 	wait = { current, NULL };
 	int			n;
@@ -1079,9 +1079,9 @@
 	return (count ? count : retval);
 }
 
-static int
+static long
 random_read_unlimited(struct inode * inode, struct file * file,
-		      char * buf, int nbytes)
+		      char * buf, unsigned long nbytes)
 {
 	return extract_entropy(&random_state, buf, nbytes, 1);
 }
@@ -1105,20 +1105,13 @@
 	return 0;
 }
 
-static int
+static long
 random_write(struct inode * inode, struct file * file,
-	     const char * buffer, int count)
+	     const char * buffer, unsigned long count)
 {
 	int i;
 	__u32 word, *p;
 
-	if (count < 0)
-		return -EINVAL;
-
-	i = verify_area(VERIFY_READ, (void *) buffer, count);
-	if (i)
-		return i;
-
 	for (i = count, p = (__u32 *)buffer;
 	     i >= sizeof(__u32);
 	     i-= sizeof(__u32), p++) {
@@ -1230,6 +1223,9 @@
 		if (ent_count < 0)
 			return -EINVAL;
 		size = get_user(p++);
+		retval = verify_area(VERIFY_READ, (void *) p, size);
+		if (retval)
+			return retval;
 		retval = random_write(0, file, (const char *) p, size);
 		if (retval < 0)
 			return retval;

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov