Skip to content

Commit 9dfc685

Browse files
Philipp Stannerbjorn-helgaas
authored andcommitted
PCI: Encourage resource request API users to supply driver name
PCI region request functions have a @name parameter (sometimes called "res_name"). It is used in a log message to inform drivers about request collisions, e.g., when another driver has requested that region already. This message is only useful when it contains the actual owner of the region, i.e., which driver requested it. So far, a great many drivers misuse the @name parameter and just pass pci_name(), which doesn't result in useful debug information. Rename "res_name" to "name". Detail @name's purpose in the docstrings. Link: https://lore.kernel.org/r/20241203100023.31152-2-pstanner@redhat.com Signed-off-by: Philipp Stanner <pstanner@redhat.com> [bhelgaas: tweak comment wording to include "driver"] Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
1 parent 40384c8 commit 9dfc685

File tree

2 files changed

+41
-44
lines changed

2 files changed

+41
-44
lines changed

drivers/pci/devres.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ static inline void pcim_addr_devres_clear(struct pcim_addr_devres *res)
101101
* @bar: BAR the range is within
102102
* @offset: offset from the BAR's start address
103103
* @maxlen: length in bytes, beginning at @offset
104-
* @name: name associated with the request
104+
* @name: name of the driver requesting the resource
105105
* @req_flags: flags for the request, e.g., for kernel-exclusive requests
106106
*
107107
* Returns: 0 on success, a negative error code on failure.
@@ -723,7 +723,7 @@ EXPORT_SYMBOL(pcim_iounmap);
723723
* pcim_iomap_region - Request and iomap a PCI BAR
724724
* @pdev: PCI device to map IO resources for
725725
* @bar: Index of a BAR to map
726-
* @name: Name associated with the request
726+
* @name: Name of the driver requesting the resource
727727
*
728728
* Returns: __iomem pointer on success, an IOMEM_ERR_PTR on failure.
729729
*
@@ -790,7 +790,7 @@ EXPORT_SYMBOL(pcim_iounmap_region);
790790
* pcim_iomap_regions - Request and iomap PCI BARs (DEPRECATED)
791791
* @pdev: PCI device to map IO resources for
792792
* @mask: Mask of BARs to request and iomap
793-
* @name: Name associated with the requests
793+
* @name: Name of the driver requesting the resources
794794
*
795795
* Returns: 0 on success, negative error code on failure.
796796
*
@@ -855,9 +855,9 @@ static int _pcim_request_region(struct pci_dev *pdev, int bar, const char *name,
855855

856856
/**
857857
* pcim_request_region - Request a PCI BAR
858-
* @pdev: PCI device to requestion region for
858+
* @pdev: PCI device to request region for
859859
* @bar: Index of BAR to request
860-
* @name: Name associated with the request
860+
* @name: Name of the driver requesting the resource
861861
*
862862
* Returns: 0 on success, a negative error code on failure.
863863
*
@@ -874,9 +874,9 @@ EXPORT_SYMBOL(pcim_request_region);
874874

875875
/**
876876
* pcim_request_region_exclusive - Request a PCI BAR exclusively
877-
* @pdev: PCI device to requestion region for
877+
* @pdev: PCI device to request region for
878878
* @bar: Index of BAR to request
879-
* @name: Name associated with the request
879+
* @name: Name of the driver requesting the resource
880880
*
881881
* Returns: 0 on success, a negative error code on failure.
882882
*
@@ -932,7 +932,7 @@ static void pcim_release_all_regions(struct pci_dev *pdev)
932932
/**
933933
* pcim_request_all_regions - Request all regions
934934
* @pdev: PCI device to map IO resources for
935-
* @name: name associated with the request
935+
* @name: name of the driver requesting the resources
936936
*
937937
* Returns: 0 on success, negative error code on failure.
938938
*

drivers/pci/pci.c

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3941,15 +3941,14 @@ EXPORT_SYMBOL(pci_release_region);
39413941
* __pci_request_region - Reserved PCI I/O and memory resource
39423942
* @pdev: PCI device whose resources are to be reserved
39433943
* @bar: BAR to be reserved
3944-
* @res_name: Name to be associated with resource.
3944+
* @name: name of the driver requesting the resource
39453945
* @exclusive: whether the region access is exclusive or not
39463946
*
39473947
* Returns: 0 on success, negative error code on failure.
39483948
*
3949-
* Mark the PCI region associated with PCI device @pdev BAR @bar as
3950-
* being reserved by owner @res_name. Do not access any
3951-
* address inside the PCI regions unless this call returns
3952-
* successfully.
3949+
* Mark the PCI region associated with PCI device @pdev BAR @bar as being
3950+
* reserved by owner @name. Do not access any address inside the PCI regions
3951+
* unless this call returns successfully.
39533952
*
39543953
* If @exclusive is set, then the region is marked so that userspace
39553954
* is explicitly not allowed to map the resource via /dev/mem or
@@ -3959,25 +3958,25 @@ EXPORT_SYMBOL(pci_release_region);
39593958
* message is also printed on failure.
39603959
*/
39613960
static int __pci_request_region(struct pci_dev *pdev, int bar,
3962-
const char *res_name, int exclusive)
3961+
const char *name, int exclusive)
39633962
{
39643963
if (pci_is_managed(pdev)) {
39653964
if (exclusive == IORESOURCE_EXCLUSIVE)
3966-
return pcim_request_region_exclusive(pdev, bar, res_name);
3965+
return pcim_request_region_exclusive(pdev, bar, name);
39673966

3968-
return pcim_request_region(pdev, bar, res_name);
3967+
return pcim_request_region(pdev, bar, name);
39693968
}
39703969

39713970
if (pci_resource_len(pdev, bar) == 0)
39723971
return 0;
39733972

39743973
if (pci_resource_flags(pdev, bar) & IORESOURCE_IO) {
39753974
if (!request_region(pci_resource_start(pdev, bar),
3976-
pci_resource_len(pdev, bar), res_name))
3975+
pci_resource_len(pdev, bar), name))
39773976
goto err_out;
39783977
} else if (pci_resource_flags(pdev, bar) & IORESOURCE_MEM) {
39793978
if (!__request_mem_region(pci_resource_start(pdev, bar),
3980-
pci_resource_len(pdev, bar), res_name,
3979+
pci_resource_len(pdev, bar), name,
39813980
exclusive))
39823981
goto err_out;
39833982
}
@@ -3994,14 +3993,13 @@ static int __pci_request_region(struct pci_dev *pdev, int bar,
39943993
* pci_request_region - Reserve PCI I/O and memory resource
39953994
* @pdev: PCI device whose resources are to be reserved
39963995
* @bar: BAR to be reserved
3997-
* @res_name: Name to be associated with resource
3996+
* @name: name of the driver requesting the resource
39983997
*
39993998
* Returns: 0 on success, negative error code on failure.
40003999
*
4001-
* Mark the PCI region associated with PCI device @pdev BAR @bar as
4002-
* being reserved by owner @res_name. Do not access any
4003-
* address inside the PCI regions unless this call returns
4004-
* successfully.
4000+
* Mark the PCI region associated with PCI device @pdev BAR @bar as being
4001+
* reserved by owner @name. Do not access any address inside the PCI regions
4002+
* unless this call returns successfully.
40054003
*
40064004
* Returns 0 on success, or %EBUSY on error. A warning
40074005
* message is also printed on failure.
@@ -4011,9 +4009,9 @@ static int __pci_request_region(struct pci_dev *pdev, int bar,
40114009
* when pcim_enable_device() has been called in advance. This hybrid feature is
40124010
* DEPRECATED! If you want managed cleanup, use the pcim_* functions instead.
40134011
*/
4014-
int pci_request_region(struct pci_dev *pdev, int bar, const char *res_name)
4012+
int pci_request_region(struct pci_dev *pdev, int bar, const char *name)
40154013
{
4016-
return __pci_request_region(pdev, bar, res_name, 0);
4014+
return __pci_request_region(pdev, bar, name, 0);
40174015
}
40184016
EXPORT_SYMBOL(pci_request_region);
40194017

@@ -4036,13 +4034,13 @@ void pci_release_selected_regions(struct pci_dev *pdev, int bars)
40364034
EXPORT_SYMBOL(pci_release_selected_regions);
40374035

40384036
static int __pci_request_selected_regions(struct pci_dev *pdev, int bars,
4039-
const char *res_name, int excl)
4037+
const char *name, int excl)
40404038
{
40414039
int i;
40424040

40434041
for (i = 0; i < PCI_STD_NUM_BARS; i++)
40444042
if (bars & (1 << i))
4045-
if (__pci_request_region(pdev, i, res_name, excl))
4043+
if (__pci_request_region(pdev, i, name, excl))
40464044
goto err_out;
40474045
return 0;
40484046

@@ -4059,7 +4057,7 @@ static int __pci_request_selected_regions(struct pci_dev *pdev, int bars,
40594057
* pci_request_selected_regions - Reserve selected PCI I/O and memory resources
40604058
* @pdev: PCI device whose resources are to be reserved
40614059
* @bars: Bitmask of BARs to be requested
4062-
* @res_name: Name to be associated with resource
4060+
* @name: Name of the driver requesting the resources
40634061
*
40644062
* Returns: 0 on success, negative error code on failure.
40654063
*
@@ -4069,17 +4067,17 @@ static int __pci_request_selected_regions(struct pci_dev *pdev, int bars,
40694067
* DEPRECATED! If you want managed cleanup, use the pcim_* functions instead.
40704068
*/
40714069
int pci_request_selected_regions(struct pci_dev *pdev, int bars,
4072-
const char *res_name)
4070+
const char *name)
40734071
{
4074-
return __pci_request_selected_regions(pdev, bars, res_name, 0);
4072+
return __pci_request_selected_regions(pdev, bars, name, 0);
40754073
}
40764074
EXPORT_SYMBOL(pci_request_selected_regions);
40774075

40784076
/**
40794077
* pci_request_selected_regions_exclusive - Request regions exclusively
40804078
* @pdev: PCI device to request regions from
40814079
* @bars: bit mask of BARs to request
4082-
* @res_name: name to be associated with the requests
4080+
* @name: name of the driver requesting the resources
40834081
*
40844082
* Returns: 0 on success, negative error code on failure.
40854083
*
@@ -4089,9 +4087,9 @@ EXPORT_SYMBOL(pci_request_selected_regions);
40894087
* DEPRECATED! If you want managed cleanup, use the pcim_* functions instead.
40904088
*/
40914089
int pci_request_selected_regions_exclusive(struct pci_dev *pdev, int bars,
4092-
const char *res_name)
4090+
const char *name)
40934091
{
4094-
return __pci_request_selected_regions(pdev, bars, res_name,
4092+
return __pci_request_selected_regions(pdev, bars, name,
40954093
IORESOURCE_EXCLUSIVE);
40964094
}
40974095
EXPORT_SYMBOL(pci_request_selected_regions_exclusive);
@@ -4114,12 +4112,11 @@ EXPORT_SYMBOL(pci_release_regions);
41144112
/**
41154113
* pci_request_regions - Reserve PCI I/O and memory resources
41164114
* @pdev: PCI device whose resources are to be reserved
4117-
* @res_name: Name to be associated with resource.
4115+
* @name: name of the driver requesting the resources
41184116
*
4119-
* Mark all PCI regions associated with PCI device @pdev as
4120-
* being reserved by owner @res_name. Do not access any
4121-
* address inside the PCI regions unless this call returns
4122-
* successfully.
4117+
* Mark all PCI regions associated with PCI device @pdev as being reserved by
4118+
* owner @name. Do not access any address inside the PCI regions unless this
4119+
* call returns successfully.
41234120
*
41244121
* Returns 0 on success, or %EBUSY on error. A warning
41254122
* message is also printed on failure.
@@ -4129,22 +4126,22 @@ EXPORT_SYMBOL(pci_release_regions);
41294126
* when pcim_enable_device() has been called in advance. This hybrid feature is
41304127
* DEPRECATED! If you want managed cleanup, use the pcim_* functions instead.
41314128
*/
4132-
int pci_request_regions(struct pci_dev *pdev, const char *res_name)
4129+
int pci_request_regions(struct pci_dev *pdev, const char *name)
41334130
{
41344131
return pci_request_selected_regions(pdev,
4135-
((1 << PCI_STD_NUM_BARS) - 1), res_name);
4132+
((1 << PCI_STD_NUM_BARS) - 1), name);
41364133
}
41374134
EXPORT_SYMBOL(pci_request_regions);
41384135

41394136
/**
41404137
* pci_request_regions_exclusive - Reserve PCI I/O and memory resources
41414138
* @pdev: PCI device whose resources are to be reserved
4142-
* @res_name: Name to be associated with resource.
4139+
* @name: name of the driver requesting the resources
41434140
*
41444141
* Returns: 0 on success, negative error code on failure.
41454142
*
41464143
* Mark all PCI regions associated with PCI device @pdev as being reserved
4147-
* by owner @res_name. Do not access any address inside the PCI regions
4144+
* by owner @name. Do not access any address inside the PCI regions
41484145
* unless this call returns successfully.
41494146
*
41504147
* pci_request_regions_exclusive() will mark the region so that /dev/mem
@@ -4158,10 +4155,10 @@ EXPORT_SYMBOL(pci_request_regions);
41584155
* when pcim_enable_device() has been called in advance. This hybrid feature is
41594156
* DEPRECATED! If you want managed cleanup, use the pcim_* functions instead.
41604157
*/
4161-
int pci_request_regions_exclusive(struct pci_dev *pdev, const char *res_name)
4158+
int pci_request_regions_exclusive(struct pci_dev *pdev, const char *name)
41624159
{
41634160
return pci_request_selected_regions_exclusive(pdev,
4164-
((1 << PCI_STD_NUM_BARS) - 1), res_name);
4161+
((1 << PCI_STD_NUM_BARS) - 1), name);
41654162
}
41664163
EXPORT_SYMBOL(pci_request_regions_exclusive);
41674164

0 commit comments

Comments
 (0)