diff options
author | Bjorn Helgaas <bhelgaas@google.com> | 2021-07-06 18:56:25 +0300 |
---|---|---|
committer | Bjorn Helgaas <bhelgaas@google.com> | 2021-07-06 18:56:25 +0300 |
commit | 7132700067f234d37c234e5d711bb49ea06d2352 (patch) | |
tree | 58e1cdcb9bb16bb9c8fbd2bb38c599fa4d460def /drivers/pci/pci.c | |
parent | 131e4f76c9ae9636046bf04d19d43af0e4ae9807 (diff) | |
parent | 14c19b2a40b61b609f68d1d6a5518ebb1c30706f (diff) | |
download | linux-7132700067f234d37c234e5d711bb49ea06d2352.tar.xz |
Merge branch 'pci/sysfs'
- Fix dsm_label_utf16s_to_utf8s() buffer overrun (Krzysztof Wilczyński)
- Use sysfs_emit() and sysfs_emit_at() in "show" functions (Krzysztof
Wilczyński)
- Fix 'resource_alignment' newline issues (Krzysztof Wilczyński)
- Add newline to 'devspec' sysfs file (Krzysztof Wilczyński)
* pci/sysfs:
PCI/sysfs: Add 'devspec' newline
PCI/sysfs: Fix 'resource_alignment' newline issues
PCI/sysfs: Use sysfs_emit() and sysfs_emit_at() in "show" functions
PCI/sysfs: Rely on lengths from scnprintf(), dsm_label_utf16s_to_utf8s()
PCI/sysfs: Fix dsm_label_utf16s_to_utf8s() buffer overrun
# Conflicts:
# drivers/pci/p2pdma.c
Diffstat (limited to 'drivers/pci/pci.c')
-rw-r--r-- | drivers/pci/pci.c | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 452351025a09..29cb92bccf59 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -6443,34 +6443,40 @@ static ssize_t resource_alignment_show(struct bus_type *bus, char *buf) spin_lock(&resource_alignment_lock); if (resource_alignment_param) - count = scnprintf(buf, PAGE_SIZE, "%s", resource_alignment_param); + count = sysfs_emit(buf, "%s\n", resource_alignment_param); spin_unlock(&resource_alignment_lock); - /* - * When set by the command line, resource_alignment_param will not - * have a trailing line feed, which is ugly. So conditionally add - * it here. - */ - if (count >= 2 && buf[count - 2] != '\n' && count < PAGE_SIZE - 1) { - buf[count - 1] = '\n'; - buf[count++] = 0; - } - return count; } static ssize_t resource_alignment_store(struct bus_type *bus, const char *buf, size_t count) { - char *param = kstrndup(buf, count, GFP_KERNEL); + char *param, *old, *end; + + if (count >= (PAGE_SIZE - 1)) + return -EINVAL; + param = kstrndup(buf, count, GFP_KERNEL); if (!param) return -ENOMEM; + end = strchr(param, '\n'); + if (end) + *end = '\0'; + spin_lock(&resource_alignment_lock); - kfree(resource_alignment_param); - resource_alignment_param = param; + old = resource_alignment_param; + if (strlen(param)) { + resource_alignment_param = param; + } else { + kfree(param); + resource_alignment_param = NULL; + } spin_unlock(&resource_alignment_lock); + + kfree(old); + return count; } |