[PATCH 07/10] staging: unisys: fix chipsetready parsing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The chipsetready interface was using strsep() on a const buffer, which is
wrong and overcomplicated for what is being done in the function. This patch
changes it to use sscanf() instead.

Signed-off-by: Benjamin Romer <benjamin.romer@xxxxxxxxxx>
---
 .../unisys/visorchipset/visorchipset_main.c        | 40 ++++++++++------------
 1 file changed, 19 insertions(+), 21 deletions(-)

diff --git a/drivers/staging/unisys/visorchipset/visorchipset_main.c b/drivers/staging/unisys/visorchipset/visorchipset_main.c
index a82a5e7..7d0983a 100644
--- a/drivers/staging/unisys/visorchipset/visorchipset_main.c
+++ b/drivers/staging/unisys/visorchipset/visorchipset_main.c
@@ -2466,28 +2466,26 @@ visorchipset_cache_free(struct kmem_cache *pool, void *p, char *fn, int ln)
 ssize_t store_chipsetready(struct device *dev, struct device_attribute *attr,
 		const char *buf, size_t count)
 {
-	char *token, *p = (char *)buf;
-
-	token = strsep(&p, " -\t\n");
-
-	if (strcmp(token, "CALLHOMEDISK_MOUNTED") == 0) {
-		token = strsep(&p, " -\t\n");
-		/* The Call Home Disk has been mounted */
-		if (strcmp(token, "0") == 0)
-			chipset_events[0] = 1;
-	} else if (strcmp(token, "MODULES_LOADED") == 0) {
-		token = strsep(&p, " -\t\n");
-		/* All modules for the partition have been loaded */
-		if (strcmp(token, "0") == 0)
-			chipset_events[1] = 1;
-	} else if (token == NULL) {
-		/* No event specified */
-		LOGERR("No event was specified to send CHIPSET_READY response");
-		return -1;
+	char msgtype[64];
+	int msgparam;
+
+	if (sscanf(buf, "%64s %d", msgtype, &msgparam) == 2) {
+		if (strcmp(msgtype, "CALLHOMEDISK_MOUNTED") == 0) {
+			/* The Call Home Disk has been mounted */
+			if (msgparam == 0)
+				chipset_events[0] = 1;
+		} else if (strcmp(msgtype, "MODULES_LOADED") == 0) {
+			/* All modules for the partition have been loaded */
+			if (msgparam == 0)
+				chipset_events[1] = 1;
+		} else {
+			/* Unsupported event specified */
+			LOGERR("%s is an invalid event for sending CHIPSET_READY response",
+				msgtype);
+			return -1;
+		}
 	} else {
-		/* Unsupported event specified */
-		LOGERR("%s is an invalid event for sending CHIPSET_READY response",
-			token);
+		LOGERR("malformed input to chipsetready attribute");
 		return -1;
 	}
 
-- 
1.9.1

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel




[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux