aboutsummaryrefslogtreecommitdiff
path: root/sound
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2013-03-13 12:11:13 +0100
committerTakashi Iwai <tiwai@suse.de>2013-03-13 12:11:13 +0100
commit0bc0ec903c45163f1263d9936f8a218fe9d3a29e (patch)
tree34065e119b60c4baab214df70344ea9019cef679 /sound
parent0d861ac23812428deae17de2038234b79818b964 (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')
-rw-r--r--sound/core/info.c21
1 files changed, 8 insertions, 13 deletions
diff --git a/sound/core/info.c b/sound/core/info.c
index 58e97b35cce..c9042b4d369 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)
{
int c = -1;
+ if (snd_BUG_ON(!buffer || !buffer->buffer))
+ return 1;
if (len <= 0 || buffer->stop || buffer->error)
return 1;
- while (--len > 0) {
+ while (!buffer->stop) {
c = buffer->buffer[buffer->curr++];
- if (c == '\n') {
- if (buffer->curr >= buffer->size)
- buffer->stop = 1;
- break;
- }
- *line++ = c;
- if (buffer->curr >= buffer->size) {
+ if (buffer->curr >= buffer->size)
buffer->stop = 1;
+ if (c == '\n')
break;
+ if (len) {
+ len--;
+ *line++ = c;
}
}
- while (c != '\n' && !buffer->stop) {
- c = buffer->buffer[buffer->curr++];
- if (buffer->curr >= buffer->size)
- buffer->stop = 1;
- }
*line = '\0';
return 0;
}