Merge branch 'liblockdep-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-microblaze.git] / drivers / edac / edac_mc_sysfs.c
index 071f7fc..a75acea 100644 (file)
@@ -229,7 +229,7 @@ static ssize_t channel_dimm_label_show(struct device *dev,
        if (!rank->dimm->label[0])
                return 0;
 
-       return snprintf(data, EDAC_MC_LABEL_LEN, "%s\n",
+       return snprintf(data, sizeof(rank->dimm->label) + 1, "%s\n",
                        rank->dimm->label);
 }
 
@@ -240,14 +240,21 @@ static ssize_t channel_dimm_label_store(struct device *dev,
        struct csrow_info *csrow = to_csrow(dev);
        unsigned chan = to_channel(mattr);
        struct rank_info *rank = csrow->channels[chan];
+       size_t copy_count = count;
 
-       ssize_t max_size = 0;
+       if (count == 0)
+               return -EINVAL;
+
+       if (data[count - 1] == '\0' || data[count - 1] == '\n')
+               copy_count -= 1;
 
-       max_size = min((ssize_t) count, (ssize_t) EDAC_MC_LABEL_LEN - 1);
-       strncpy(rank->dimm->label, data, max_size);
-       rank->dimm->label[max_size] = '\0';
+       if (copy_count == 0 || copy_count >= sizeof(rank->dimm->label))
+               return -EINVAL;
 
-       return max_size;
+       strncpy(rank->dimm->label, data, copy_count);
+       rank->dimm->label[copy_count] = '\0';
+
+       return count;
 }
 
 /* show function for dynamic chX_ce_count attribute */
@@ -485,7 +492,7 @@ static ssize_t dimmdev_label_show(struct device *dev,
        if (!dimm->label[0])
                return 0;
 
-       return snprintf(data, EDAC_MC_LABEL_LEN, "%s\n", dimm->label);
+       return snprintf(data, sizeof(dimm->label) + 1, "%s\n", dimm->label);
 }
 
 static ssize_t dimmdev_label_store(struct device *dev,
@@ -494,14 +501,21 @@ static ssize_t dimmdev_label_store(struct device *dev,
                                   size_t count)
 {
        struct dimm_info *dimm = to_dimm(dev);
+       size_t copy_count = count;
 
-       ssize_t max_size = 0;
+       if (count == 0)
+               return -EINVAL;
+
+       if (data[count - 1] == '\0' || data[count - 1] == '\n')
+               copy_count -= 1;
 
-       max_size = min((ssize_t) count, (ssize_t) EDAC_MC_LABEL_LEN - 1);
-       strncpy(dimm->label, data, max_size);
-       dimm->label[max_size] = '\0';
+       if (copy_count == 0 || copy_count >= sizeof(dimm->label))
+               return -EINVAL;
 
-       return max_size;
+       strncpy(dimm->label, data, copy_count);
+       dimm->label[copy_count] = '\0';
+
+       return count;
 }
 
 static ssize_t dimmdev_size_show(struct device *dev,
@@ -962,7 +976,7 @@ void edac_remove_sysfs_mci_device(struct mem_ctl_info *mci)
        edac_dbg(0, "\n");
 
 #ifdef CONFIG_EDAC_DEBUG
-       debugfs_remove(mci->debugfs);
+       edac_debugfs_remove_recursive(mci->debugfs);
 #endif
 #ifdef CONFIG_EDAC_LEGACY_SYSFS
        edac_delete_csrow_objects(mci);