diff options
| author | Mark Brown <broonie@kernel.org> | 2021-06-09 11:52:35 +0100 |
|---|---|---|
| committer | Mark Brown <broonie@kernel.org> | 2021-06-09 11:52:35 +0100 |
| commit | c441bfb5f2866de71e092c1b9d866a65978dfe1a (patch) | |
| tree | 51aca8f1e4b2de5819d4b83a4646f8448de75546 /include/linux/seq_buf.h | |
| parent | bcc0f0c078771e983a7e602eb14efa02f811445f (diff) | |
| parent | c4681547bcce777daf576925a966ffa824edd09d (diff) | |
| download | cachepc-linux-c441bfb5f2866de71e092c1b9d866a65978dfe1a.tar.gz cachepc-linux-c441bfb5f2866de71e092c1b9d866a65978dfe1a.zip | |
Merge tag 'v5.13-rc3' into asoc-5.13
Linux 5.13-rc3
Diffstat (limited to 'include/linux/seq_buf.h')
| -rw-r--r-- | include/linux/seq_buf.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/include/linux/seq_buf.h b/include/linux/seq_buf.h index 9d6c28cc4d8f..5b31c5147969 100644 --- a/include/linux/seq_buf.h +++ b/include/linux/seq_buf.h @@ -72,6 +72,31 @@ static inline unsigned int seq_buf_used(struct seq_buf *s) } /** + * seq_buf_terminate - Make sure buffer is nul terminated + * @s: the seq_buf descriptor to terminate. + * + * This makes sure that the buffer in @s is nul terminated and + * safe to read as a string. + * + * Note, if this is called when the buffer has overflowed, then + * the last byte of the buffer is zeroed, and the len will still + * point passed it. + * + * After this function is called, s->buffer is safe to use + * in string operations. + */ +static inline void seq_buf_terminate(struct seq_buf *s) +{ + if (WARN_ON(s->size == 0)) + return; + + if (seq_buf_buffer_left(s)) + s->buffer[s->len] = 0; + else + s->buffer[s->size - 1] = 0; +} + +/** * seq_buf_get_buf - get buffer to write arbitrary data to * @s: the seq_buf handle * @bufp: the beginning of the buffer is stored here |
