Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
* 2.1.4 exception question
@ 1996-10-16  0:22 Richard Henderson
  1996-10-16  5:33 ` Linus Torvalds
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Henderson @ 1996-10-16  0:22 UTC (permalink / raw)


I am aware that quite a bit was hashed about on linux-kernel recently,
but to clarify, I'm wondering about the implementation of read/write
as they exist in 2.1.4.  I take as my example the routines from
drivers/char/mem.c.

As it stands, copy_{to,from}_user correctly trap the exception, but 
the surrounding code does nothing with the status returned from those
functions.

According to my understanding of the recent discussion, the appended
patch is required to make the code correct.  Specifically, it actually
tests the return values and returns the amount actually written.  Is
this indeed correct?  Should this pattern be replicated to the other
drivers?

What about bits like those in, e.g., arch/alpha/kernel/osf_sys.c
osf_filldir() that similarly assume that the entire buffer is valid,
and blithely attempts to fill it all despite the fact that it 
generates oodles of exceptions? 

Or, on a slightly different tack, sys_newstat that never returns
an error.  Or the set_termios bits which don't recognize that the
copy_from_user failed.  True, POSIX says we needn't reliably report
such errors, but is this what _we_ want in this situation?

Just wondering what the Official Position on these issues are 
before doing wholesale changes.

r~

*** mem.c.orig	Tue Oct 15 18:42:40 1996
--- mem.c	Tue Oct 15 18:51:59 1996
*************** static long read_mem(struct inode * inod
*** 51,57 ****
  {
  	unsigned long p = file->f_pos;
  	unsigned long end_mem;
! 	int read;
  
  	if (count < 0)
  		return -EINVAL;
--- 51,57 ----
  {
  	unsigned long p = file->f_pos;
  	unsigned long end_mem;
! 	long read;
  
  	if (count < 0)
  		return -EINVAL;
*************** static long read_mem(struct inode * inod
*** 60,79 ****
  		return 0;
  	if (count > end_mem - p)
  		count = end_mem - p;
  	read = 0;
  #if defined(__sparc__) /* we don't have page 0 mapped on sparc.. */
! 	while (p < PAGE_SIZE && count > 0) {
! 		put_user(0,buf);
  		buf++;
  		p++;
- 		count--;
  		read++;
  	}
  #endif
! 	copy_to_user(buf, __va(p), count);
! 	read += count;
  	file->f_pos += read;
! 	return read;
  }
  
  static long write_mem(struct inode * inode, struct file * file,
--- 60,81 ----
  		return 0;
  	if (count > end_mem - p)
  		count = end_mem - p;
+ 
  	read = 0;
  #if defined(__sparc__) /* we don't have page 0 mapped on sparc.. */
! 	while (p < PAGE_SIZE && read < count) {
! 		if (put_user(0,buf))
! 			goto error;
  		buf++;
  		p++;
  		read++;
  	}
  #endif
! 	read += count - copy_to_user(buf, __va(p), count);
! 
! error:
  	file->f_pos += read;
! 	return read || !count ? read : -EFAULT;
  }
  
  static long write_mem(struct inode * inode, struct file * file,
*************** static long write_mem(struct inode * ino
*** 81,87 ****
  {
  	unsigned long p = file->f_pos;
  	unsigned long end_mem;
! 	int written;
  
  	if (count < 0)
  		return -EINVAL;
--- 83,89 ----
  {
  	unsigned long p = file->f_pos;
  	unsigned long end_mem;
! 	long written;
  
  	if (count < 0)
  		return -EINVAL;
*************** static long write_mem(struct inode * ino
*** 90,109 ****
  		return 0;
  	if (count > end_mem - p)
  		count = end_mem - p;
  	written = 0;
  #if defined(__sparc__) /* we don't have page 0 mapped on sparc.. */
! 	while (p < PAGE_SIZE && count > 0) {
  		/* Hmm. Do something? */
  		buf++;
  		p++;
- 		count--;
  		written++;
  	}
  #endif
! 	copy_from_user(__va(p), buf, count);
! 	written += count;
  	file->f_pos += written;
! 	return count;
  }
  
  static int mmap_mem(struct inode * inode, struct file * file, struct vm_area_struct * vma)
--- 92,111 ----
  		return 0;
  	if (count > end_mem - p)
  		count = end_mem - p;
+ 
  	written = 0;
  #if defined(__sparc__) /* we don't have page 0 mapped on sparc.. */
! 	while (p < PAGE_SIZE && written < count) {
  		/* Hmm. Do something? */
  		buf++;
  		p++;
  		written++;
  	}
  #endif
! 	written += count - copy_from_user(__va(p), buf, count);
! 
  	file->f_pos += written;
! 	return written || !count ? written : -EFAULT;
  }
  
  static int mmap_mem(struct inode * inode, struct file * file, struct vm_area_struct * vma)

--
To unsubscribe: mail -s unsubscribe axp-list-request@redhat.com < /dev/null

^ permalink raw reply	[flat|nested] 4+ messages in thread
[parent not found: <Pine.LNX.3.91.961016075015.19371A-100000@linux.cs.Helsinki.FI>]
[parent not found: <199610161954.OAA08203@atheist.tamu.edu>]

end of thread, other threads:[~1996-10-17  4:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1996-10-16  0:22 2.1.4 exception question Richard Henderson
1996-10-16  5:33 ` Linus Torvalds
     [not found] <Pine.LNX.3.91.961016075015.19371A-100000@linux.cs.Helsinki.FI>
1996-10-16 19:54 ` Richard Henderson
     [not found] <199610161954.OAA08203@atheist.tamu.edu>
1996-10-17  4:30 ` Linus Torvalds

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox