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

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

authored by

Xiongfeng Wang and committed by
Borislav Petkov
e6bbde8b 07def587

+17 -5
+17 -5
drivers/edac/edac_mc_sysfs.c
··· 474 474 struct device_attribute *mattr, char *data) 475 475 { 476 476 struct dimm_info *dimm = to_dimm(dev); 477 + ssize_t count; 477 478 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; 479 483 } 480 484 481 485 static ssize_t dimmdev_label_show(struct device *dev, ··· 817 813 char *data) 818 814 { 819 815 struct mem_ctl_info *mci = to_mci(dev); 820 - int i; 816 + int len = PAGE_SIZE; 821 817 char *p = data; 818 + int i, n; 822 819 823 820 for (i = 0; i < mci->n_layers; i++) { 824 - p += sprintf(p, "%s %d ", 825 - edac_layer_name[mci->layers[i].type], 826 - mci->layers[i].size - 1); 821 + n = scnprintf(p, len, "%s %d ", 822 + edac_layer_name[mci->layers[i].type], 823 + mci->layers[i].size - 1); 824 + len -= n; 825 + if (len <= 0) 826 + goto out; 827 + 828 + p += n; 827 829 } 828 830 831 + p += scnprintf(p, len, "\n"); 832 + out: 829 833 return p - data; 830 834 } 831 835