Skip to content

Commit dee37e9

Browse files
Philipp Stannerkwilczynski
authored andcommitted
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/[email protected] Signed-off-by: Philipp Stanner <[email protected]> Signed-off-by: Krzysztof Wilczyński <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]>
1 parent 1613e60 commit dee37e9

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

drivers/pci/devres.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ int pcim_set_mwi(struct pci_dev *dev)
161161
}
162162
EXPORT_SYMBOL(pcim_set_mwi);
163163

164+
static inline bool mask_contains_bar(int mask, int bar)
165+
{
166+
return mask & BIT(bar);
167+
}
164168

165169
static void pcim_release(struct device *gendev, void *res)
166170
{
@@ -169,7 +173,7 @@ static void pcim_release(struct device *gendev, void *res)
169173
int i;
170174

171175
for (i = 0; i < DEVICE_COUNT_RESOURCE; i++)
172-
if (this->region_mask & (1 << i))
176+
if (mask_contains_bar(this->region_mask, i))
173177
pci_release_region(dev, i);
174178

175179
if (this->mwi)
@@ -363,7 +367,7 @@ int pcim_iomap_regions(struct pci_dev *pdev, int mask, const char *name)
363367
for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
364368
unsigned long len;
365369

366-
if (!(mask & (1 << i)))
370+
if (!mask_contains_bar(mask, i))
367371
continue;
368372

369373
rc = -EINVAL;
@@ -386,7 +390,7 @@ int pcim_iomap_regions(struct pci_dev *pdev, int mask, const char *name)
386390
pci_release_region(pdev, i);
387391
err_inval:
388392
while (--i >= 0) {
389-
if (!(mask & (1 << i)))
393+
if (!mask_contains_bar(mask, i))
390394
continue;
391395
pcim_iounmap(pdev, iomap[i]);
392396
pci_release_region(pdev, i);
@@ -438,7 +442,7 @@ void pcim_iounmap_regions(struct pci_dev *pdev, int mask)
438442
return;
439443

440444
for (i = 0; i < PCIM_IOMAP_MAX; i++) {
441-
if (!(mask & (1 << i)))
445+
if (!mask_contains_bar(mask, i))
442446
continue;
443447

444448
pcim_iounmap(pdev, iomap[i]);

0 commit comments

Comments
 (0)