Skip to contentSkip to conversation

ALSA: info: Drop WARN_ON() from buffer NULL sanity check

PATCH New Takashi Iwai 1 participant 1 message Jul 17, 2020 Sound

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA: info: Drop WARN_ON() from buffer NULL sanity check

snd_info_get_line() has a sanity check of NULL buffer -- both buffer itself being NULL and buffer->buffer being NULL. Basically both checks are valid and necessary, but the problem is that it's with snd_BUG_ON() macro that triggers WARN_ON(). The latter condition (NULL buffer->buffer) can be met arbitrarily by user since the buffer is allocated at the first write, so it means that user can trigger WARN_ON() at will.

This patch addresses it by simply moving buffer->buffer NULL check out of snd_BUG_ON() so that spurious WARNING is no longer triggered.

---
 sound/core/info.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
sound/core/info.c +3 -1
index 8c6bc5241df5..9fec3070f8ba 100644
@@ -606,7 +606,9 @@ int snd_info_get_line(struct snd_info_buffer *buffer, char *line, int len)
 {
 	int c;
 
-	if (snd_BUG_ON(!buffer || !buffer->buffer))
+	if (snd_BUG_ON(!buffer))
+		return 1;
+	if (!buffer->buffer)
 		return 1;
 	if (len <= 0 || buffer->stop || buffer->error)
 		return 1;
Signature · 1 line
2.16.4