Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * linux/fs/seq_file.c |
| 4 | * |
| 5 | * helper functions for making synthetic files from sequences of records. |
| 6 | * initial implementation -- AV, Oct 2001. |
| 7 | */ |
| 8 | |
Alexey Dobriyan | 096523203 | 2018-04-10 16:34:45 -0700 | [diff] [blame] | 9 | #include <linux/cache.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/fs.h> |
Paul Gortmaker | 630d9c4 | 2011-11-16 23:57:37 -0500 | [diff] [blame] | 11 | #include <linux/export.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/seq_file.h> |
Heiko Carstens | 058504e | 2014-07-02 15:22:37 -0700 | [diff] [blame] | 13 | #include <linux/vmalloc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/slab.h> |
Eric W. Biederman | adb37c4 | 2012-05-23 18:01:20 -0600 | [diff] [blame] | 15 | #include <linux/cred.h> |
Heiko Carstens | 058504e | 2014-07-02 15:22:37 -0700 | [diff] [blame] | 16 | #include <linux/mm.h> |
Andy Shevchenko | 3760710 | 2015-09-09 15:38:33 -0700 | [diff] [blame] | 17 | #include <linux/printk.h> |
Andy Shevchenko | 25c6bb7 | 2015-11-06 16:32:40 -0800 | [diff] [blame] | 18 | #include <linux/string_helpers.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 20 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <asm/page.h> |
| 22 | |
Alexey Dobriyan | 096523203 | 2018-04-10 16:34:45 -0700 | [diff] [blame] | 23 | static struct kmem_cache *seq_file_cache __ro_after_init; |
| 24 | |
KAMEZAWA Hiroyuki | e075f59 | 2012-03-23 15:02:55 -0700 | [diff] [blame] | 25 | static void seq_set_overflow(struct seq_file *m) |
| 26 | { |
| 27 | m->count = m->size; |
| 28 | } |
| 29 | |
Heiko Carstens | 058504e | 2014-07-02 15:22:37 -0700 | [diff] [blame] | 30 | static void *seq_buf_alloc(unsigned long size) |
| 31 | { |
Alexey Dobriyan | d64d01a | 2018-04-10 16:34:49 -0700 | [diff] [blame] | 32 | return kvmalloc(size, GFP_KERNEL_ACCOUNT); |
Heiko Carstens | 058504e | 2014-07-02 15:22:37 -0700 | [diff] [blame] | 33 | } |
| 34 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | /** |
| 36 | * seq_open - initialize sequential file |
| 37 | * @file: file we initialize |
| 38 | * @op: method table describing the sequence |
| 39 | * |
| 40 | * seq_open() sets @file, associating it with a sequence described |
| 41 | * by @op. @op->start() sets the iterator up and returns the first |
| 42 | * element of sequence. @op->stop() shuts it down. @op->next() |
| 43 | * returns the next element of sequence. @op->show() prints element |
| 44 | * into the buffer. In case of error ->start() and ->next() return |
| 45 | * ERR_PTR(error). In the end of sequence they return %NULL. ->show() |
| 46 | * returns 0 in case of success and negative number in case of error. |
Al Viro | 521b5d0 | 2008-03-28 00:46:41 -0400 | [diff] [blame] | 47 | * Returning SEQ_SKIP means "discard this element and move on". |
Yann Droneaud | 460b865 | 2015-06-30 14:57:36 -0700 | [diff] [blame] | 48 | * Note: seq_open() will allocate a struct seq_file and store its |
| 49 | * pointer in @file->private_data. This pointer should not be modified. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | */ |
Helge Deller | 15ad7cd | 2006-12-06 20:40:36 -0800 | [diff] [blame] | 51 | int seq_open(struct file *file, const struct seq_operations *op) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | { |
Yann Droneaud | 189f984 | 2015-06-30 14:57:33 -0700 | [diff] [blame] | 53 | struct seq_file *p; |
Al Viro | 1abe77b | 2005-11-07 17:15:34 -0500 | [diff] [blame] | 54 | |
Yann Droneaud | 189f984 | 2015-06-30 14:57:33 -0700 | [diff] [blame] | 55 | WARN_ON(file->private_data); |
| 56 | |
Alexey Dobriyan | 096523203 | 2018-04-10 16:34:45 -0700 | [diff] [blame] | 57 | p = kmem_cache_zalloc(seq_file_cache, GFP_KERNEL); |
Yann Droneaud | 189f984 | 2015-06-30 14:57:33 -0700 | [diff] [blame] | 58 | if (!p) |
| 59 | return -ENOMEM; |
| 60 | |
| 61 | file->private_data = p; |
| 62 | |
Ingo Molnar | 0ac1759 | 2006-03-23 03:00:37 -0800 | [diff] [blame] | 63 | mutex_init(&p->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | p->op = op; |
Linus Torvalds | 34dbbcd | 2016-04-14 11:22:00 -0700 | [diff] [blame] | 65 | |
| 66 | // No refcounting: the lifetime of 'p' is constrained |
| 67 | // to the lifetime of the file. |
| 68 | p->file = file; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
| 70 | /* |
Eric Biederman | 8f19d47 | 2009-02-18 14:48:16 -0800 | [diff] [blame] | 71 | * seq_files support lseek() and pread(). They do not implement |
| 72 | * write() at all, but we clear FMODE_PWRITE here for historical |
| 73 | * reasons. |
| 74 | * |
| 75 | * If a client of seq_files a) implements file.write() and b) wishes to |
| 76 | * support pwrite() then that client will need to implement its own |
| 77 | * file.open() which calls seq_open() and then sets FMODE_PWRITE. |
| 78 | */ |
| 79 | file->f_mode &= ~FMODE_PWRITE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | return 0; |
| 81 | } |
| 82 | EXPORT_SYMBOL(seq_open); |
| 83 | |
Eric Biederman | 33da889 | 2009-02-04 15:12:25 -0800 | [diff] [blame] | 84 | static int traverse(struct seq_file *m, loff_t offset) |
| 85 | { |
NeilBrown | 1f4aace | 2018-08-17 15:44:41 -0700 | [diff] [blame] | 86 | loff_t pos = 0; |
Eric Biederman | 33da889 | 2009-02-04 15:12:25 -0800 | [diff] [blame] | 87 | int error = 0; |
| 88 | void *p; |
| 89 | |
NeilBrown | 1f4aace | 2018-08-17 15:44:41 -0700 | [diff] [blame] | 90 | m->index = 0; |
Eric Biederman | 33da889 | 2009-02-04 15:12:25 -0800 | [diff] [blame] | 91 | m->count = m->from = 0; |
NeilBrown | 1f4aace | 2018-08-17 15:44:41 -0700 | [diff] [blame] | 92 | if (!offset) |
Eric Biederman | 33da889 | 2009-02-04 15:12:25 -0800 | [diff] [blame] | 93 | return 0; |
NeilBrown | 1f4aace | 2018-08-17 15:44:41 -0700 | [diff] [blame] | 94 | |
Eric Biederman | 33da889 | 2009-02-04 15:12:25 -0800 | [diff] [blame] | 95 | if (!m->buf) { |
Heiko Carstens | 058504e | 2014-07-02 15:22:37 -0700 | [diff] [blame] | 96 | m->buf = seq_buf_alloc(m->size = PAGE_SIZE); |
Eric Biederman | 33da889 | 2009-02-04 15:12:25 -0800 | [diff] [blame] | 97 | if (!m->buf) |
| 98 | return -ENOMEM; |
| 99 | } |
NeilBrown | 1f4aace | 2018-08-17 15:44:41 -0700 | [diff] [blame] | 100 | p = m->op->start(m, &m->index); |
Eric Biederman | 33da889 | 2009-02-04 15:12:25 -0800 | [diff] [blame] | 101 | while (p) { |
| 102 | error = PTR_ERR(p); |
| 103 | if (IS_ERR(p)) |
| 104 | break; |
| 105 | error = m->op->show(m, p); |
| 106 | if (error < 0) |
| 107 | break; |
| 108 | if (unlikely(error)) { |
| 109 | error = 0; |
| 110 | m->count = 0; |
| 111 | } |
Joe Perches | 1f33c41 | 2014-09-29 16:08:21 -0700 | [diff] [blame] | 112 | if (seq_has_overflowed(m)) |
Eric Biederman | 33da889 | 2009-02-04 15:12:25 -0800 | [diff] [blame] | 113 | goto Eoverflow; |
NeilBrown | 6a2aeab | 2019-08-13 15:37:44 -0700 | [diff] [blame] | 114 | p = m->op->next(m, p, &m->index); |
Eric Biederman | 33da889 | 2009-02-04 15:12:25 -0800 | [diff] [blame] | 115 | if (pos + m->count > offset) { |
| 116 | m->from = offset - pos; |
| 117 | m->count -= m->from; |
Eric Biederman | 33da889 | 2009-02-04 15:12:25 -0800 | [diff] [blame] | 118 | break; |
| 119 | } |
| 120 | pos += m->count; |
| 121 | m->count = 0; |
NeilBrown | 1f4aace | 2018-08-17 15:44:41 -0700 | [diff] [blame] | 122 | if (pos == offset) |
Eric Biederman | 33da889 | 2009-02-04 15:12:25 -0800 | [diff] [blame] | 123 | break; |
Eric Biederman | 33da889 | 2009-02-04 15:12:25 -0800 | [diff] [blame] | 124 | } |
| 125 | m->op->stop(m, p); |
| 126 | return error; |
| 127 | |
| 128 | Eoverflow: |
| 129 | m->op->stop(m, p); |
Heiko Carstens | 058504e | 2014-07-02 15:22:37 -0700 | [diff] [blame] | 130 | kvfree(m->buf); |
Al Viro | 801a760 | 2013-11-19 01:20:43 +0000 | [diff] [blame] | 131 | m->count = 0; |
Heiko Carstens | 058504e | 2014-07-02 15:22:37 -0700 | [diff] [blame] | 132 | m->buf = seq_buf_alloc(m->size <<= 1); |
Eric Biederman | 33da889 | 2009-02-04 15:12:25 -0800 | [diff] [blame] | 133 | return !m->buf ? -ENOMEM : -EAGAIN; |
| 134 | } |
| 135 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | /** |
| 137 | * seq_read - ->read() method for sequential files. |
Martin Waitz | 67be2dd | 2005-05-01 08:59:26 -0700 | [diff] [blame] | 138 | * @file: the file to read from |
| 139 | * @buf: the buffer to read to |
| 140 | * @size: the maximum number of bytes to read |
| 141 | * @ppos: the current position in the file |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | * |
| 143 | * Ready-made ->f_op->read() |
| 144 | */ |
| 145 | ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos) |
| 146 | { |
Joe Perches | 8209e2f | 2010-09-04 18:52:49 -0700 | [diff] [blame] | 147 | struct seq_file *m = file->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | size_t copied = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | size_t n; |
| 150 | void *p; |
| 151 | int err = 0; |
| 152 | |
Ingo Molnar | 0ac1759 | 2006-03-23 03:00:37 -0800 | [diff] [blame] | 153 | mutex_lock(&m->lock); |
Eric Biederman | 8f19d47 | 2009-02-18 14:48:16 -0800 | [diff] [blame] | 154 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | /* |
Tomasz Majchrzak | e522751 | 2016-11-29 15:18:20 +0100 | [diff] [blame] | 156 | * if request is to read from zero offset, reset iterator to first |
| 157 | * record as it might have been already advanced by previous requests |
| 158 | */ |
Miklos Szeredi | cf5eeba | 2017-11-15 11:34:58 +0100 | [diff] [blame] | 159 | if (*ppos == 0) { |
Tomasz Majchrzak | e522751 | 2016-11-29 15:18:20 +0100 | [diff] [blame] | 160 | m->index = 0; |
Miklos Szeredi | cf5eeba | 2017-11-15 11:34:58 +0100 | [diff] [blame] | 161 | m->count = 0; |
| 162 | } |
Tomasz Majchrzak | e522751 | 2016-11-29 15:18:20 +0100 | [diff] [blame] | 163 | |
Earl Chew | 7904ac8 | 2012-03-21 16:33:43 -0700 | [diff] [blame] | 164 | /* Don't assume *ppos is where we left it */ |
| 165 | if (unlikely(*ppos != m->read_pos)) { |
| 166 | while ((err = traverse(m, *ppos)) == -EAGAIN) |
| 167 | ; |
| 168 | if (err) { |
| 169 | /* With prejudice... */ |
| 170 | m->read_pos = 0; |
Earl Chew | 7904ac8 | 2012-03-21 16:33:43 -0700 | [diff] [blame] | 171 | m->index = 0; |
| 172 | m->count = 0; |
| 173 | goto Done; |
| 174 | } else { |
| 175 | m->read_pos = *ppos; |
| 176 | } |
| 177 | } |
| 178 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | /* grab buffer if we didn't have one */ |
| 180 | if (!m->buf) { |
Heiko Carstens | 058504e | 2014-07-02 15:22:37 -0700 | [diff] [blame] | 181 | m->buf = seq_buf_alloc(m->size = PAGE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | if (!m->buf) |
| 183 | goto Enomem; |
| 184 | } |
| 185 | /* if not empty - flush it first */ |
| 186 | if (m->count) { |
| 187 | n = min(m->count, size); |
| 188 | err = copy_to_user(buf, m->buf + m->from, n); |
| 189 | if (err) |
| 190 | goto Efault; |
| 191 | m->count -= n; |
| 192 | m->from += n; |
| 193 | size -= n; |
| 194 | buf += n; |
| 195 | copied += n; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | if (!size) |
| 197 | goto Done; |
| 198 | } |
| 199 | /* we need at least one record in buffer */ |
NeilBrown | 1f4aace | 2018-08-17 15:44:41 -0700 | [diff] [blame] | 200 | m->from = 0; |
| 201 | p = m->op->start(m, &m->index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | while (1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | err = PTR_ERR(p); |
| 204 | if (!p || IS_ERR(p)) |
| 205 | break; |
| 206 | err = m->op->show(m, p); |
Al Viro | 521b5d0 | 2008-03-28 00:46:41 -0400 | [diff] [blame] | 207 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | break; |
Al Viro | 521b5d0 | 2008-03-28 00:46:41 -0400 | [diff] [blame] | 209 | if (unlikely(err)) |
| 210 | m->count = 0; |
Al Viro | 4cdfe84 | 2008-08-24 07:45:33 -0400 | [diff] [blame] | 211 | if (unlikely(!m->count)) { |
NeilBrown | 1f4aace | 2018-08-17 15:44:41 -0700 | [diff] [blame] | 212 | p = m->op->next(m, p, &m->index); |
Al Viro | 4cdfe84 | 2008-08-24 07:45:33 -0400 | [diff] [blame] | 213 | continue; |
| 214 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | if (m->count < m->size) |
| 216 | goto Fill; |
| 217 | m->op->stop(m, p); |
Heiko Carstens | 058504e | 2014-07-02 15:22:37 -0700 | [diff] [blame] | 218 | kvfree(m->buf); |
Al Viro | 801a760 | 2013-11-19 01:20:43 +0000 | [diff] [blame] | 219 | m->count = 0; |
Heiko Carstens | 058504e | 2014-07-02 15:22:37 -0700 | [diff] [blame] | 220 | m->buf = seq_buf_alloc(m->size <<= 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | if (!m->buf) |
| 222 | goto Enomem; |
NeilBrown | 1f4aace | 2018-08-17 15:44:41 -0700 | [diff] [blame] | 223 | p = m->op->start(m, &m->index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | } |
| 225 | m->op->stop(m, p); |
| 226 | m->count = 0; |
| 227 | goto Done; |
| 228 | Fill: |
| 229 | /* they want more? let's try to get some more */ |
NeilBrown | 1f4aace | 2018-08-17 15:44:41 -0700 | [diff] [blame] | 230 | while (1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | size_t offs = m->count; |
NeilBrown | 1f4aace | 2018-08-17 15:44:41 -0700 | [diff] [blame] | 232 | loff_t pos = m->index; |
| 233 | |
| 234 | p = m->op->next(m, p, &m->index); |
Vasily Averin | 3bfa7e1 | 2020-04-10 14:34:06 -0700 | [diff] [blame] | 235 | if (pos == m->index) { |
| 236 | pr_info_ratelimited("buggy seq_file .next function %ps " |
| 237 | "did not updated position index\n", |
| 238 | m->op->next); |
NeilBrown | 1f4aace | 2018-08-17 15:44:41 -0700 | [diff] [blame] | 239 | m->index++; |
Vasily Averin | 3bfa7e1 | 2020-04-10 14:34:06 -0700 | [diff] [blame] | 240 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | if (!p || IS_ERR(p)) { |
| 242 | err = PTR_ERR(p); |
| 243 | break; |
| 244 | } |
NeilBrown | 1f4aace | 2018-08-17 15:44:41 -0700 | [diff] [blame] | 245 | if (m->count >= size) |
| 246 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | err = m->op->show(m, p); |
Joe Perches | 1f33c41 | 2014-09-29 16:08:21 -0700 | [diff] [blame] | 248 | if (seq_has_overflowed(m) || err) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | m->count = offs; |
Al Viro | 521b5d0 | 2008-03-28 00:46:41 -0400 | [diff] [blame] | 250 | if (likely(err <= 0)) |
| 251 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | } |
| 254 | m->op->stop(m, p); |
| 255 | n = min(m->count, size); |
| 256 | err = copy_to_user(buf, m->buf, n); |
| 257 | if (err) |
| 258 | goto Efault; |
| 259 | copied += n; |
| 260 | m->count -= n; |
NeilBrown | 1f4aace | 2018-08-17 15:44:41 -0700 | [diff] [blame] | 261 | m->from = n; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | Done: |
| 263 | if (!copied) |
| 264 | copied = err; |
Eric Biederman | 8f19d47 | 2009-02-18 14:48:16 -0800 | [diff] [blame] | 265 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | *ppos += copied; |
Eric Biederman | 8f19d47 | 2009-02-18 14:48:16 -0800 | [diff] [blame] | 267 | m->read_pos += copied; |
| 268 | } |
Ingo Molnar | 0ac1759 | 2006-03-23 03:00:37 -0800 | [diff] [blame] | 269 | mutex_unlock(&m->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | return copied; |
| 271 | Enomem: |
| 272 | err = -ENOMEM; |
| 273 | goto Done; |
| 274 | Efault: |
| 275 | err = -EFAULT; |
| 276 | goto Done; |
| 277 | } |
| 278 | EXPORT_SYMBOL(seq_read); |
| 279 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | /** |
| 281 | * seq_lseek - ->llseek() method for sequential files. |
Martin Waitz | 67be2dd | 2005-05-01 08:59:26 -0700 | [diff] [blame] | 282 | * @file: the file in question |
| 283 | * @offset: new position |
Randy Dunlap | 254adaa | 2013-01-09 17:13:00 -0800 | [diff] [blame] | 284 | * @whence: 0 for absolute, 1 for relative position |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | * |
| 286 | * Ready-made ->f_op->llseek() |
| 287 | */ |
Andrew Morton | 965c8e5 | 2012-12-17 15:59:39 -0800 | [diff] [blame] | 288 | loff_t seq_lseek(struct file *file, loff_t offset, int whence) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | { |
Joe Perches | 8209e2f | 2010-09-04 18:52:49 -0700 | [diff] [blame] | 290 | struct seq_file *m = file->private_data; |
David Sterba | 16abef0 | 2008-04-22 15:09:22 +0200 | [diff] [blame] | 291 | loff_t retval = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | |
Ingo Molnar | 0ac1759 | 2006-03-23 03:00:37 -0800 | [diff] [blame] | 293 | mutex_lock(&m->lock); |
Andrew Morton | 965c8e5 | 2012-12-17 15:59:39 -0800 | [diff] [blame] | 294 | switch (whence) { |
Andrew Morton | 5e62ade | 2013-02-27 17:03:22 -0800 | [diff] [blame] | 295 | case SEEK_CUR: |
| 296 | offset += file->f_pos; |
Gustavo A. R. Silva | 0a4c926 | 2019-01-23 02:48:28 -0600 | [diff] [blame] | 297 | /* fall through */ |
Andrew Morton | 5e62ade | 2013-02-27 17:03:22 -0800 | [diff] [blame] | 298 | case SEEK_SET: |
| 299 | if (offset < 0) |
| 300 | break; |
| 301 | retval = offset; |
| 302 | if (offset != m->read_pos) { |
| 303 | while ((retval = traverse(m, offset)) == -EAGAIN) |
| 304 | ; |
| 305 | if (retval) { |
| 306 | /* with extreme prejudice... */ |
| 307 | file->f_pos = 0; |
| 308 | m->read_pos = 0; |
Andrew Morton | 5e62ade | 2013-02-27 17:03:22 -0800 | [diff] [blame] | 309 | m->index = 0; |
| 310 | m->count = 0; |
| 311 | } else { |
| 312 | m->read_pos = offset; |
| 313 | retval = file->f_pos = offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | } |
Gu Zheng | 05e1674 | 2013-10-25 18:15:06 +0800 | [diff] [blame] | 315 | } else { |
| 316 | file->f_pos = offset; |
Andrew Morton | 5e62ade | 2013-02-27 17:03:22 -0800 | [diff] [blame] | 317 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | } |
Alexey Dobriyan | 00c5746 | 2007-07-15 23:40:22 -0700 | [diff] [blame] | 319 | mutex_unlock(&m->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | return retval; |
| 321 | } |
| 322 | EXPORT_SYMBOL(seq_lseek); |
| 323 | |
| 324 | /** |
| 325 | * seq_release - free the structures associated with sequential file. |
| 326 | * @file: file in question |
Al Viro | 6131ffa | 2013-02-27 16:59:05 -0500 | [diff] [blame] | 327 | * @inode: its inode |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | * |
| 329 | * Frees the structures associated with sequential file; can be used |
| 330 | * as ->f_op->release() if you don't have private data to destroy. |
| 331 | */ |
| 332 | int seq_release(struct inode *inode, struct file *file) |
| 333 | { |
Joe Perches | 8209e2f | 2010-09-04 18:52:49 -0700 | [diff] [blame] | 334 | struct seq_file *m = file->private_data; |
Heiko Carstens | 058504e | 2014-07-02 15:22:37 -0700 | [diff] [blame] | 335 | kvfree(m->buf); |
Alexey Dobriyan | 096523203 | 2018-04-10 16:34:45 -0700 | [diff] [blame] | 336 | kmem_cache_free(seq_file_cache, m); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | return 0; |
| 338 | } |
| 339 | EXPORT_SYMBOL(seq_release); |
| 340 | |
| 341 | /** |
| 342 | * seq_escape - print string into buffer, escaping some characters |
| 343 | * @m: target buffer |
| 344 | * @s: string |
| 345 | * @esc: set of characters that need escaping |
| 346 | * |
| 347 | * Puts string into buffer, replacing each occurrence of character from |
Joe Perches | 6798a8c | 2015-09-11 13:07:48 -0700 | [diff] [blame] | 348 | * @esc with usual octal escape. |
| 349 | * Use seq_has_overflowed() to check for errors. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | */ |
Joe Perches | 6798a8c | 2015-09-11 13:07:48 -0700 | [diff] [blame] | 351 | void seq_escape(struct seq_file *m, const char *s, const char *esc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | { |
Andy Shevchenko | 25c6bb7 | 2015-11-06 16:32:40 -0800 | [diff] [blame] | 353 | char *buf; |
| 354 | size_t size = seq_get_buf(m, &buf); |
| 355 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | |
Andy Shevchenko | 25c6bb7 | 2015-11-06 16:32:40 -0800 | [diff] [blame] | 357 | ret = string_escape_str(s, buf, size, ESCAPE_OCTAL, esc); |
| 358 | seq_commit(m, ret < size ? ret : -1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | } |
| 360 | EXPORT_SYMBOL(seq_escape); |
| 361 | |
J. Bruce Fields | ea053e1 | 2019-06-19 12:30:13 -0400 | [diff] [blame] | 362 | void seq_escape_mem_ascii(struct seq_file *m, const char *src, size_t isz) |
| 363 | { |
| 364 | char *buf; |
| 365 | size_t size = seq_get_buf(m, &buf); |
| 366 | int ret; |
| 367 | |
| 368 | ret = string_escape_mem_ascii(src, isz, buf, size); |
| 369 | seq_commit(m, ret < size ? ret : -1); |
| 370 | } |
| 371 | EXPORT_SYMBOL(seq_escape_mem_ascii); |
| 372 | |
Joe Perches | 6798a8c | 2015-09-11 13:07:48 -0700 | [diff] [blame] | 373 | void seq_vprintf(struct seq_file *m, const char *f, va_list args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | int len; |
| 376 | |
| 377 | if (m->count < m->size) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | len = vsnprintf(m->buf + m->count, m->size - m->count, f, args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | if (m->count + len < m->size) { |
| 380 | m->count += len; |
Joe Perches | 6798a8c | 2015-09-11 13:07:48 -0700 | [diff] [blame] | 381 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | } |
| 383 | } |
KAMEZAWA Hiroyuki | e075f59 | 2012-03-23 15:02:55 -0700 | [diff] [blame] | 384 | seq_set_overflow(m); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | } |
Steven Whitehouse | a480814 | 2012-06-11 13:16:35 +0100 | [diff] [blame] | 386 | EXPORT_SYMBOL(seq_vprintf); |
| 387 | |
Joe Perches | 6798a8c | 2015-09-11 13:07:48 -0700 | [diff] [blame] | 388 | void seq_printf(struct seq_file *m, const char *f, ...) |
Steven Whitehouse | a480814 | 2012-06-11 13:16:35 +0100 | [diff] [blame] | 389 | { |
Steven Whitehouse | a480814 | 2012-06-11 13:16:35 +0100 | [diff] [blame] | 390 | va_list args; |
| 391 | |
| 392 | va_start(args, f); |
Joe Perches | 6798a8c | 2015-09-11 13:07:48 -0700 | [diff] [blame] | 393 | seq_vprintf(m, f, args); |
Steven Whitehouse | a480814 | 2012-06-11 13:16:35 +0100 | [diff] [blame] | 394 | va_end(args); |
Steven Whitehouse | a480814 | 2012-06-11 13:16:35 +0100 | [diff] [blame] | 395 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | EXPORT_SYMBOL(seq_printf); |
| 397 | |
Török Edwin | 74e2f33 | 2008-11-22 13:28:48 +0200 | [diff] [blame] | 398 | /** |
Török Edwin | 958086d | 2008-11-23 23:24:53 +0200 | [diff] [blame] | 399 | * mangle_path - mangle and copy path to buffer beginning |
| 400 | * @s: buffer start |
| 401 | * @p: beginning of path in above buffer |
| 402 | * @esc: set of characters that need escaping |
Török Edwin | 74e2f33 | 2008-11-22 13:28:48 +0200 | [diff] [blame] | 403 | * |
| 404 | * Copy the path from @p to @s, replacing each occurrence of character from |
| 405 | * @esc with usual octal escape. |
| 406 | * Returns pointer past last written character in @s, or NULL in case of |
| 407 | * failure. |
| 408 | */ |
Al Viro | 8c9379e | 2011-12-08 20:18:57 -0500 | [diff] [blame] | 409 | char *mangle_path(char *s, const char *p, const char *esc) |
Ram Pai | 6092d04 | 2008-03-27 13:06:20 +0100 | [diff] [blame] | 410 | { |
| 411 | while (s <= p) { |
| 412 | char c = *p++; |
| 413 | if (!c) { |
| 414 | return s; |
| 415 | } else if (!strchr(esc, c)) { |
| 416 | *s++ = c; |
| 417 | } else if (s + 4 > p) { |
| 418 | break; |
| 419 | } else { |
| 420 | *s++ = '\\'; |
| 421 | *s++ = '0' + ((c & 0300) >> 6); |
| 422 | *s++ = '0' + ((c & 070) >> 3); |
| 423 | *s++ = '0' + (c & 07); |
| 424 | } |
| 425 | } |
| 426 | return NULL; |
| 427 | } |
Ingo Molnar | 604094f | 2008-11-28 18:03:22 +0100 | [diff] [blame] | 428 | EXPORT_SYMBOL(mangle_path); |
Ram Pai | 6092d04 | 2008-03-27 13:06:20 +0100 | [diff] [blame] | 429 | |
Arjan van de Ven | 52afeef | 2008-12-01 14:35:00 -0800 | [diff] [blame] | 430 | /** |
| 431 | * seq_path - seq_file interface to print a pathname |
| 432 | * @m: the seq_file handle |
| 433 | * @path: the struct path to print |
| 434 | * @esc: set of characters to escape in the output |
| 435 | * |
| 436 | * return the absolute path of 'path', as represented by the |
| 437 | * dentry / mnt pair in the path parameter. |
Ram Pai | 6092d04 | 2008-03-27 13:06:20 +0100 | [diff] [blame] | 438 | */ |
Al Viro | 8c9379e | 2011-12-08 20:18:57 -0500 | [diff] [blame] | 439 | int seq_path(struct seq_file *m, const struct path *path, const char *esc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | { |
Miklos Szeredi | f843980 | 2009-09-21 14:48:36 +0200 | [diff] [blame] | 441 | char *buf; |
| 442 | size_t size = seq_get_buf(m, &buf); |
| 443 | int res = -1; |
| 444 | |
| 445 | if (size) { |
| 446 | char *p = d_path(path, buf, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | if (!IS_ERR(p)) { |
Miklos Szeredi | f843980 | 2009-09-21 14:48:36 +0200 | [diff] [blame] | 448 | char *end = mangle_path(buf, p, esc); |
| 449 | if (end) |
| 450 | res = end - buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | } |
| 452 | } |
Miklos Szeredi | f843980 | 2009-09-21 14:48:36 +0200 | [diff] [blame] | 453 | seq_commit(m, res); |
| 454 | |
| 455 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | } |
| 457 | EXPORT_SYMBOL(seq_path); |
| 458 | |
Miklos Szeredi | 2726d56 | 2015-06-19 10:30:28 +0200 | [diff] [blame] | 459 | /** |
| 460 | * seq_file_path - seq_file interface to print a pathname of a file |
| 461 | * @m: the seq_file handle |
| 462 | * @file: the struct file to print |
| 463 | * @esc: set of characters to escape in the output |
| 464 | * |
| 465 | * return the absolute path to the file. |
| 466 | */ |
| 467 | int seq_file_path(struct seq_file *m, struct file *file, const char *esc) |
| 468 | { |
| 469 | return seq_path(m, &file->f_path, esc); |
| 470 | } |
| 471 | EXPORT_SYMBOL(seq_file_path); |
| 472 | |
Ram Pai | 6092d04 | 2008-03-27 13:06:20 +0100 | [diff] [blame] | 473 | /* |
Miklos Szeredi | 9d1bc601 | 2008-03-27 13:06:21 +0100 | [diff] [blame] | 474 | * Same as seq_path, but relative to supplied root. |
Miklos Szeredi | 9d1bc601 | 2008-03-27 13:06:21 +0100 | [diff] [blame] | 475 | */ |
Al Viro | 8c9379e | 2011-12-08 20:18:57 -0500 | [diff] [blame] | 476 | int seq_path_root(struct seq_file *m, const struct path *path, |
| 477 | const struct path *root, const char *esc) |
Miklos Szeredi | 9d1bc601 | 2008-03-27 13:06:21 +0100 | [diff] [blame] | 478 | { |
Miklos Szeredi | f843980 | 2009-09-21 14:48:36 +0200 | [diff] [blame] | 479 | char *buf; |
| 480 | size_t size = seq_get_buf(m, &buf); |
| 481 | int res = -ENAMETOOLONG; |
| 482 | |
| 483 | if (size) { |
Miklos Szeredi | 9d1bc601 | 2008-03-27 13:06:21 +0100 | [diff] [blame] | 484 | char *p; |
| 485 | |
Miklos Szeredi | f843980 | 2009-09-21 14:48:36 +0200 | [diff] [blame] | 486 | p = __d_path(path, root, buf, size); |
Al Viro | 02125a8 | 2011-12-05 08:43:34 -0500 | [diff] [blame] | 487 | if (!p) |
| 488 | return SEQ_SKIP; |
Miklos Szeredi | f843980 | 2009-09-21 14:48:36 +0200 | [diff] [blame] | 489 | res = PTR_ERR(p); |
Miklos Szeredi | 9d1bc601 | 2008-03-27 13:06:21 +0100 | [diff] [blame] | 490 | if (!IS_ERR(p)) { |
Miklos Szeredi | f843980 | 2009-09-21 14:48:36 +0200 | [diff] [blame] | 491 | char *end = mangle_path(buf, p, esc); |
| 492 | if (end) |
| 493 | res = end - buf; |
| 494 | else |
| 495 | res = -ENAMETOOLONG; |
Miklos Szeredi | 9d1bc601 | 2008-03-27 13:06:21 +0100 | [diff] [blame] | 496 | } |
| 497 | } |
Miklos Szeredi | f843980 | 2009-09-21 14:48:36 +0200 | [diff] [blame] | 498 | seq_commit(m, res); |
| 499 | |
Al Viro | 02125a8 | 2011-12-05 08:43:34 -0500 | [diff] [blame] | 500 | return res < 0 && res != -ENAMETOOLONG ? res : 0; |
Miklos Szeredi | 9d1bc601 | 2008-03-27 13:06:21 +0100 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | /* |
Ram Pai | 6092d04 | 2008-03-27 13:06:20 +0100 | [diff] [blame] | 504 | * returns the path of the 'dentry' from the root of its filesystem. |
| 505 | */ |
Al Viro | 8c9379e | 2011-12-08 20:18:57 -0500 | [diff] [blame] | 506 | int seq_dentry(struct seq_file *m, struct dentry *dentry, const char *esc) |
Ram Pai | 6092d04 | 2008-03-27 13:06:20 +0100 | [diff] [blame] | 507 | { |
Miklos Szeredi | f843980 | 2009-09-21 14:48:36 +0200 | [diff] [blame] | 508 | char *buf; |
| 509 | size_t size = seq_get_buf(m, &buf); |
| 510 | int res = -1; |
| 511 | |
| 512 | if (size) { |
| 513 | char *p = dentry_path(dentry, buf, size); |
Ram Pai | 6092d04 | 2008-03-27 13:06:20 +0100 | [diff] [blame] | 514 | if (!IS_ERR(p)) { |
Miklos Szeredi | f843980 | 2009-09-21 14:48:36 +0200 | [diff] [blame] | 515 | char *end = mangle_path(buf, p, esc); |
| 516 | if (end) |
| 517 | res = end - buf; |
Ram Pai | 6092d04 | 2008-03-27 13:06:20 +0100 | [diff] [blame] | 518 | } |
| 519 | } |
Miklos Szeredi | f843980 | 2009-09-21 14:48:36 +0200 | [diff] [blame] | 520 | seq_commit(m, res); |
| 521 | |
| 522 | return res; |
Ram Pai | 6092d04 | 2008-03-27 13:06:20 +0100 | [diff] [blame] | 523 | } |
Omar Sandoval | c8d3fe0 | 2015-05-18 02:16:31 -0700 | [diff] [blame] | 524 | EXPORT_SYMBOL(seq_dentry); |
Ram Pai | 6092d04 | 2008-03-27 13:06:20 +0100 | [diff] [blame] | 525 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | static void *single_start(struct seq_file *p, loff_t *pos) |
| 527 | { |
| 528 | return NULL + (*pos == 0); |
| 529 | } |
| 530 | |
| 531 | static void *single_next(struct seq_file *p, void *v, loff_t *pos) |
| 532 | { |
| 533 | ++*pos; |
| 534 | return NULL; |
| 535 | } |
| 536 | |
| 537 | static void single_stop(struct seq_file *p, void *v) |
| 538 | { |
| 539 | } |
| 540 | |
| 541 | int single_open(struct file *file, int (*show)(struct seq_file *, void *), |
| 542 | void *data) |
| 543 | { |
Alexey Dobriyan | d64d01a | 2018-04-10 16:34:49 -0700 | [diff] [blame] | 544 | struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL_ACCOUNT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | int res = -ENOMEM; |
| 546 | |
| 547 | if (op) { |
| 548 | op->start = single_start; |
| 549 | op->next = single_next; |
| 550 | op->stop = single_stop; |
| 551 | op->show = show; |
| 552 | res = seq_open(file, op); |
| 553 | if (!res) |
| 554 | ((struct seq_file *)file->private_data)->private = data; |
| 555 | else |
| 556 | kfree(op); |
| 557 | } |
| 558 | return res; |
| 559 | } |
| 560 | EXPORT_SYMBOL(single_open); |
| 561 | |
Al Viro | 2043f49 | 2013-03-31 13:43:23 -0400 | [diff] [blame] | 562 | int single_open_size(struct file *file, int (*show)(struct seq_file *, void *), |
| 563 | void *data, size_t size) |
| 564 | { |
Heiko Carstens | 058504e | 2014-07-02 15:22:37 -0700 | [diff] [blame] | 565 | char *buf = seq_buf_alloc(size); |
Al Viro | 2043f49 | 2013-03-31 13:43:23 -0400 | [diff] [blame] | 566 | int ret; |
| 567 | if (!buf) |
| 568 | return -ENOMEM; |
| 569 | ret = single_open(file, show, data); |
| 570 | if (ret) { |
Heiko Carstens | 058504e | 2014-07-02 15:22:37 -0700 | [diff] [blame] | 571 | kvfree(buf); |
Al Viro | 2043f49 | 2013-03-31 13:43:23 -0400 | [diff] [blame] | 572 | return ret; |
| 573 | } |
| 574 | ((struct seq_file *)file->private_data)->buf = buf; |
| 575 | ((struct seq_file *)file->private_data)->size = size; |
| 576 | return 0; |
| 577 | } |
| 578 | EXPORT_SYMBOL(single_open_size); |
| 579 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | int single_release(struct inode *inode, struct file *file) |
| 581 | { |
Helge Deller | 15ad7cd | 2006-12-06 20:40:36 -0800 | [diff] [blame] | 582 | const struct seq_operations *op = ((struct seq_file *)file->private_data)->op; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | int res = seq_release(inode, file); |
| 584 | kfree(op); |
| 585 | return res; |
| 586 | } |
| 587 | EXPORT_SYMBOL(single_release); |
| 588 | |
| 589 | int seq_release_private(struct inode *inode, struct file *file) |
| 590 | { |
| 591 | struct seq_file *seq = file->private_data; |
| 592 | |
| 593 | kfree(seq->private); |
| 594 | seq->private = NULL; |
| 595 | return seq_release(inode, file); |
| 596 | } |
| 597 | EXPORT_SYMBOL(seq_release_private); |
| 598 | |
Pavel Emelyanov | 3969903 | 2007-10-10 02:28:42 -0700 | [diff] [blame] | 599 | void *__seq_open_private(struct file *f, const struct seq_operations *ops, |
| 600 | int psize) |
| 601 | { |
| 602 | int rc; |
| 603 | void *private; |
| 604 | struct seq_file *seq; |
| 605 | |
Alexey Dobriyan | d64d01a | 2018-04-10 16:34:49 -0700 | [diff] [blame] | 606 | private = kzalloc(psize, GFP_KERNEL_ACCOUNT); |
Pavel Emelyanov | 3969903 | 2007-10-10 02:28:42 -0700 | [diff] [blame] | 607 | if (private == NULL) |
| 608 | goto out; |
| 609 | |
| 610 | rc = seq_open(f, ops); |
| 611 | if (rc < 0) |
| 612 | goto out_free; |
| 613 | |
| 614 | seq = f->private_data; |
| 615 | seq->private = private; |
| 616 | return private; |
| 617 | |
| 618 | out_free: |
| 619 | kfree(private); |
| 620 | out: |
| 621 | return NULL; |
| 622 | } |
| 623 | EXPORT_SYMBOL(__seq_open_private); |
| 624 | |
| 625 | int seq_open_private(struct file *filp, const struct seq_operations *ops, |
| 626 | int psize) |
| 627 | { |
| 628 | return __seq_open_private(filp, ops, psize) ? 0 : -ENOMEM; |
| 629 | } |
| 630 | EXPORT_SYMBOL(seq_open_private); |
| 631 | |
Joe Perches | 6798a8c | 2015-09-11 13:07:48 -0700 | [diff] [blame] | 632 | void seq_putc(struct seq_file *m, char c) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | { |
Joe Perches | 6798a8c | 2015-09-11 13:07:48 -0700 | [diff] [blame] | 634 | if (m->count >= m->size) |
| 635 | return; |
| 636 | |
| 637 | m->buf[m->count++] = c; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | } |
| 639 | EXPORT_SYMBOL(seq_putc); |
| 640 | |
Joe Perches | 6798a8c | 2015-09-11 13:07:48 -0700 | [diff] [blame] | 641 | void seq_puts(struct seq_file *m, const char *s) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | { |
| 643 | int len = strlen(s); |
Joe Perches | 6798a8c | 2015-09-11 13:07:48 -0700 | [diff] [blame] | 644 | |
| 645 | if (m->count + len >= m->size) { |
| 646 | seq_set_overflow(m); |
| 647 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | } |
Joe Perches | 6798a8c | 2015-09-11 13:07:48 -0700 | [diff] [blame] | 649 | memcpy(m->buf + m->count, s, len); |
| 650 | m->count += len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | } |
| 652 | EXPORT_SYMBOL(seq_puts); |
Pavel Emelianov | bcf67e1 | 2007-07-10 17:22:26 -0700 | [diff] [blame] | 653 | |
Andrei Vagin | d1be35c | 2018-04-10 16:31:16 -0700 | [diff] [blame] | 654 | /** |
KAMEZAWA Hiroyuki | 1ac101a | 2012-03-23 15:02:54 -0700 | [diff] [blame] | 655 | * A helper routine for putting decimal numbers without rich format of printf(). |
| 656 | * only 'unsigned long long' is supported. |
Andrei Vagin | d1be35c | 2018-04-10 16:31:16 -0700 | [diff] [blame] | 657 | * @m: seq_file identifying the buffer to which data should be written |
| 658 | * @delimiter: a string which is printed before the number |
| 659 | * @num: the number |
| 660 | * @width: a minimum field width |
| 661 | * |
| 662 | * This routine will put strlen(delimiter) + number into seq_filed. |
KAMEZAWA Hiroyuki | 1ac101a | 2012-03-23 15:02:54 -0700 | [diff] [blame] | 663 | * This routine is very quick when you show lots of numbers. |
| 664 | * In usual cases, it will be better to use seq_printf(). It's easier to read. |
| 665 | */ |
Andrei Vagin | d1be35c | 2018-04-10 16:31:16 -0700 | [diff] [blame] | 666 | void seq_put_decimal_ull_width(struct seq_file *m, const char *delimiter, |
| 667 | unsigned long long num, unsigned int width) |
KAMEZAWA Hiroyuki | 1ac101a | 2012-03-23 15:02:54 -0700 | [diff] [blame] | 668 | { |
| 669 | int len; |
| 670 | |
| 671 | if (m->count + 2 >= m->size) /* we'll write 2 bytes at least */ |
| 672 | goto overflow; |
| 673 | |
Andrei Vagin | 48dffbf | 2018-04-10 16:31:23 -0700 | [diff] [blame] | 674 | if (delimiter && delimiter[0]) { |
| 675 | if (delimiter[1] == 0) |
| 676 | seq_putc(m, delimiter[0]); |
| 677 | else |
| 678 | seq_puts(m, delimiter); |
| 679 | } |
Joe Perches | 75ba1d0 | 2016-10-07 17:02:20 -0700 | [diff] [blame] | 680 | |
Andrei Vagin | d1be35c | 2018-04-10 16:31:16 -0700 | [diff] [blame] | 681 | if (!width) |
| 682 | width = 1; |
| 683 | |
| 684 | if (m->count + width >= m->size) |
Joe Perches | 75ba1d0 | 2016-10-07 17:02:20 -0700 | [diff] [blame] | 685 | goto overflow; |
KAMEZAWA Hiroyuki | 1ac101a | 2012-03-23 15:02:54 -0700 | [diff] [blame] | 686 | |
Andrei Vagin | d1be35c | 2018-04-10 16:31:16 -0700 | [diff] [blame] | 687 | len = num_to_str(m->buf + m->count, m->size - m->count, num, width); |
KAMEZAWA Hiroyuki | 1ac101a | 2012-03-23 15:02:54 -0700 | [diff] [blame] | 688 | if (!len) |
| 689 | goto overflow; |
Joe Perches | 75ba1d0 | 2016-10-07 17:02:20 -0700 | [diff] [blame] | 690 | |
KAMEZAWA Hiroyuki | 1ac101a | 2012-03-23 15:02:54 -0700 | [diff] [blame] | 691 | m->count += len; |
Joe Perches | 6798a8c | 2015-09-11 13:07:48 -0700 | [diff] [blame] | 692 | return; |
| 693 | |
KAMEZAWA Hiroyuki | 1ac101a | 2012-03-23 15:02:54 -0700 | [diff] [blame] | 694 | overflow: |
KAMEZAWA Hiroyuki | e075f59 | 2012-03-23 15:02:55 -0700 | [diff] [blame] | 695 | seq_set_overflow(m); |
KAMEZAWA Hiroyuki | 1ac101a | 2012-03-23 15:02:54 -0700 | [diff] [blame] | 696 | } |
Andrei Vagin | d1be35c | 2018-04-10 16:31:16 -0700 | [diff] [blame] | 697 | |
| 698 | void seq_put_decimal_ull(struct seq_file *m, const char *delimiter, |
| 699 | unsigned long long num) |
| 700 | { |
| 701 | return seq_put_decimal_ull_width(m, delimiter, num, 0); |
| 702 | } |
KAMEZAWA Hiroyuki | 1ac101a | 2012-03-23 15:02:54 -0700 | [diff] [blame] | 703 | EXPORT_SYMBOL(seq_put_decimal_ull); |
| 704 | |
Andrei Vagin | 0e3dc01 | 2018-04-10 16:30:44 -0700 | [diff] [blame] | 705 | /** |
| 706 | * seq_put_hex_ll - put a number in hexadecimal notation |
| 707 | * @m: seq_file identifying the buffer to which data should be written |
| 708 | * @delimiter: a string which is printed before the number |
| 709 | * @v: the number |
| 710 | * @width: a minimum field width |
| 711 | * |
| 712 | * seq_put_hex_ll(m, "", v, 8) is equal to seq_printf(m, "%08llx", v) |
| 713 | * |
| 714 | * This routine is very quick when you show lots of numbers. |
| 715 | * In usual cases, it will be better to use seq_printf(). It's easier to read. |
| 716 | */ |
| 717 | void seq_put_hex_ll(struct seq_file *m, const char *delimiter, |
| 718 | unsigned long long v, unsigned int width) |
| 719 | { |
| 720 | unsigned int len; |
| 721 | int i; |
| 722 | |
| 723 | if (delimiter && delimiter[0]) { |
| 724 | if (delimiter[1] == 0) |
| 725 | seq_putc(m, delimiter[0]); |
| 726 | else |
| 727 | seq_puts(m, delimiter); |
| 728 | } |
| 729 | |
| 730 | /* If x is 0, the result of __builtin_clzll is undefined */ |
| 731 | if (v == 0) |
| 732 | len = 1; |
| 733 | else |
| 734 | len = (sizeof(v) * 8 - __builtin_clzll(v) + 3) / 4; |
| 735 | |
| 736 | if (len < width) |
| 737 | len = width; |
| 738 | |
| 739 | if (m->count + len > m->size) { |
| 740 | seq_set_overflow(m); |
| 741 | return; |
| 742 | } |
| 743 | |
| 744 | for (i = len - 1; i >= 0; i--) { |
| 745 | m->buf[m->count + i] = hex_asc[0xf & v]; |
| 746 | v = v >> 4; |
| 747 | } |
| 748 | m->count += len; |
| 749 | } |
| 750 | |
Joe Perches | 75ba1d0 | 2016-10-07 17:02:20 -0700 | [diff] [blame] | 751 | void seq_put_decimal_ll(struct seq_file *m, const char *delimiter, long long num) |
KAMEZAWA Hiroyuki | bda7bad | 2012-03-23 15:02:54 -0700 | [diff] [blame] | 752 | { |
Joe Perches | 75ba1d0 | 2016-10-07 17:02:20 -0700 | [diff] [blame] | 753 | int len; |
| 754 | |
| 755 | if (m->count + 3 >= m->size) /* we'll write 2 bytes at least */ |
| 756 | goto overflow; |
| 757 | |
Andrei Vagin | 48dffbf | 2018-04-10 16:31:23 -0700 | [diff] [blame] | 758 | if (delimiter && delimiter[0]) { |
| 759 | if (delimiter[1] == 0) |
| 760 | seq_putc(m, delimiter[0]); |
| 761 | else |
| 762 | seq_puts(m, delimiter); |
| 763 | } |
Joe Perches | 75ba1d0 | 2016-10-07 17:02:20 -0700 | [diff] [blame] | 764 | |
| 765 | if (m->count + 2 >= m->size) |
| 766 | goto overflow; |
| 767 | |
KAMEZAWA Hiroyuki | bda7bad | 2012-03-23 15:02:54 -0700 | [diff] [blame] | 768 | if (num < 0) { |
Joe Perches | 75ba1d0 | 2016-10-07 17:02:20 -0700 | [diff] [blame] | 769 | m->buf[m->count++] = '-'; |
KAMEZAWA Hiroyuki | bda7bad | 2012-03-23 15:02:54 -0700 | [diff] [blame] | 770 | num = -num; |
KAMEZAWA Hiroyuki | bda7bad | 2012-03-23 15:02:54 -0700 | [diff] [blame] | 771 | } |
Joe Perches | 75ba1d0 | 2016-10-07 17:02:20 -0700 | [diff] [blame] | 772 | |
| 773 | if (num < 10) { |
| 774 | m->buf[m->count++] = num + '0'; |
| 775 | return; |
| 776 | } |
| 777 | |
Andrei Vagin | d1be35c | 2018-04-10 16:31:16 -0700 | [diff] [blame] | 778 | len = num_to_str(m->buf + m->count, m->size - m->count, num, 0); |
Joe Perches | 75ba1d0 | 2016-10-07 17:02:20 -0700 | [diff] [blame] | 779 | if (!len) |
| 780 | goto overflow; |
| 781 | |
| 782 | m->count += len; |
| 783 | return; |
| 784 | |
| 785 | overflow: |
| 786 | seq_set_overflow(m); |
KAMEZAWA Hiroyuki | bda7bad | 2012-03-23 15:02:54 -0700 | [diff] [blame] | 787 | } |
| 788 | EXPORT_SYMBOL(seq_put_decimal_ll); |
| 789 | |
Peter Oberparleiter | 0b92360 | 2009-06-17 16:28:05 -0700 | [diff] [blame] | 790 | /** |
| 791 | * seq_write - write arbitrary data to buffer |
| 792 | * @seq: seq_file identifying the buffer to which data should be written |
| 793 | * @data: data address |
| 794 | * @len: number of bytes |
| 795 | * |
| 796 | * Return 0 on success, non-zero otherwise. |
| 797 | */ |
| 798 | int seq_write(struct seq_file *seq, const void *data, size_t len) |
| 799 | { |
| 800 | if (seq->count + len < seq->size) { |
| 801 | memcpy(seq->buf + seq->count, data, len); |
| 802 | seq->count += len; |
| 803 | return 0; |
| 804 | } |
KAMEZAWA Hiroyuki | e075f59 | 2012-03-23 15:02:55 -0700 | [diff] [blame] | 805 | seq_set_overflow(seq); |
Peter Oberparleiter | 0b92360 | 2009-06-17 16:28:05 -0700 | [diff] [blame] | 806 | return -1; |
| 807 | } |
| 808 | EXPORT_SYMBOL(seq_write); |
| 809 | |
Tetsuo Handa | 839cc2a | 2013-11-14 14:31:56 -0800 | [diff] [blame] | 810 | /** |
| 811 | * seq_pad - write padding spaces to buffer |
| 812 | * @m: seq_file identifying the buffer to which data should be written |
| 813 | * @c: the byte to append after padding if non-zero |
| 814 | */ |
| 815 | void seq_pad(struct seq_file *m, char c) |
| 816 | { |
| 817 | int size = m->pad_until - m->count; |
Andrei Vagin | 8cfa67b4 | 2018-04-10 16:30:47 -0700 | [diff] [blame] | 818 | if (size > 0) { |
| 819 | if (size + m->count > m->size) { |
| 820 | seq_set_overflow(m); |
| 821 | return; |
| 822 | } |
| 823 | memset(m->buf + m->count, ' ', size); |
| 824 | m->count += size; |
| 825 | } |
Tetsuo Handa | 839cc2a | 2013-11-14 14:31:56 -0800 | [diff] [blame] | 826 | if (c) |
| 827 | seq_putc(m, c); |
| 828 | } |
| 829 | EXPORT_SYMBOL(seq_pad); |
| 830 | |
Andy Shevchenko | 3760710 | 2015-09-09 15:38:33 -0700 | [diff] [blame] | 831 | /* A complete analogue of print_hex_dump() */ |
| 832 | void seq_hex_dump(struct seq_file *m, const char *prefix_str, int prefix_type, |
| 833 | int rowsize, int groupsize, const void *buf, size_t len, |
| 834 | bool ascii) |
| 835 | { |
| 836 | const u8 *ptr = buf; |
| 837 | int i, linelen, remaining = len; |
Andy Shevchenko | 8b91a31 | 2015-11-06 16:32:37 -0800 | [diff] [blame] | 838 | char *buffer; |
| 839 | size_t size; |
Andy Shevchenko | 3760710 | 2015-09-09 15:38:33 -0700 | [diff] [blame] | 840 | int ret; |
| 841 | |
| 842 | if (rowsize != 16 && rowsize != 32) |
| 843 | rowsize = 16; |
| 844 | |
| 845 | for (i = 0; i < len && !seq_has_overflowed(m); i += rowsize) { |
| 846 | linelen = min(remaining, rowsize); |
| 847 | remaining -= rowsize; |
| 848 | |
| 849 | switch (prefix_type) { |
| 850 | case DUMP_PREFIX_ADDRESS: |
| 851 | seq_printf(m, "%s%p: ", prefix_str, ptr + i); |
| 852 | break; |
| 853 | case DUMP_PREFIX_OFFSET: |
| 854 | seq_printf(m, "%s%.8x: ", prefix_str, i); |
| 855 | break; |
| 856 | default: |
| 857 | seq_printf(m, "%s", prefix_str); |
| 858 | break; |
| 859 | } |
| 860 | |
Andy Shevchenko | 8b91a31 | 2015-11-06 16:32:37 -0800 | [diff] [blame] | 861 | size = seq_get_buf(m, &buffer); |
Andy Shevchenko | 3760710 | 2015-09-09 15:38:33 -0700 | [diff] [blame] | 862 | ret = hex_dump_to_buffer(ptr + i, linelen, rowsize, groupsize, |
Andy Shevchenko | 8b91a31 | 2015-11-06 16:32:37 -0800 | [diff] [blame] | 863 | buffer, size, ascii); |
| 864 | seq_commit(m, ret < size ? ret : -1); |
| 865 | |
| 866 | seq_putc(m, '\n'); |
Andy Shevchenko | 3760710 | 2015-09-09 15:38:33 -0700 | [diff] [blame] | 867 | } |
| 868 | } |
| 869 | EXPORT_SYMBOL(seq_hex_dump); |
| 870 | |
Pavel Emelianov | bcf67e1 | 2007-07-10 17:22:26 -0700 | [diff] [blame] | 871 | struct list_head *seq_list_start(struct list_head *head, loff_t pos) |
| 872 | { |
| 873 | struct list_head *lh; |
| 874 | |
| 875 | list_for_each(lh, head) |
| 876 | if (pos-- == 0) |
| 877 | return lh; |
| 878 | |
| 879 | return NULL; |
| 880 | } |
Pavel Emelianov | bcf67e1 | 2007-07-10 17:22:26 -0700 | [diff] [blame] | 881 | EXPORT_SYMBOL(seq_list_start); |
| 882 | |
| 883 | struct list_head *seq_list_start_head(struct list_head *head, loff_t pos) |
| 884 | { |
| 885 | if (!pos) |
| 886 | return head; |
| 887 | |
| 888 | return seq_list_start(head, pos - 1); |
| 889 | } |
Pavel Emelianov | bcf67e1 | 2007-07-10 17:22:26 -0700 | [diff] [blame] | 890 | EXPORT_SYMBOL(seq_list_start_head); |
| 891 | |
| 892 | struct list_head *seq_list_next(void *v, struct list_head *head, loff_t *ppos) |
| 893 | { |
| 894 | struct list_head *lh; |
| 895 | |
| 896 | lh = ((struct list_head *)v)->next; |
| 897 | ++*ppos; |
| 898 | return lh == head ? NULL : lh; |
| 899 | } |
Pavel Emelianov | bcf67e1 | 2007-07-10 17:22:26 -0700 | [diff] [blame] | 900 | EXPORT_SYMBOL(seq_list_next); |
Li Zefan | 66655de | 2010-02-08 23:18:22 +0000 | [diff] [blame] | 901 | |
| 902 | /** |
| 903 | * seq_hlist_start - start an iteration of a hlist |
| 904 | * @head: the head of the hlist |
| 905 | * @pos: the start position of the sequence |
| 906 | * |
| 907 | * Called at seq_file->op->start(). |
| 908 | */ |
| 909 | struct hlist_node *seq_hlist_start(struct hlist_head *head, loff_t pos) |
| 910 | { |
| 911 | struct hlist_node *node; |
| 912 | |
| 913 | hlist_for_each(node, head) |
| 914 | if (pos-- == 0) |
| 915 | return node; |
| 916 | return NULL; |
| 917 | } |
| 918 | EXPORT_SYMBOL(seq_hlist_start); |
| 919 | |
| 920 | /** |
| 921 | * seq_hlist_start_head - start an iteration of a hlist |
| 922 | * @head: the head of the hlist |
| 923 | * @pos: the start position of the sequence |
| 924 | * |
| 925 | * Called at seq_file->op->start(). Call this function if you want to |
| 926 | * print a header at the top of the output. |
| 927 | */ |
| 928 | struct hlist_node *seq_hlist_start_head(struct hlist_head *head, loff_t pos) |
| 929 | { |
| 930 | if (!pos) |
| 931 | return SEQ_START_TOKEN; |
| 932 | |
| 933 | return seq_hlist_start(head, pos - 1); |
| 934 | } |
| 935 | EXPORT_SYMBOL(seq_hlist_start_head); |
| 936 | |
| 937 | /** |
| 938 | * seq_hlist_next - move to the next position of the hlist |
| 939 | * @v: the current iterator |
| 940 | * @head: the head of the hlist |
Randy Dunlap | 138860b | 2010-03-04 09:37:12 -0800 | [diff] [blame] | 941 | * @ppos: the current position |
Li Zefan | 66655de | 2010-02-08 23:18:22 +0000 | [diff] [blame] | 942 | * |
| 943 | * Called at seq_file->op->next(). |
| 944 | */ |
| 945 | struct hlist_node *seq_hlist_next(void *v, struct hlist_head *head, |
| 946 | loff_t *ppos) |
| 947 | { |
| 948 | struct hlist_node *node = v; |
| 949 | |
| 950 | ++*ppos; |
| 951 | if (v == SEQ_START_TOKEN) |
| 952 | return head->first; |
| 953 | else |
| 954 | return node->next; |
| 955 | } |
| 956 | EXPORT_SYMBOL(seq_hlist_next); |
stephen hemminger | 1cc5232 | 2010-02-22 07:57:17 +0000 | [diff] [blame] | 957 | |
| 958 | /** |
| 959 | * seq_hlist_start_rcu - start an iteration of a hlist protected by RCU |
| 960 | * @head: the head of the hlist |
| 961 | * @pos: the start position of the sequence |
| 962 | * |
| 963 | * Called at seq_file->op->start(). |
| 964 | * |
| 965 | * This list-traversal primitive may safely run concurrently with |
| 966 | * the _rcu list-mutation primitives such as hlist_add_head_rcu() |
| 967 | * as long as the traversal is guarded by rcu_read_lock(). |
| 968 | */ |
| 969 | struct hlist_node *seq_hlist_start_rcu(struct hlist_head *head, |
| 970 | loff_t pos) |
| 971 | { |
| 972 | struct hlist_node *node; |
| 973 | |
| 974 | __hlist_for_each_rcu(node, head) |
| 975 | if (pos-- == 0) |
| 976 | return node; |
| 977 | return NULL; |
| 978 | } |
| 979 | EXPORT_SYMBOL(seq_hlist_start_rcu); |
| 980 | |
| 981 | /** |
| 982 | * seq_hlist_start_head_rcu - start an iteration of a hlist protected by RCU |
| 983 | * @head: the head of the hlist |
| 984 | * @pos: the start position of the sequence |
| 985 | * |
| 986 | * Called at seq_file->op->start(). Call this function if you want to |
| 987 | * print a header at the top of the output. |
| 988 | * |
| 989 | * This list-traversal primitive may safely run concurrently with |
| 990 | * the _rcu list-mutation primitives such as hlist_add_head_rcu() |
| 991 | * as long as the traversal is guarded by rcu_read_lock(). |
| 992 | */ |
| 993 | struct hlist_node *seq_hlist_start_head_rcu(struct hlist_head *head, |
| 994 | loff_t pos) |
| 995 | { |
| 996 | if (!pos) |
| 997 | return SEQ_START_TOKEN; |
| 998 | |
| 999 | return seq_hlist_start_rcu(head, pos - 1); |
| 1000 | } |
| 1001 | EXPORT_SYMBOL(seq_hlist_start_head_rcu); |
| 1002 | |
| 1003 | /** |
| 1004 | * seq_hlist_next_rcu - move to the next position of the hlist protected by RCU |
| 1005 | * @v: the current iterator |
| 1006 | * @head: the head of the hlist |
Randy Dunlap | 138860b | 2010-03-04 09:37:12 -0800 | [diff] [blame] | 1007 | * @ppos: the current position |
stephen hemminger | 1cc5232 | 2010-02-22 07:57:17 +0000 | [diff] [blame] | 1008 | * |
| 1009 | * Called at seq_file->op->next(). |
| 1010 | * |
| 1011 | * This list-traversal primitive may safely run concurrently with |
| 1012 | * the _rcu list-mutation primitives such as hlist_add_head_rcu() |
| 1013 | * as long as the traversal is guarded by rcu_read_lock(). |
| 1014 | */ |
| 1015 | struct hlist_node *seq_hlist_next_rcu(void *v, |
| 1016 | struct hlist_head *head, |
| 1017 | loff_t *ppos) |
| 1018 | { |
| 1019 | struct hlist_node *node = v; |
| 1020 | |
| 1021 | ++*ppos; |
| 1022 | if (v == SEQ_START_TOKEN) |
| 1023 | return rcu_dereference(head->first); |
| 1024 | else |
| 1025 | return rcu_dereference(node->next); |
| 1026 | } |
| 1027 | EXPORT_SYMBOL(seq_hlist_next_rcu); |
Jeff Layton | 0bc7738 | 2013-06-21 08:58:21 -0400 | [diff] [blame] | 1028 | |
| 1029 | /** |
| 1030 | * seq_hlist_start_precpu - start an iteration of a percpu hlist array |
| 1031 | * @head: pointer to percpu array of struct hlist_heads |
| 1032 | * @cpu: pointer to cpu "cursor" |
| 1033 | * @pos: start position of sequence |
| 1034 | * |
| 1035 | * Called at seq_file->op->start(). |
| 1036 | */ |
| 1037 | struct hlist_node * |
| 1038 | seq_hlist_start_percpu(struct hlist_head __percpu *head, int *cpu, loff_t pos) |
| 1039 | { |
| 1040 | struct hlist_node *node; |
| 1041 | |
| 1042 | for_each_possible_cpu(*cpu) { |
| 1043 | hlist_for_each(node, per_cpu_ptr(head, *cpu)) { |
| 1044 | if (pos-- == 0) |
| 1045 | return node; |
| 1046 | } |
| 1047 | } |
| 1048 | return NULL; |
| 1049 | } |
| 1050 | EXPORT_SYMBOL(seq_hlist_start_percpu); |
| 1051 | |
| 1052 | /** |
| 1053 | * seq_hlist_next_percpu - move to the next position of the percpu hlist array |
| 1054 | * @v: pointer to current hlist_node |
| 1055 | * @head: pointer to percpu array of struct hlist_heads |
| 1056 | * @cpu: pointer to cpu "cursor" |
| 1057 | * @pos: start position of sequence |
| 1058 | * |
| 1059 | * Called at seq_file->op->next(). |
| 1060 | */ |
| 1061 | struct hlist_node * |
| 1062 | seq_hlist_next_percpu(void *v, struct hlist_head __percpu *head, |
| 1063 | int *cpu, loff_t *pos) |
| 1064 | { |
| 1065 | struct hlist_node *node = v; |
| 1066 | |
| 1067 | ++*pos; |
| 1068 | |
| 1069 | if (node->next) |
| 1070 | return node->next; |
| 1071 | |
| 1072 | for (*cpu = cpumask_next(*cpu, cpu_possible_mask); *cpu < nr_cpu_ids; |
| 1073 | *cpu = cpumask_next(*cpu, cpu_possible_mask)) { |
| 1074 | struct hlist_head *bucket = per_cpu_ptr(head, *cpu); |
| 1075 | |
| 1076 | if (!hlist_empty(bucket)) |
| 1077 | return bucket->first; |
| 1078 | } |
| 1079 | return NULL; |
| 1080 | } |
| 1081 | EXPORT_SYMBOL(seq_hlist_next_percpu); |
Alexey Dobriyan | 096523203 | 2018-04-10 16:34:45 -0700 | [diff] [blame] | 1082 | |
| 1083 | void __init seq_file_init(void) |
| 1084 | { |
Alexey Dobriyan | d64d01a | 2018-04-10 16:34:49 -0700 | [diff] [blame] | 1085 | seq_file_cache = KMEM_CACHE(seq_file, SLAB_ACCOUNT|SLAB_PANIC); |
Alexey Dobriyan | 096523203 | 2018-04-10 16:34:45 -0700 | [diff] [blame] | 1086 | } |