Re: [-mm patch] relayfs: add read() support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Tom Zanussi <[email protected]> wrote:
>
> +static ssize_t relayfs_read(struct file *filp,
>  +			    char __user *buffer,
>  +			    size_t count,
>  +			    loff_t *ppos)
>  +{
>  +	struct inode *inode = filp->f_dentry->d_inode;
>  +	struct rchan_buf *buf = RELAYFS_I(inode)->buf;
>  +	unsigned int read_start, read_end, avail, start_subbuf;
>  +	unsigned int buf_size = buf->chan->subbuf_size * buf->chan->n_subbufs;
>  +	void *from;
>  +
>  +	avail = relayfs_read_avail(buf, &start_subbuf);
>  +	if (*ppos >= avail)
>  +		return 0;
>  +
>  +	read_start = relayfs_read_start(*ppos, avail, start_subbuf, buf);
>  +	if (read_start == 0 && *ppos)
>  +		return 0;
>  +	
>  +	read_end = relayfs_read_end(read_start, avail, start_subbuf, buf);
>  +	if (read_end == read_start)
>  +		return 0;
>  +	
>  +	from = buf->start + start_subbuf * buf->chan->subbuf_size + read_start;
>  +	if (from >= buf->start + buf_size)
>  +		from -= buf_size;
>  +
>  +	count = min(count, read_end - read_start);
>  +	if (copy_to_user(buffer, from, count))
>  +		return -EFAULT;
>  +
>  +	*ppos = read_start + count;
>  +	
>  +	return count;
>  +}

The use of `unsigned int' in here will cause >4G reads to fail on 64-bit
platforms.  I think you want size_t throughout.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]
  Powered by Linux