PCI: Force trailing new line to resource_alignment_param in sysfs
authorLogan Gunthorpe <logang@deltatee.com>
Thu, 22 Aug 2019 16:10:13 +0000 (10:10 -0600)
committerBjorn Helgaas <bhelgaas@google.com>
Thu, 5 Sep 2019 21:47:30 +0000 (16:47 -0500)
When 'pci=resource_alignment=' is specified on the command line, there is
no trailing new line.  Then, when it's read through the corresponding sysfs
attribute, there will be no newline and a cat command will not show
correctly in a shell. If the parameter is set through sysfs a new line will
be stored and it will 'cat' correctly.

To solve this, append a new line character in the show function if one does
not already exist.

Link: https://lore.kernel.org/r/20190822161013.5481-4-logang@deltatee.com
Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
drivers/pci/pci.c

index ff3abc577a25b8baea9f456c0942dbe25665495e..5f70ff1031d2a44c1be7e6efc6cdcf2ec5b2ea67 100644 (file)
@@ -6126,6 +6126,16 @@ static ssize_t resource_alignment_show(struct bus_type *bus, char *buf)
                count = snprintf(buf, PAGE_SIZE, "%s", 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;
 }