public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@osdl.org>
To: Tom Zanussi <zanussi@us.ibm.com>
Cc: linux-kernel@vger.kernel.org, karim@opersys.com, prasadav@us.ibm.com
Subject: Re: [-mm patch] relayfs: add read() support
Date: Fri, 5 Aug 2005 00:57:53 -0700	[thread overview]
Message-ID: <20050805005753.031db798.akpm@osdl.org> (raw)
In-Reply-To: <17138.53203.430849.147593@tut.ibm.com>

Tom Zanussi <zanussi@us.ibm.com> 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.

  reply	other threads:[~2005-08-05  8:02 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-05  2:32 [-mm patch] relayfs: add read() support Tom Zanussi
2005-08-05  7:57 ` Andrew Morton [this message]
2005-08-05 17:06   ` Tom Zanussi
2005-08-05 14:49 ` Jens Axboe
2005-08-05 15:05   ` Tom Zanussi
2005-08-05 15:58     ` Jens Axboe
2005-08-05 19:01       ` Andrew Morton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050805005753.031db798.akpm@osdl.org \
    --to=akpm@osdl.org \
    --cc=karim@opersys.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=prasadav@us.ibm.com \
    --cc=zanussi@us.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox