hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/kernel/relay.c
....@@ -1,7 +1,7 @@
11 /*
22 * Public API and common code for kernel->userspace relay file support.
33 *
4
- * See Documentation/filesystems/relay.txt for an overview.
4
+ * See Documentation/filesystems/relay.rst for an overview.
55 *
66 * Copyright (C) 2002-2005 - Tom Zanussi (zanussi@us.ibm.com), IBM Corp
77 * Copyright (C) 1999-2005 - Karim Yaghmour (karim@opersys.com)
....@@ -91,7 +91,7 @@
9191 *
9292 * Returns 0 if ok, negative on error
9393 *
94
- * Caller should already have grabbed mmap_sem.
94
+ * Caller should already have grabbed mmap_lock.
9595 */
9696 static int relay_mmap_buf(struct rchan_buf *buf, struct vm_area_struct *vma)
9797 {
....@@ -163,13 +163,13 @@
163163 {
164164 struct rchan_buf *buf;
165165
166
- if (chan->n_subbufs > KMALLOC_MAX_SIZE / sizeof(size_t *))
166
+ if (chan->n_subbufs > KMALLOC_MAX_SIZE / sizeof(size_t))
167167 return NULL;
168168
169169 buf = kzalloc(sizeof(struct rchan_buf), GFP_KERNEL);
170170 if (!buf)
171171 return NULL;
172
- buf->padding = kmalloc_array(chan->n_subbufs, sizeof(size_t *),
172
+ buf->padding = kmalloc_array(chan->n_subbufs, sizeof(size_t),
173173 GFP_KERNEL);
174174 if (!buf->padding)
175175 goto free_buf;
....@@ -997,14 +997,14 @@
997997 /*
998998 * relay_file_read_avail - boolean, are there unconsumed bytes available?
999999 */
1000
-static int relay_file_read_avail(struct rchan_buf *buf, size_t read_pos)
1000
+static int relay_file_read_avail(struct rchan_buf *buf)
10011001 {
10021002 size_t subbuf_size = buf->chan->subbuf_size;
10031003 size_t n_subbufs = buf->chan->n_subbufs;
10041004 size_t produced = buf->subbufs_produced;
1005
- size_t consumed = buf->subbufs_consumed;
1005
+ size_t consumed;
10061006
1007
- relay_file_read_consume(buf, read_pos, 0);
1007
+ relay_file_read_consume(buf, 0, 0);
10081008
10091009 consumed = buf->subbufs_consumed;
10101010
....@@ -1065,23 +1065,21 @@
10651065
10661066 /**
10671067 * relay_file_read_start_pos - find the first available byte to read
1068
- * @read_pos: file read position
10691068 * @buf: relay channel buffer
10701069 *
1071
- * If the @read_pos is in the middle of padding, return the
1070
+ * If the read_pos is in the middle of padding, return the
10721071 * position of the first actually available byte, otherwise
10731072 * return the original value.
10741073 */
1075
-static size_t relay_file_read_start_pos(size_t read_pos,
1076
- struct rchan_buf *buf)
1074
+static size_t relay_file_read_start_pos(struct rchan_buf *buf)
10771075 {
10781076 size_t read_subbuf, padding, padding_start, padding_end;
10791077 size_t subbuf_size = buf->chan->subbuf_size;
10801078 size_t n_subbufs = buf->chan->n_subbufs;
10811079 size_t consumed = buf->subbufs_consumed % n_subbufs;
1080
+ size_t read_pos = (consumed * subbuf_size + buf->bytes_consumed)
1081
+ % (n_subbufs * subbuf_size);
10821082
1083
- if (!read_pos)
1084
- read_pos = consumed * subbuf_size + buf->bytes_consumed;
10851083 read_subbuf = read_pos / subbuf_size;
10861084 padding = buf->padding[read_subbuf];
10871085 padding_start = (read_subbuf + 1) * subbuf_size - padding;
....@@ -1137,10 +1135,10 @@
11371135 do {
11381136 void *from;
11391137
1140
- if (!relay_file_read_avail(buf, *ppos))
1138
+ if (!relay_file_read_avail(buf))
11411139 break;
11421140
1143
- read_start = relay_file_read_start_pos(*ppos, buf);
1141
+ read_start = relay_file_read_start_pos(buf);
11441142 avail = relay_file_read_subbuf_avail(read_start, buf);
11451143 if (!avail)
11461144 break;
....@@ -1183,11 +1181,9 @@
11831181 }
11841182
11851183 static const struct pipe_buf_operations relay_pipe_buf_ops = {
1186
- .can_merge = 0,
1187
- .confirm = generic_pipe_buf_confirm,
1188
- .release = relay_pipe_buf_release,
1189
- .steal = generic_pipe_buf_steal,
1190
- .get = generic_pipe_buf_get,
1184
+ .release = relay_pipe_buf_release,
1185
+ .try_steal = generic_pipe_buf_try_steal,
1186
+ .get = generic_pipe_buf_get,
11911187 };
11921188
11931189 static void relay_page_release(struct splice_pipe_desc *spd, unsigned int i)