Skip to content

Commit 2c3e842

Browse files
Philipp Stannerkwilczynski
authored andcommitted
PCI: Give pcim_set_mwi() its own devres cleanup callback
Managing pci_set_mwi() with devres can easily be done with its own callback, without the necessity to store any state about it in a device-related struct. Remove the MWI state from struct pci_devres. Give pcim_set_mwi() a separate devres cleanup callback. 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 1b9469c commit 2c3e842

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

drivers/pci/devres.c

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -370,24 +370,34 @@ void __iomem *devm_pci_remap_cfg_resource(struct device *dev,
370370
}
371371
EXPORT_SYMBOL(devm_pci_remap_cfg_resource);
372372

373+
static void __pcim_clear_mwi(void *pdev_raw)
374+
{
375+
struct pci_dev *pdev = pdev_raw;
376+
377+
pci_clear_mwi(pdev);
378+
}
379+
373380
/**
374381
* pcim_set_mwi - a device-managed pci_set_mwi()
375-
* @dev: the PCI device for which MWI is enabled
382+
* @pdev: the PCI device for which MWI is enabled
376383
*
377384
* Managed pci_set_mwi().
378385
*
379386
* RETURNS: An appropriate -ERRNO error value on error, or zero for success.
380387
*/
381-
int pcim_set_mwi(struct pci_dev *dev)
388+
int pcim_set_mwi(struct pci_dev *pdev)
382389
{
383-
struct pci_devres *dr;
390+
int ret;
384391

385-
dr = find_pci_dr(dev);
386-
if (!dr)
387-
return -ENOMEM;
392+
ret = devm_add_action(&pdev->dev, __pcim_clear_mwi, pdev);
393+
if (ret != 0)
394+
return ret;
395+
396+
ret = pci_set_mwi(pdev);
397+
if (ret != 0)
398+
devm_remove_action(&pdev->dev, __pcim_clear_mwi, pdev);
388399

389-
dr->mwi = 1;
390-
return pci_set_mwi(dev);
400+
return ret;
391401
}
392402
EXPORT_SYMBOL(pcim_set_mwi);
393403

@@ -401,9 +411,6 @@ static void pcim_release(struct device *gendev, void *res)
401411
struct pci_dev *dev = to_pci_dev(gendev);
402412
struct pci_devres *this = res;
403413

404-
if (this->mwi)
405-
pci_clear_mwi(dev);
406-
407414
if (this->restore_intx)
408415
pci_intx(dev, this->orig_intx);
409416

drivers/pci/pci.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,6 @@ static inline pci_power_t mid_pci_get_power_state(struct pci_dev *pdev)
823823
struct pci_devres {
824824
unsigned int orig_intx:1;
825825
unsigned int restore_intx:1;
826-
unsigned int mwi:1;
827826
};
828827

829828
struct pci_devres *find_pci_dr(struct pci_dev *pdev);

0 commit comments

Comments
 (0)