EDAC: Don't allow empty DIMM labels
authorToshi Kani <toshi.kani@hpe.com>
Thu, 24 Sep 2015 19:59:27 +0000 (13:59 -0600)
committerBorislav Petkov <bp@suse.de>
Mon, 28 Sep 2015 14:39:05 +0000 (16:39 +0200)
Updating dimm_label to an empty string does not make much sense. Change
the sysfs dimm_label store operation to fail a request when an input
string is empty.

Suggested-by: Borislav Petkov <bp@alien8.de>
Signed-off-by: Toshi Kani <toshi.kani@hpe.com>
Cc: elliott@hpe.com
Cc: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Cc: Tony Luck <tony.luck@intel.com>
Cc: linux-edac <linux-edac@vger.kernel.org>
Link: http://lkml.kernel.org/r/1443124767.25474.172.camel@hpe.com
Signed-off-by: Borislav Petkov <bp@suse.de>
drivers/edac/edac_mc_sysfs.c

index bf6b6802105c2c336d126adcc941180f79b9a0c4..3929391f0b920e9feaaaea9da5054099272b1986 100644 (file)
@@ -248,7 +248,7 @@ static ssize_t channel_dimm_label_store(struct device *dev,
        if (data[count - 1] == '\0' || data[count - 1] == '\n')
                copy_count -= 1;
 
-       if (copy_count >= sizeof(rank->dimm->label))
+       if (copy_count == 0 || copy_count >= sizeof(rank->dimm->label))
                return -EINVAL;
 
        strncpy(rank->dimm->label, data, copy_count);
@@ -509,7 +509,7 @@ static ssize_t dimmdev_label_store(struct device *dev,
        if (data[count - 1] == '\0' || data[count - 1] == '\n')
                copy_count -= 1;
 
-       if (copy_count >= sizeof(dimm->label))
+       if (copy_count == 0 || copy_count >= sizeof(dimm->label))
                return -EINVAL;
 
        strncpy(dimm->label, data, copy_count);