* Re: [PATCH v2 05/11] pci: use helper for safer setting of driver_override
[not found] <20220223191310.347669-6-krzysztof.kozlowski@canonical.com>
@ 2022-02-23 21:51 ` Bjorn Helgaas
0 siblings, 0 replies; 3+ messages in thread
From: Bjorn Helgaas @ 2022-02-23 21:51 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: linux-hyperv, Stuart Yoder, Rafael J. Wysocki, linux-pci,
linux-remoteproc, alsa-devel, Bjorn Andersson,
Srinivas Kandagatla, Vineeth Vijayan, Alexander Gordeev,
Fabio Estevam, linux-clk, linux-s390, Wei Liu, Stephen Hemminger,
Abel Vesa, Michael S. Tsirkin, Dexuan Cui, Linus Torvalds,
Andy Gross, NXP Linux Team, Heiko Carstens, Vasily Gorbik,
linux-arm-msm, Sascha Hauer, linux-spi, Mark Brown,
Rasmus Villemoes, Bjorn Helgaas, virtualization, linux-arm-kernel,
Laurentiu Tudor, Mathieu Poirier, Greg Kroah-Hartman,
Haiyang Zhang, Peter Oberparleiter, linux-kernel, Sven Schnelle,
Shawn Guo
In subject, to match drivers/pci/ convention, do something like:
PCI: Use driver_set_override() instead of open-coding
On Wed, Feb 23, 2022 at 08:13:04PM +0100, Krzysztof Kozlowski wrote:
> Use a helper for seting driver_override to reduce amount of duplicated
> code.
s/seting/setting/
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
> ---
> drivers/pci/pci-sysfs.c | 24 ++++--------------------
> 1 file changed, 4 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
> index 602f0fb0b007..16a163d4623e 100644
> --- a/drivers/pci/pci-sysfs.c
> +++ b/drivers/pci/pci-sysfs.c
> @@ -567,31 +567,15 @@ static ssize_t driver_override_store(struct device *dev,
> const char *buf, size_t count)
> {
> struct pci_dev *pdev = to_pci_dev(dev);
> - char *driver_override, *old, *cp;
> + int ret;
>
> /* We need to keep extra room for a newline */
> if (count >= (PAGE_SIZE - 1))
> return -EINVAL;
This check makes no sense in the new function. Michael alluded to
this as well.
> - driver_override = kstrndup(buf, count, GFP_KERNEL);
> - if (!driver_override)
> - return -ENOMEM;
> -
> - cp = strchr(driver_override, '\n');
> - if (cp)
> - *cp = '\0';
> -
> - device_lock(dev);
> - old = pdev->driver_override;
> - if (strlen(driver_override)) {
> - pdev->driver_override = driver_override;
> - } else {
> - kfree(driver_override);
> - pdev->driver_override = NULL;
> - }
> - device_unlock(dev);
> -
> - kfree(old);
> + ret = driver_set_override(dev, &pdev->driver_override, buf);
> + if (ret)
> + return ret;
>
> return count;
> }
> --
> 2.32.0
>
>
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2 05/11] pci: use helper for safer setting of driver_override
[not found] <f7347531-8aa4-c011-d405-dea93e29779f@canonical.com>
@ 2022-02-24 23:52 ` Bjorn Helgaas
0 siblings, 0 replies; 3+ messages in thread
From: Bjorn Helgaas @ 2022-02-24 23:52 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: linux-hyperv, Stuart Yoder, Rafael J. Wysocki, linux-pci,
linux-remoteproc, alsa-devel, Bjorn Andersson,
Srinivas Kandagatla, Vineeth Vijayan, Alexander Gordeev,
Fabio Estevam, linux-clk, linux-s390, Wei Liu, Stephen Hemminger,
Abel Vesa, Michael S. Tsirkin, Dexuan Cui, Linus Torvalds,
Andy Gross, NXP Linux Team, Heiko Carstens, Vasily Gorbik,
linux-arm-msm, Sascha Hauer, linux-spi, Mark Brown,
Rasmus Villemoes, Bjorn Helgaas, virtualization, linux-arm-kernel,
Laurentiu Tudor, Mathieu Poirier, Greg Kroah-Hartman,
Haiyang Zhang, Peter Oberparleiter, linux-kernel, Sven Schnelle,
Shawn Guo
On Thu, Feb 24, 2022 at 08:49:15AM +0100, Krzysztof Kozlowski wrote:
> On 23/02/2022 22:51, Bjorn Helgaas wrote:
> > In subject, to match drivers/pci/ convention, do something like:
> >
> > PCI: Use driver_set_override() instead of open-coding
> >
> > On Wed, Feb 23, 2022 at 08:13:04PM +0100, Krzysztof Kozlowski wrote:
> >> Use a helper for seting driver_override to reduce amount of duplicated
> >> code.
> >> @@ -567,31 +567,15 @@ static ssize_t driver_override_store(struct device *dev,
> >> const char *buf, size_t count)
> >> {
> >> struct pci_dev *pdev = to_pci_dev(dev);
> >> - char *driver_override, *old, *cp;
> >> + int ret;
> >>
> >> /* We need to keep extra room for a newline */
> >> if (count >= (PAGE_SIZE - 1))
> >> return -EINVAL;
> >
> > This check makes no sense in the new function. Michael alluded to
> > this as well.
>
> I am not sure if I got your comment properly. You mean here:
> 1. Move this check to driver_set_override()?
> 2. Remove the check entirely?
I was mistaken about the purpose of the comment and the check. I
thought it had to do with *this* function, and this function doesn't
add a newline, and there's no obvious connection with PAGE_SIZE.
But looking closer, I think the "extra room for a newline" is really
to make sure that *driver_override_show()* can add a newline and have
it still fit within the PAGE_SIZE sysfs limit.
Most driver_override_*() functions have the same comment, so maybe
this was obvious to everybody except me :) I do see that spi.c adds
"when displaying value" at the end, which helps a lot.
Sorry for the wild goose chase.
> >> - driver_override = kstrndup(buf, count, GFP_KERNEL);
> >> - if (!driver_override)
> >> - return -ENOMEM;
> >> -
> >> - cp = strchr(driver_override, '\n');
> >> - if (cp)
> >> - *cp = '\0';
> >> -
> >> - device_lock(dev);
> >> - old = pdev->driver_override;
> >> - if (strlen(driver_override)) {
> >> - pdev->driver_override = driver_override;
> >> - } else {
> >> - kfree(driver_override);
> >> - pdev->driver_override = NULL;
> >> - }
> >> - device_unlock(dev);
> >> -
> >> - kfree(old);
> >> + ret = driver_set_override(dev, &pdev->driver_override, buf);
> >> + if (ret)
> >> + return ret;
> >>
> >> return count;
> >> }
> >> --
> >> 2.32.0
> >>
> >>
> >> _______________________________________________
> >> linux-arm-kernel mailing list
> >> linux-arm-kernel@lists.infradead.org
> >> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
>
>
> Best regards,
> Krzysztof
>
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2 05/11] pci: use helper for safer setting of driver_override
[not found] <0aff95ff-5b79-8ae9-48fd-720a9f27cbce@canonical.com>
@ 2022-02-25 17:13 ` Bjorn Helgaas
0 siblings, 0 replies; 3+ messages in thread
From: Bjorn Helgaas @ 2022-02-25 17:13 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: linux-hyperv, Stuart Yoder, Rafael J. Wysocki, linux-pci,
linux-remoteproc, alsa-devel, Bjorn Andersson,
Srinivas Kandagatla, Vineeth Vijayan, Alexander Gordeev,
Fabio Estevam, linux-clk, linux-s390, Wei Liu, Stephen Hemminger,
Abel Vesa, Michael S. Tsirkin, Dexuan Cui, Linus Torvalds,
Andy Gross, NXP Linux Team, Heiko Carstens, Vasily Gorbik,
linux-arm-msm, Sascha Hauer, linux-spi, Mark Brown,
Rasmus Villemoes, Bjorn Helgaas, virtualization, linux-arm-kernel,
Laurentiu Tudor, Mathieu Poirier, Greg Kroah-Hartman,
Haiyang Zhang, Peter Oberparleiter, linux-kernel, Sven Schnelle,
Shawn Guo
On Fri, Feb 25, 2022 at 10:36:20AM +0100, Krzysztof Kozlowski wrote:
> On 25/02/2022 00:52, Bjorn Helgaas wrote:
> > On Thu, Feb 24, 2022 at 08:49:15AM +0100, Krzysztof Kozlowski wrote:
> >> On 23/02/2022 22:51, Bjorn Helgaas wrote:
> >>> In subject, to match drivers/pci/ convention, do something like:
> >>>
> >>> PCI: Use driver_set_override() instead of open-coding
> >>>
> >>> On Wed, Feb 23, 2022 at 08:13:04PM +0100, Krzysztof Kozlowski wrote:
> >>>> Use a helper for seting driver_override to reduce amount of duplicated
> >>>> code.
> >>>> @@ -567,31 +567,15 @@ static ssize_t driver_override_store(struct device *dev,
> >>>> const char *buf, size_t count)
> >>>> {
> >>>> struct pci_dev *pdev = to_pci_dev(dev);
> >>>> - char *driver_override, *old, *cp;
> >>>> + int ret;
> >>>>
> >>>> /* We need to keep extra room for a newline */
> >>>> if (count >= (PAGE_SIZE - 1))
> >>>> return -EINVAL;
> >>>
> >>> This check makes no sense in the new function. Michael alluded to
> >>> this as well.
> >>
> >> I am not sure if I got your comment properly. You mean here:
> >> 1. Move this check to driver_set_override()?
> >> 2. Remove the check entirely?
> >
> > I was mistaken about the purpose of the comment and the check. I
> > thought it had to do with *this* function, and this function doesn't
> > add a newline, and there's no obvious connection with PAGE_SIZE.
> >
> > But looking closer, I think the "extra room for a newline" is really
> > to make sure that *driver_override_show()* can add a newline and have
> > it still fit within the PAGE_SIZE sysfs limit.
> >
> > Most driver_override_*() functions have the same comment, so maybe
> > this was obvious to everybody except me :) I do see that spi.c adds
> > "when displaying value" at the end, which helps a lot.
> >
> > Sorry for the wild goose chase.
>
> I think I will move this check anyway to driver_set_override() helper,
> because there is no particular benefit to have duplicated all over. The
> helper will receive "count" argument so can perform all checks.
Thanks, I think that would be good!
Bjorn
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-02-25 17:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20220223191310.347669-6-krzysztof.kozlowski@canonical.com>
2022-02-23 21:51 ` [PATCH v2 05/11] pci: use helper for safer setting of driver_override Bjorn Helgaas
[not found] <f7347531-8aa4-c011-d405-dea93e29779f@canonical.com>
2022-02-24 23:52 ` Bjorn Helgaas
[not found] <0aff95ff-5b79-8ae9-48fd-720a9f27cbce@canonical.com>
2022-02-25 17:13 ` Bjorn Helgaas
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).