]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
scsi: fcoe: catch invalid values for the 'enabled' attribute
authorHannes Reinecke <hare@suse.de>
Thu, 13 Oct 2016 13:10:57 +0000 (15:10 +0200)
committerMartin K. Petersen <martin.petersen@oracle.com>
Tue, 8 Nov 2016 22:29:53 +0000 (17:29 -0500)
The 'enabled' sysfs attribute only accepts the values '0' and '1',
so we should error out any other values.

Signed-off-by: Hannes Reinecke <hare@suse.com>
Acked-by: Johannes Thumshirn <jth@kernel.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/fcoe/fcoe_sysfs.c

index 9e6baac18e76954e51aa6fabfe1b0b2a24b8bf6f..9cf3d56296ab87fca59da317412199afc354e5ba 100644 (file)
@@ -335,16 +335,24 @@ static ssize_t store_ctlr_enabled(struct device *dev,
                                  const char *buf, size_t count)
 {
        struct fcoe_ctlr_device *ctlr = dev_to_ctlr(dev);
+       bool enabled;
        int rc;
 
+       if (*buf == '1')
+               enabled = true;
+       else if (*buf == '0')
+               enabled = false;
+       else
+               return -EINVAL;
+
        switch (ctlr->enabled) {
        case FCOE_CTLR_ENABLED:
-               if (*buf == '1')
+               if (enabled)
                        return count;
                ctlr->enabled = FCOE_CTLR_DISABLED;
                break;
        case FCOE_CTLR_DISABLED:
-               if (*buf == '0')
+               if (!enabled)
                        return count;
                ctlr->enabled = FCOE_CTLR_ENABLED;
                break;