Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scsi: fcoe: catch invalid values for the 'enabled' attribute

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>

authored by

Hannes Reinecke and committed by
Martin K. Petersen
5cc55126 c216e876

+10 -2
+10 -2
drivers/scsi/fcoe/fcoe_sysfs.c
··· 335 335 const char *buf, size_t count) 336 336 { 337 337 struct fcoe_ctlr_device *ctlr = dev_to_ctlr(dev); 338 + bool enabled; 338 339 int rc; 340 + 341 + if (*buf == '1') 342 + enabled = true; 343 + else if (*buf == '0') 344 + enabled = false; 345 + else 346 + return -EINVAL; 339 347 340 348 switch (ctlr->enabled) { 341 349 case FCOE_CTLR_ENABLED: 342 - if (*buf == '1') 350 + if (enabled) 343 351 return count; 344 352 ctlr->enabled = FCOE_CTLR_DISABLED; 345 353 break; 346 354 case FCOE_CTLR_DISABLED: 347 - if (*buf == '0') 355 + if (!enabled) 348 356 return count; 349 357 ctlr->enabled = FCOE_CTLR_ENABLED; 350 358 break;