From 0bc0ec903c45163f1263d9936f8a218fe9d3a29e Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Wed, 13 Mar 2013 12:11:13 +0100 Subject: [PATCH] ALSA: info: Small refactoring and a sanity check in snd_info_get_line() Signed-off-by: Takashi Iwai --- sound/core/info.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/sound/core/info.c b/sound/core/info.c index 58e97b35cceb..c9042b4d3695 100644 --- a/sound/core/info.c +++ b/sound/core/info.c @@ -700,25 +700,20 @@ int snd_info_get_line(struct snd_info_buffer *buffer, char *line, int len) { int c = -1; + if (snd_BUG_ON(!buffer || !buffer->buffer)) + return 1; if (len <= 0 || buffer->stop || buffer->error) return 1; - while (--len > 0) { - c = buffer->buffer[buffer->curr++]; - if (c == '\n') { - if (buffer->curr >= buffer->size) - buffer->stop = 1; - break; - } - *line++ = c; - if (buffer->curr >= buffer->size) { - buffer->stop = 1; - break; - } - } - while (c != '\n' && !buffer->stop) { + while (!buffer->stop) { c = buffer->buffer[buffer->curr++]; if (buffer->curr >= buffer->size) buffer->stop = 1; + if (c == '\n') + break; + if (len) { + len--; + *line++ = c; + } } *line = '\0'; return 0;