mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-01-08 14:13:53 +00:00
PCI: Add and use devres helper for bit masks
The current devres implementation uses manual shift operations to check whether a bit in a mask is set. The code can be made more readable by writing a small helper function for that. Implement mask_contains_bar() and use it where applicable. Link: https://lore.kernel.org/r/20240613115032.29098-2-pstanner@redhat.com Signed-off-by: Philipp Stanner <pstanner@redhat.com> Signed-off-by: Krzysztof Wilczyński <kwilczynski@kernel.org> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
This commit is contained in:
parent
1613e604df
commit
dee37e90b4
@ -161,6 +161,10 @@ int pcim_set_mwi(struct pci_dev *dev)
|
|||||||
}
|
}
|
||||||
EXPORT_SYMBOL(pcim_set_mwi);
|
EXPORT_SYMBOL(pcim_set_mwi);
|
||||||
|
|
||||||
|
static inline bool mask_contains_bar(int mask, int bar)
|
||||||
|
{
|
||||||
|
return mask & BIT(bar);
|
||||||
|
}
|
||||||
|
|
||||||
static void pcim_release(struct device *gendev, void *res)
|
static void pcim_release(struct device *gendev, void *res)
|
||||||
{
|
{
|
||||||
@ -169,7 +173,7 @@ static void pcim_release(struct device *gendev, void *res)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < DEVICE_COUNT_RESOURCE; i++)
|
for (i = 0; i < DEVICE_COUNT_RESOURCE; i++)
|
||||||
if (this->region_mask & (1 << i))
|
if (mask_contains_bar(this->region_mask, i))
|
||||||
pci_release_region(dev, i);
|
pci_release_region(dev, i);
|
||||||
|
|
||||||
if (this->mwi)
|
if (this->mwi)
|
||||||
@ -363,7 +367,7 @@ int pcim_iomap_regions(struct pci_dev *pdev, int mask, const char *name)
|
|||||||
for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
|
for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
|
||||||
unsigned long len;
|
unsigned long len;
|
||||||
|
|
||||||
if (!(mask & (1 << i)))
|
if (!mask_contains_bar(mask, i))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
rc = -EINVAL;
|
rc = -EINVAL;
|
||||||
@ -386,7 +390,7 @@ int pcim_iomap_regions(struct pci_dev *pdev, int mask, const char *name)
|
|||||||
pci_release_region(pdev, i);
|
pci_release_region(pdev, i);
|
||||||
err_inval:
|
err_inval:
|
||||||
while (--i >= 0) {
|
while (--i >= 0) {
|
||||||
if (!(mask & (1 << i)))
|
if (!mask_contains_bar(mask, i))
|
||||||
continue;
|
continue;
|
||||||
pcim_iounmap(pdev, iomap[i]);
|
pcim_iounmap(pdev, iomap[i]);
|
||||||
pci_release_region(pdev, i);
|
pci_release_region(pdev, i);
|
||||||
@ -438,7 +442,7 @@ void pcim_iounmap_regions(struct pci_dev *pdev, int mask)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
for (i = 0; i < PCIM_IOMAP_MAX; i++) {
|
for (i = 0; i < PCIM_IOMAP_MAX; i++) {
|
||||||
if (!(mask & (1 << i)))
|
if (!mask_contains_bar(mask, i))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
pcim_iounmap(pdev, iomap[i]);
|
pcim_iounmap(pdev, iomap[i]);
|
||||||
|
Loading…
Reference in New Issue
Block a user