Skip to contentSkip to conversation

genrtc: fix read on 64-bit platforms

PATCH In review Atsushi Nemoto 2 participants 3 messages Apr 28, 2006 – Apr 29, 2006 Char and misc drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 genrtc: fix read on 64-bit platforms

Fix genrtc's read() routine for 64-bit platforms.

drivers/char/genrtc.c +4 -4
index d3a2bc3..588fca5 100644
@@ -200,13 +200,13 @@ static ssize_t gen_rtc_read(struct file 
 	/* first test allows optimizer to nuke this case for 32-bit machines */
 	if (sizeof (int) != sizeof (long) && count == sizeof (unsigned int)) {
 		unsigned int uidata = data;
-		retval = put_user(uidata, (unsigned long __user *)buf);
+		retval = put_user(uidata, (unsigned int __user *)buf) ?:
+			sizeof(unsigned int);
 	}
 	else {
-		retval = put_user(data, (unsigned long __user *)buf);
+		retval = put_user(data, (unsigned long __user *)buf) ?:
+			sizeof(unsigned long);
 	}
-	if (!retval)
-		retval = sizeof(unsigned long);
  out:
 	current->state = TASK_RUNNING;
 	remove_wait_queue(&gen_rtc_wait, &wait);
#1 lore raw
Quoted 3 lines · Atsushi Nemoto

Fix genrtc's read() routine for 64-bit platforms.

When fixing something, please provide a description of what the problem was and also a description of how the patch fixes it (unless it's obvious, of course).

Thanks.

Quoted 23 lines
drivers/char/genrtc.c +4 -4
index d3a2bc3..588fca5 100644
@@ -200,13 +200,13 @@ static ssize_t gen_rtc_read(struct file 
 	/* first test allows optimizer to nuke this case for 32-bit machines */
 	if (sizeof (int) != sizeof (long) && count == sizeof (unsigned int)) {
 		unsigned int uidata = data;
-		retval = put_user(uidata, (unsigned long __user *)buf);
+		retval = put_user(uidata, (unsigned int __user *)buf) ?:
+			sizeof(unsigned int);
 	}
 	else {
-		retval = put_user(data, (unsigned long __user *)buf);
+		retval = put_user(data, (unsigned long __user *)buf) ?:
+			sizeof(unsigned long);
 	}
-	if (!retval)
-		retval = sizeof(unsigned long);
  out:
 	current->state = TASK_RUNNING;
 	remove_wait_queue(&gen_rtc_wait, &wait);
#2 lore raw
Quoted 5 lines · Andrew Morton
Quoted 1 line

Fix genrtc's read() routine for 64-bit platforms.

When fixing something, please provide a description of what the problem was and also a description of how the patch fixes it (unless it's obvious, of course).

Thanks. Here is a same patch with an updated description.

Fix genrtc's read() routine for 64-bit platforms. Current gen_rtc_read() stores 64bit integer and returns 8 even if an user tried to read a 32bit integer.

drivers/char/genrtc.c +4 -4
index d3a2bc3..588fca5 100644
@@ -200,13 +200,13 @@ static ssize_t gen_rtc_read(struct file 
 	/* first test allows optimizer to nuke this case for 32-bit machines */
 	if (sizeof (int) != sizeof (long) && count == sizeof (unsigned int)) {
 		unsigned int uidata = data;
-		retval = put_user(uidata, (unsigned long __user *)buf);
+		retval = put_user(uidata, (unsigned int __user *)buf) ?:
+			sizeof(unsigned int);
 	}
 	else {
-		retval = put_user(data, (unsigned long __user *)buf);
+		retval = put_user(data, (unsigned long __user *)buf) ?:
+			sizeof(unsigned long);
 	}
-	if (!retval)
-		retval = sizeof(unsigned long);
  out:
 	current->state = TASK_RUNNING;
 	remove_wait_queue(&gen_rtc_wait, &wait);