Skip to contentSkip to conversation

mac80211: check for allocation failure in debugfs code

PATCH Applied Dan Carpenter 2 participants 2 messages Feb 7, 2017 – Feb 8, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mac80211: check for allocation failure in debugfs code

kmalloc() can fail. Also let's move the allocation out of the declaration block so it's easier to read.

Fixes 4a5eccaa9350 ("mac80211: Show pending txqlen in debugfs.")
net/mac80211/debugfs.c +9 -2
index f62cd0e13c58..4689353aa263 100644
@@ -249,12 +249,19 @@ static ssize_t misc_read(struct file *file, char __user *user_buf,
 	struct ieee80211_local *local = file->private_data;
 	/* Max len of each line is 16 characters, plus 9 for 'pending:\n' */
 	size_t bufsz = IEEE80211_MAX_QUEUES * 16 + 9;
-	char *buf = kzalloc(bufsz, GFP_KERNEL);
-	char *pos = buf, *end = buf + bufsz - 1;
+	char *buf;
+	char *pos, *end;
 	ssize_t rv;
 	int i;
 	int ln;
 
+	buf = kzalloc(bufsz, GFP_KERNEL);
+	if (!buf)
+		return -ENOMEM;
+
+	pos = buf;
+	end = buf + bufsz - 1;
+
 	pos += scnprintf(pos, end - pos, "pending:\n");
 
 	for (i = 0; i < IEEE80211_MAX_QUEUES; i++) {
maintainer Applied
#1 lore raw
Quoted 3 lines · Dan Carpenter

kmalloc() can fail.  Also let's move the allocation out of the declaration block so it's easier to read.

Applied, thanks.

johannes