Re: [PATCH v3 1/4] PCI: sysfs: Define device attributes with DEVICE_ATTR*
From: Kelsey
Date: Tue Mar 24 2020 - 02:10:53 EST
On Sat, Mar 14, 2020 at 5:20 AM Greg Kroah-Hartman
<gregkh@xxxxxxxxxxxxxxxxxxx> wrote:
>
> On Sat, Mar 14, 2020 at 12:51:47PM +0200, Ruslan Bilovol wrote:
> > On Thu, Aug 15, 2019 at 7:01 PM Kelsey Skunberg
> > <skunberg.kelsey@xxxxxxxxx> wrote:
> > >
> > > Defining device attributes should be done through the helper
> > > DEVICE_ATTR_RO(), DEVICE_ATTR_WO(), or similar. Change all instances using
> > > __ATTR* to now use its equivalent DEVICE_ATTR*.
> > >
> > > Example of old:
> > >
> > > static struct device_attribute dev_name_##_attr=__ATTR_RO(_name);
> > >
> > > Example of new:
> > >
> > > static DEVICE_ATTR_RO(_name);
> > >
> > > Signed-off-by: Kelsey Skunberg <skunberg.kelsey@xxxxxxxxx>
> > > ---
> > > drivers/pci/pci-sysfs.c | 59 +++++++++++++++++++----------------------
> > > 1 file changed, 27 insertions(+), 32 deletions(-)
> > >
> > > diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
> > > index 965c72104150..8af7944fdccb 100644
> > > --- a/drivers/pci/pci-sysfs.c
> > > +++ b/drivers/pci/pci-sysfs.c
> > > @@ -464,9 +464,7 @@ static ssize_t dev_rescan_store(struct device *dev,
> > > }
> > > return count;
> > > }
> > > -static struct device_attribute dev_rescan_attr = __ATTR(rescan,
> > > - (S_IWUSR|S_IWGRP),
> > > - NULL, dev_rescan_store);
> > > +static DEVICE_ATTR(rescan, (S_IWUSR | S_IWGRP), NULL, dev_rescan_store);
> > >
> > > static ssize_t remove_store(struct device *dev, struct device_attribute *attr,
> > > const char *buf, size_t count)
> > > @@ -480,9 +478,8 @@ static ssize_t remove_store(struct device *dev, struct device_attribute *attr,
> > > pci_stop_and_remove_bus_device_locked(to_pci_dev(dev));
> > > return count;
> > > }
> > > -static struct device_attribute dev_remove_attr = __ATTR_IGNORE_LOCKDEP(remove,
> > > - (S_IWUSR|S_IWGRP),
> > > - NULL, remove_store);
> > > +static DEVICE_ATTR_IGNORE_LOCKDEP(remove, (S_IWUSR | S_IWGRP), NULL,
> > > + remove_store);
> > >
> > > static ssize_t dev_bus_rescan_store(struct device *dev,
> > > struct device_attribute *attr,
> > > @@ -504,7 +501,7 @@ static ssize_t dev_bus_rescan_store(struct device *dev,
> > > }
> > > return count;
> > > }
> > > -static DEVICE_ATTR(rescan, (S_IWUSR|S_IWGRP), NULL, dev_bus_rescan_store);
> > > +static DEVICE_ATTR(bus_rescan, (S_IWUSR | S_IWGRP), NULL, dev_bus_rescan_store);
> >
> > This patch renamed 'rescan' to 'bus_rescan' and broke my userspace application.
> > There is also mismatch now between real functionality and documentation
> > Documentation/ABI/testing/sysfs-bus-pci which still contains old "rescan"
> > descriptions.
> >
> > Another patch from this patch series also renamed 'rescan' to 'dev_rescan'
> >
> > Here is a comparison between two stable kernels (with and without this
> > patch series):
> >
> > v5.4
> > # find /sys -name '*rescan'
> > /sys/devices/pci0000:00/0000:00:01.2/dev_rescan
> > /sys/devices/pci0000:00/0000:00:01.0/dev_rescan
> > /sys/devices/pci0000:00/0000:00:04.0/dev_rescan
> > /sys/devices/pci0000:00/0000:00:00.0/dev_rescan
> > /sys/devices/pci0000:00/pci_bus/0000:00/bus_rescan
> > /sys/devices/pci0000:00/0000:00:01.3/dev_rescan
> > /sys/devices/pci0000:00/0000:00:03.0/dev_rescan
> > /sys/devices/pci0000:00/0000:00:01.1/dev_rescan
> > /sys/devices/pci0000:00/0000:00:02.0/dev_rescan
> > /sys/devices/pci0000:00/0000:00:05.0/dev_rescan
> > /sys/bus/pci/rescan
> >
> > v4.19
> > # find /sys -name '*rescan'
> > /sys/devices/pci0000:00/0000:00:01.2/rescan
> > /sys/devices/pci0000:00/0000:00:01.0/rescan
> > /sys/devices/pci0000:00/0000:00:04.0/rescan
> > /sys/devices/pci0000:00/0000:00:00.0/rescan
> > /sys/devices/pci0000:00/pci_bus/0000:00/rescan
> > /sys/devices/pci0000:00/0000:00:01.3/rescan
> > /sys/devices/pci0000:00/0000:00:03.0/rescan
> > /sys/devices/pci0000:00/0000:00:01.1/rescan
> > /sys/devices/pci0000:00/0000:00:02.0/rescan
> > /sys/devices/pci0000:00/0000:00:05.0/rescan
> > /sys/bus/pci/rescan
> >
> > Do we maintain this kind of API as non-changeable?
>
> Yeah, that's a bug and should be fixed, sorry for missing that on
> review.
>
> Kelsey, can you fix this up?
>
> thanks,
>
> greg k-h
I'd be happy to help get this fixed up.
Would it be proper to go back to using DEVICE_ATTR() for 'bus_rescan'
and 'dev_rescan' in order to change their names back to 'rescan'?
The name changes were done so the correct *_store() would still be
called. When using DEVICE_ATTR() the *_store() name is passed as the
last argument, as seen here:
static DEVICE_ATTR(rescan, (S_IWUSR|S_IWGRP), NULL, dev_bus_rescan_store);
When using the helper, only the name is passed and it assumes default
<name>_show(), as seen here:
static DEVICE_ATTR_WO(dev_rescan); # (This would assume
dev_rescan_store())
This can be verified in Documentation/filesystems/sysfs.txt.
There is already a rescan attribute using rescan_store(), so changing
at least one of these to DEVICE_ATTR_WO(rescan) would be conflicting.
I understand it's ideal to stay away from using DEVICE_ATTR() unless
an unusual mode is needed. Would having a different name vs
name_store() be another reason to justify using DEVICE_ATTR()?
Thank you Ruslan for pointing this out!
- Kelsey