From: Bjorn Helgaas <helgaas@kernel.org>
To: "Krzysztof Wilczyński" <kw@linux.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>,
Logan Gunthorpe <logang@deltatee.com>,
Joe Perches <joe@perches.com>,
Oliver O'Halloran <oohall@gmail.com>,
Michael Ellerman <mpe@ellerman.id.au>,
Benjamin Herrenschmidt <benh@kernel.crashing.org>,
Paul Mackerras <paulus@samba.org>,
Tyrel Datwyler <tyreld@linux.ibm.com>,
Russell Currey <ruscur@russell.cc>,
Kurt Schwemmer <kurt.schwemmer@microsemi.com>,
Vidya Sagar <vidyas@nvidia.com>,
Xiongfeng Wang <wangxiongfeng2@huawei.com>,
linux-pci@vger.kernel.org
Subject: Re: [PATCH v7 3/6] PCI/sysfs: Fix trailing newline handling of resource_alignment_param
Date: Fri, 4 Jun 2021 09:28:39 -0500 [thread overview]
Message-ID: <20210604142839.GA2206654@bjorn-Precision-5520> (raw)
In-Reply-To: <20210604133230.983956-4-kw@linux.com>
On Fri, Jun 04, 2021 at 01:32:27PM +0000, Krzysztof Wilczyński wrote:
> The value of the "resource_alignment" can be specified using a kernel
> command-line argument (using the "pci=resource_alignment=") or through
> the corresponding sysfs object under the /sys/bus/pci path.
>
> Currently, when the value is set via the kernel command-line argument,
> and then subsequently accessed through sysfs object, the value read back
> will not be correct, as per:
>
> # grep -oE 'pci=resource_alignment.+' /proc/cmdline
> pci=resource_alignment=20@00:1f.2
> # cat /sys/bus/pci/resource_alignment
> 20@00:1f.
>
> This is also true when the value is set through the sysfs object, but
> the trailing newline has not been included, as per:
>
> # echo -n 20@00:1f.2 > /sys/bus/pci/resource_alignment
> # cat /sys/bus/pci/resource_alignment
> 20@00:1f.
>
> When the value set through the sysfs object includes the trailing
> newline, then reading it back will work as intended, as per:
>
> # echo 20@00:1f.2 > /sys/bus/pci/resource_alignment
> # cat /sys/bus/pci/resource_alignment
> 20@00:1f.2
>
> To fix this inconsistency, append a trailing newline in the show()
> function and strip the trailing line in the store() function if one is
> present.
>
> Also, allow for the value previously set using either a command-line
> argument or through the sysfs object to be cleared at run-time.
>
> Fixes: e499081da1a2 ("PCI: Force trailing new line to resource_alignment_param in sysfs")
> Signed-off-by: Krzysztof Wilczyński <kw@linux.com>
> Reviewed-by: Logan Gunthorpe <logang@deltatee.com>
> ---
> drivers/pci/pci.c | 34 ++++++++++++++++++++--------------
> 1 file changed, 20 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index 5ed316ea5831..68f57d86b243 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -6439,34 +6439,40 @@ static ssize_t resource_alignment_show(struct bus_type *bus, char *buf)
>
> spin_lock(&resource_alignment_lock);
> if (resource_alignment_param)
> - count = sysfs_emit(buf, "%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);
I folded this kfree change (free "param" instead of
"resource_alignment_param" as in v6) into my pci/sysfs branch.
> + resource_alignment_param = NULL;
> + }
> spin_unlock(&resource_alignment_lock);
> +
> + kfree(old);
> +
> return count;
> }
>
> --
> 2.31.1
>
next prev parent reply other threads:[~2021-06-04 14:28 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-04 13:32 [PATCH v7 0/6] PCI/sysfs: Use sysfs_emit() and sysfs_emit_at() in "show" functions Krzysztof Wilczyński
2021-06-04 13:32 ` [PATCH v7 1/6] " Krzysztof Wilczyński
2021-06-04 13:32 ` [PATCH v7 2/6] PCI/sysfs: Use return value from dsm_label_utf16s_to_utf8s() directly Krzysztof Wilczyński
2021-06-04 13:32 ` [PATCH v7 3/6] PCI/sysfs: Fix trailing newline handling of resource_alignment_param Krzysztof Wilczyński
2021-06-04 14:28 ` Bjorn Helgaas [this message]
2021-06-04 13:32 ` [PATCH v7 4/6] PCI/sysfs: Add missing trailing newline to devspec_show() Krzysztof Wilczyński
2021-06-04 13:32 ` [PATCH v7 5/6] PCI/sysfs: Only show value when driver_override is not NULL Krzysztof Wilczyński
2021-06-04 13:32 ` [PATCH v7 6/6] PCI/sysfs: Fix a buffer overrun problem with dsm_label_utf16s_to_utf8s() Krzysztof Wilczyński
2021-06-04 14:38 ` [PATCH v7 0/6] PCI/sysfs: Use sysfs_emit() and sysfs_emit_at() in "show" functions Bjorn Helgaas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210604142839.GA2206654@bjorn-Precision-5520 \
--to=helgaas@kernel.org \
--cc=benh@kernel.crashing.org \
--cc=bhelgaas@google.com \
--cc=joe@perches.com \
--cc=kurt.schwemmer@microsemi.com \
--cc=kw@linux.com \
--cc=linux-pci@vger.kernel.org \
--cc=logang@deltatee.com \
--cc=mpe@ellerman.id.au \
--cc=oohall@gmail.com \
--cc=paulus@samba.org \
--cc=ruscur@russell.cc \
--cc=tyreld@linux.ibm.com \
--cc=vidyas@nvidia.com \
--cc=wangxiongfeng2@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).