Skip to content

Commit 51204fa

Browse files
committed
Merge branch 'pci/misc'
- Fix whitespace issues (Li Jun) - Fix pci_acpi_preserve_config() memory leak (Nirmoy Das) - Add sysfs 'serial_number' file to expose the Device Serial Number (Matthew Wood) * pci/misc: PCI/sysfs: Expose PCI device serial number PCI/ACPI: Fix pci_acpi_preserve_config() memory leak
2 parents 43c5934 + cf6ee09 commit 51204fa

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

Documentation/ABI/testing/sysfs-bus-pci

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,3 +612,12 @@ Description:
612612

613613
# ls doe_features
614614
0001:01 0001:02 doe_discovery
615+
616+
What: /sys/bus/pci/devices/.../serial_number
617+
Date: December 2025
618+
Contact: Matthew Wood <[email protected]>
619+
Description:
620+
This is visible only for PCI devices that support the serial
621+
number extended capability. The file is read only and due to
622+
the possible sensitivity of accessible serial numbers, admin
623+
only.

drivers/pci/pci-acpi.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ phys_addr_t acpi_pci_root_get_mcfg_addr(acpi_handle handle)
122122

123123
bool pci_acpi_preserve_config(struct pci_host_bridge *host_bridge)
124124
{
125+
bool ret = false;
126+
125127
if (ACPI_HANDLE(&host_bridge->dev)) {
126128
union acpi_object *obj;
127129

@@ -135,11 +137,11 @@ bool pci_acpi_preserve_config(struct pci_host_bridge *host_bridge)
135137
1, DSM_PCI_PRESERVE_BOOT_CONFIG,
136138
NULL, ACPI_TYPE_INTEGER);
137139
if (obj && obj->integer.value == 0)
138-
return true;
140+
ret = true;
139141
ACPI_FREE(obj);
140142
}
141143

142-
return false;
144+
return ret;
143145
}
144146

145147
/* _HPX PCI Setting Record (Type 0); same as _HPP */

drivers/pci/pci-sysfs.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <linux/msi.h>
3131
#include <linux/of.h>
3232
#include <linux/aperture.h>
33+
#include <linux/unaligned.h>
3334
#include "pci.h"
3435

3536
#ifndef ARCH_PCI_DEV_GROUPS
@@ -719,6 +720,22 @@ static ssize_t boot_vga_show(struct device *dev, struct device_attribute *attr,
719720
}
720721
static DEVICE_ATTR_RO(boot_vga);
721722

723+
static ssize_t serial_number_show(struct device *dev,
724+
struct device_attribute *attr, char *buf)
725+
{
726+
struct pci_dev *pci_dev = to_pci_dev(dev);
727+
u64 dsn;
728+
u8 bytes[8];
729+
730+
dsn = pci_get_dsn(pci_dev);
731+
if (!dsn)
732+
return -EIO;
733+
734+
put_unaligned_be64(dsn, bytes);
735+
return sysfs_emit(buf, "%8phD\n", bytes);
736+
}
737+
static DEVICE_ATTR_ADMIN_RO(serial_number);
738+
722739
static ssize_t pci_read_config(struct file *filp, struct kobject *kobj,
723740
const struct bin_attribute *bin_attr, char *buf,
724741
loff_t off, size_t count)
@@ -1729,6 +1746,7 @@ late_initcall(pci_sysfs_init);
17291746

17301747
static struct attribute *pci_dev_dev_attrs[] = {
17311748
&dev_attr_boot_vga.attr,
1749+
&dev_attr_serial_number.attr,
17321750
NULL,
17331751
};
17341752

@@ -1741,6 +1759,9 @@ static umode_t pci_dev_attrs_are_visible(struct kobject *kobj,
17411759
if (a == &dev_attr_boot_vga.attr && pci_is_vga(pdev))
17421760
return a->mode;
17431761

1762+
if (a == &dev_attr_serial_number.attr && pci_get_dsn(pdev))
1763+
return a->mode;
1764+
17441765
return 0;
17451766
}
17461767

0 commit comments

Comments
 (0)