Skip to content

Commit 24da24d

Browse files
Tom ZanussiJens Axboe
authored andcommitted
relay: fix bogus cast in subbuf_splice_actor()
The current code that sets the read position in subbuf_splice_actor may give erroneous results if the buffer size isn't a power of 2. This patch fixes the problem. Signed-off-by: Tom Zanussi <zanussi@us.ibm.com> Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
1 parent 7732089 commit 24da24d

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

‎kernel/relay.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,9 @@ static int subbuf_splice_actor(struct file *in,
10741074
unsigned int pidx, poff, total_len, subbuf_pages, ret;
10751075
struct rchan_buf *rbuf = in->private_data;
10761076
unsigned int subbuf_size = rbuf->chan->subbuf_size;
1077-
size_t read_start = ((size_t)*ppos) % rbuf->chan->alloc_size;
1077+
uint64_t pos = (uint64_t) *ppos;
1078+
uint32_t alloc_size = (uint32_t) rbuf->chan->alloc_size;
1079+
size_t read_start = (size_t) do_div(pos, alloc_size);
10781080
size_t read_subbuf = read_start / subbuf_size;
10791081
size_t padding = rbuf->padding[read_subbuf];
10801082
size_t nonpad_end = read_subbuf * subbuf_size + subbuf_size - padding;

0 commit comments

Comments
 (0)