nl80211: missing sysctl flags aren't fatal
diff mbox series

Message ID 20190716234321.195337-1-briannorris@chromium.org
State Accepted
Headers show
Series
  • nl80211: missing sysctl flags aren't fatal
Related show

Commit Message

Brian Norris July 16, 2019, 11:43 p.m. UTC
The relevant flags were only added in Linux 4.6, so we shouldn't
complain because they're missing. Also, they're always missing if a
device is being removed (e.g., 'iw dev wlan0 del', or if the device is
in the process of resetting itself). So kill those 2 birds with 1 stone:
if we can't find the file, just silently skip it.

Also, we probably should *actually* propagate the error if we had a
write failure.

Signed-off-by: Brian Norris <briannorris@chromium.org>
---
 src/drivers/driver_nl80211.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

Comments

Jouni Malinen July 30, 2019, 5:58 p.m. UTC | #1
On Tue, Jul 16, 2019 at 04:43:21PM -0700, Brian Norris wrote:
> The relevant flags were only added in Linux 4.6, so we shouldn't
> complain because they're missing. Also, they're always missing if a
> device is being removed (e.g., 'iw dev wlan0 del', or if the device is
> in the process of resetting itself). So kill those 2 birds with 1 stone:
> if we can't find the file, just silently skip it.
> 
> Also, we probably should *actually* propagate the error if we had a
> write failure.

Thanks, applied.

Patch
diff mbox series

diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
index 45835a21bc92..49257ee5326d 100644
--- a/src/drivers/driver_nl80211.c
+++ b/src/drivers/driver_nl80211.c
@@ -10745,22 +10745,37 @@  static int nl80211_write_to_file(const char *name, unsigned int val)
 {
 	int fd, len;
 	char tmp[128];
+	int ret = 0;
 
 	fd = open(name, O_RDWR);
 	if (fd < 0) {
-		wpa_printf(MSG_ERROR, "nl80211: Failed to open %s: %s",
+		int level;
+		/*
+		 * Flags may not exist on older kernels, or while we're tearing
+		 * down a disappearing device.
+		 */
+		if (errno == ENOENT) {
+			ret = 0;
+			level = MSG_DEBUG;
+		} else {
+			ret = -1;
+			level = MSG_ERROR;
+		}
+		wpa_printf(level, "nl80211: Failed to open %s: %s",
 			   name, strerror(errno));
-		return fd;
+		return ret;
 	}
 
 	len = os_snprintf(tmp, sizeof(tmp), "%u\n", val);
 	len = write(fd, tmp, len);
-	if (len < 0)
+	if (len < 0) {
+		ret = -1;
 		wpa_printf(MSG_ERROR, "nl80211: Failed to write to %s: %s",
 			   name, strerror(errno));
+	}
 	close(fd);
 
-	return 0;
+	return ret;
 }