diff options
author | Takashi Iwai <tiwai@suse.de> | 2013-03-13 07:11:13 -0400 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2013-03-13 07:11:13 -0400 |
commit | 0bc0ec903c45163f1263d9936f8a218fe9d3a29e (patch) | |
tree | 34065e119b60c4baab214df70344ea9019cef679 /sound/core | |
parent | 0d861ac23812428deae17de2038234b79818b964 (diff) |
ALSA: info: Small refactoring and a sanity check in snd_info_get_line()
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/core')
-rw-r--r-- | sound/core/info.c | 21 |
1 files changed, 8 insertions, 13 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,26 +700,21 @@ int snd_info_get_line(struct snd_info_buffer *buffer, char *line, int len) | |||
700 | { | 700 | { |
701 | int c = -1; | 701 | int c = -1; |
702 | 702 | ||
703 | if (snd_BUG_ON(!buffer || !buffer->buffer)) | ||
704 | return 1; | ||
703 | if (len <= 0 || buffer->stop || buffer->error) | 705 | if (len <= 0 || buffer->stop || buffer->error) |
704 | return 1; | 706 | return 1; |
705 | while (--len > 0) { | 707 | while (!buffer->stop) { |
706 | c = buffer->buffer[buffer->curr++]; | 708 | c = buffer->buffer[buffer->curr++]; |
707 | if (c == '\n') { | 709 | if (buffer->curr >= buffer->size) |
708 | if (buffer->curr >= buffer->size) | ||
709 | buffer->stop = 1; | ||
710 | break; | ||
711 | } | ||
712 | *line++ = c; | ||
713 | if (buffer->curr >= buffer->size) { | ||
714 | buffer->stop = 1; | 710 | buffer->stop = 1; |
711 | if (c == '\n') | ||
715 | break; | 712 | break; |
713 | if (len) { | ||
714 | len--; | ||
715 | *line++ = c; | ||
716 | } | 716 | } |
717 | } | 717 | } |
718 | while (c != '\n' && !buffer->stop) { | ||
719 | c = buffer->buffer[buffer->curr++]; | ||
720 | if (buffer->curr >= buffer->size) | ||
721 | buffer->stop = 1; | ||
722 | } | ||
723 | *line = '\0'; | 718 | *line = '\0'; |
724 | return 0; | 719 | return 0; |
725 | } | 720 | } |