Skip to content

Commit e6bbde8

Browse files
fenghusthusuryasaimadhu
authored andcommitted
EDAC/mc_sysfs: Add missing newlines when printing {max,dimm}_location
Reading those sysfs entries gives: [root@localhost /]# cat /sys/devices/system/edac/mc/mc0/max_location memory 3 [root@localhost /]# cat /sys/devices/system/edac/mc/mc0/dimm0/dimm_location memory 0 [root@localhost /]# Add newlines after the value it prints for better readability. [ bp: Make len a signed int and change the check to catch wraparound. Increment the pointer p only when the length check passes. Use scnprintf(). ] Signed-off-by: Xiongfeng Wang <wangxiongfeng2@huawei.com> Signed-off-by: Borislav Petkov <bp@suse.de> Link: https://lkml.kernel.org/r/1600051734-8993-1-git-send-email-wangxiongfeng2@huawei.com
1 parent 07def58 commit e6bbde8

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

drivers/edac/edac_mc_sysfs.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -474,8 +474,12 @@ static ssize_t dimmdev_location_show(struct device *dev,
474474
struct device_attribute *mattr, char *data)
475475
{
476476
struct dimm_info *dimm = to_dimm(dev);
477+
ssize_t count;
477478

478-
return edac_dimm_info_location(dimm, data, PAGE_SIZE);
479+
count = edac_dimm_info_location(dimm, data, PAGE_SIZE);
480+
count += scnprintf(data + count, PAGE_SIZE - count, "\n");
481+
482+
return count;
479483
}
480484

481485
static ssize_t dimmdev_label_show(struct device *dev,
@@ -813,15 +817,23 @@ static ssize_t mci_max_location_show(struct device *dev,
813817
char *data)
814818
{
815819
struct mem_ctl_info *mci = to_mci(dev);
816-
int i;
820+
int len = PAGE_SIZE;
817821
char *p = data;
822+
int i, n;
818823

819824
for (i = 0; i < mci->n_layers; i++) {
820-
p += sprintf(p, "%s %d ",
821-
edac_layer_name[mci->layers[i].type],
822-
mci->layers[i].size - 1);
825+
n = scnprintf(p, len, "%s %d ",
826+
edac_layer_name[mci->layers[i].type],
827+
mci->layers[i].size - 1);
828+
len -= n;
829+
if (len <= 0)
830+
goto out;
831+
832+
p += n;
823833
}
824834

835+
p += scnprintf(p, len, "\n");
836+
out:
825837
return p - data;
826838
}
827839

0 commit comments

Comments
 (0)