@@ -19,6 +19,7 @@
#include <linux/pci_ids.h>
#include <linux/module.h>
#include <linux/device.h>
+#include <linux/string.h>
#include "pci.h"
enum smbios_attr_enum {
@@ -131,13 +132,78 @@ pci_remove_smbiosname_file(struct pci_dev *pdev)
sysfs_remove_group(&pdev->dev.kobj, &smbios_attr_group);
}
+static struct kobject *pci_label_kobj;
+
+static int pci_label_kobj_init(void)
+{
+ pci_label_kobj = kobject_create_and_add("pci", firmware_kobj);
+ if (pci_label_kobj == NULL)
+ return -ENOMEM;
+ return 0;
+}
+
+static int
+pci_create_smbios_label_symlink(struct pci_dev *pdev)
+{
+ char *label, *p;
+ mode_t mode;
+ int ret=-ENOMEM;
+
+ if (!pdev)
+ return -ENODEV;
+ if (pci_label_kobj == NULL)
+ if (pci_label_kobj_init())
+ return -ENOMEM;
+ label = kmalloc(PAGE_SIZE, GFP_KERNEL);
+ if (label == NULL)
+ return -ENOMEM;
+ mode = find_smbios_instance_string(pdev, label, SMBIOS_ATTR_LABEL_SHOW);
+ if (mode == 0) {
+ ret = -ENODEV;
+ goto out_free;
+ }
+ p = strim(label);
+ ret = sysfs_create_link_nowarn(pci_label_kobj, &pdev->dev.kobj, p);
+out_free:
+ kfree(label);
+ return ret;
+}
+
+static void
+pci_delete_smbios_label_symlink(struct pci_dev *pdev)
+{
+ char *label, *p;
+ mode_t mode;
+
+ if (!pdev)
+ return;
+ if (pci_label_kobj == NULL)
+ return;
+ label = kmalloc(PAGE_SIZE, GFP_KERNEL);
+ if (label == NULL)
+ return;
+ mode = find_smbios_instance_string(pdev, label, SMBIOS_ATTR_LABEL_SHOW);
+ if (mode == 0) {
+ goto out_free;
+ }
+ p = strim(label);
+ sysfs_delete_link(pci_label_kobj, &pdev->dev.kobj, p);
+
+out_free:
+ kfree(label);
+}
+
+
void pci_create_firmware_label_files(struct pci_dev *pdev)
{
if (!pci_create_smbiosname_file(pdev))
;
+ if (!pci_create_smbios_label_symlink(pdev))
+ ;
}
void pci_remove_firmware_label_files(struct pci_dev *pdev)
{
pci_remove_smbiosname_file(pdev);
+ pci_delete_smbios_label_symlink(pdev);
}