From: Heiner Kallweit <hkallweit1@gmail.com>
To: Bjorn Helgaas <bhelgaas@google.com>
Cc: "linux-pci@vger.kernel.org" <linux-pci@vger.kernel.org>
Subject: [PATCH 2/2] PCI/VPD: Improve handling binary sysfs attribute
Date: Thu, 7 Jan 2021 22:48:55 +0100 [thread overview]
Message-ID: <f527283c-3e4e-5574-e917-519a6cc0e8b9@gmail.com> (raw)
In-Reply-To: <dba8e8ad-5243-ee84-38bd-f2b131f4b86f@gmail.com>
Since 104daa71b396 ("PCI: Determine actual VPD size on first access")
there's nothing that keeps us from using a static attribute.
This allows to significantly simplify the code.
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
drivers/pci/vpd.c | 42 +++++++++++-------------------------------
1 file changed, 11 insertions(+), 31 deletions(-)
diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c
index a3fd09105..9ef8f400e 100644
--- a/drivers/pci/vpd.c
+++ b/drivers/pci/vpd.c
@@ -21,7 +21,6 @@ struct pci_vpd_ops {
struct pci_vpd {
const struct pci_vpd_ops *ops;
- struct bin_attribute *attr; /* Descriptor for sysfs VPD entry */
struct mutex lock;
unsigned int len;
u16 flag;
@@ -397,57 +396,38 @@ void pci_vpd_release(struct pci_dev *dev)
kfree(dev->vpd);
}
-static ssize_t read_vpd_attr(struct file *filp, struct kobject *kobj,
- struct bin_attribute *bin_attr, char *buf,
- loff_t off, size_t count)
+static ssize_t vpd_read(struct file *filp, struct kobject *kobj,
+ struct bin_attribute *bin_attr, char *buf,
+ loff_t off, size_t count)
{
struct pci_dev *dev = to_pci_dev(kobj_to_dev(kobj));
return pci_read_vpd(dev, off, count, buf);
}
-static ssize_t write_vpd_attr(struct file *filp, struct kobject *kobj,
- struct bin_attribute *bin_attr, char *buf,
- loff_t off, size_t count)
+static ssize_t vpd_write(struct file *filp, struct kobject *kobj,
+ struct bin_attribute *bin_attr, char *buf,
+ loff_t off, size_t count)
{
struct pci_dev *dev = to_pci_dev(kobj_to_dev(kobj));
return pci_write_vpd(dev, off, count, buf);
}
+static const BIN_ATTR_RW(vpd, 0);
+
void pcie_vpd_create_sysfs_dev_files(struct pci_dev *dev)
{
- int retval;
- struct bin_attribute *attr;
-
if (!dev->vpd)
return;
- attr = kzalloc(sizeof(*attr), GFP_ATOMIC);
- if (!attr)
- return;
-
- sysfs_bin_attr_init(attr);
- attr->size = 0;
- attr->attr.name = "vpd";
- attr->attr.mode = S_IRUSR | S_IWUSR;
- attr->read = read_vpd_attr;
- attr->write = write_vpd_attr;
- retval = sysfs_create_bin_file(&dev->dev.kobj, attr);
- if (retval) {
- kfree(attr);
- return;
- }
-
- dev->vpd->attr = attr;
+ if (sysfs_create_bin_file(&dev->dev.kobj, &bin_attr_vpd))
+ pci_warn(dev, "can't create VPD sysfs file\n");
}
void pcie_vpd_remove_sysfs_dev_files(struct pci_dev *dev)
{
- if (dev->vpd && dev->vpd->attr) {
- sysfs_remove_bin_file(&dev->dev.kobj, dev->vpd->attr);
- kfree(dev->vpd->attr);
- }
+ sysfs_remove_bin_file(&dev->dev.kobj, &bin_attr_vpd);
}
int pci_vpd_find_tag(const u8 *buf, unsigned int off, unsigned int len, u8 rdt)
--
2.30.0
next prev parent reply other threads:[~2021-01-07 21:50 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-07 21:47 [PATCH 0/2] PCI/VPD: Improve handling binary sysfs attribute Heiner Kallweit
2021-01-07 21:48 ` [PATCH 1/2] PCI/VPD: Remove dead code from sysfs access functions Heiner Kallweit
2021-02-02 23:59 ` Bjorn Helgaas
2021-02-03 7:17 ` Heiner Kallweit
2021-01-07 21:48 ` Heiner Kallweit [this message]
2021-02-03 0:09 ` [PATCH 2/2] PCI/VPD: Improve handling binary sysfs attribute Bjorn Helgaas
2021-02-03 8:03 ` Heiner Kallweit
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=f527283c-3e4e-5574-e917-519a6cc0e8b9@gmail.com \
--to=hkallweit1@gmail.com \
--cc=bhelgaas@google.com \
--cc=linux-pci@vger.kernel.org \
/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).