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.ro...@unisys.com>
---
 .../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
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

Reply via email to