RAS/CEC: Do not set decay value on error
authorBorislav Petkov <bp@suse.de>
Sat, 20 Apr 2019 19:33:08 +0000 (21:33 +0200)
committerBorislav Petkov <bp@suse.de>
Sat, 8 Jun 2019 15:34:36 +0000 (17:34 +0200)
When the value requested doesn't match the allowed (min,max) range,
the @data buffer should not be modified with the invalid value because
reading "decay_interval" shows it otherwise as if the previous write
succeeded.

Move the data write after the check.

Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: Tony Luck <tony.luck@intel.com>
Cc: linux-edac <linux-edac@vger.kernel.org>
drivers/ras/cec.c

index 73a975c26f9f4bda8e3dbadd0688301d15a87933..31868bd99e8d5e3c58703f58cf40e06d603e99a3 100644 (file)
@@ -371,17 +371,17 @@ DEFINE_DEBUGFS_ATTRIBUTE(pfn_ops, u64_get, pfn_set, "0x%llx\n");
 
 static int decay_interval_set(void *data, u64 val)
 {
-       *(u64 *)data = val;
-
        if (val < CEC_DECAY_MIN_INTERVAL)
                return -EINVAL;
 
        if (val > CEC_DECAY_MAX_INTERVAL)
                return -EINVAL;
 
+       *(u64 *)data   = val;
        decay_interval = val;
 
        cec_mod_work(decay_interval);
+
        return 0;
 }
 DEFINE_DEBUGFS_ATTRIBUTE(decay_interval_ops, u64_get, decay_interval_set, "%lld\n");