Skip to contentSkip to conversation

PCI: Remove duplicate #ifdef in pci_try_set_mwi()

PATCH In review Utkarsh Verma 2 participants 3 messages Aug 11, 2021 – Aug 12, 2021 PCI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PCI: Remove duplicate #ifdef in pci_try_set_mwi()

Remove the unnecessary #ifdef PCI_DISABLE_MWI, because pci_set_mwi() performs the same check.

---
 drivers/pci/pci.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/pci/pci.c +0 -4
index aacf575c15cf..7d4c7c294ef2 100644
@@ -4456,11 +4456,7 @@ EXPORT_SYMBOL(pcim_set_mwi);
  */
 int pci_try_set_mwi(struct pci_dev *dev)
 {
-#ifdef PCI_DISABLE_MWI
-	return 0;
-#else
 	return pci_set_mwi(dev);
-#endif
 }
 EXPORT_SYMBOL(pci_try_set_mwi);
 
Signature · 1 line
2.25.1
#1 lore raw
Quoted 13 lines · Utkarsh Verma

Remove the unnecessary #ifdef PCI_DISABLE_MWI, because pci_set_mwi() performs the same check.

---
 drivers/pci/pci.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/pci/pci.c +0 -0
index aacf575c15cf..7d4c7c294ef2 100644

drivers/pci/pci.c EXPORT_SYMBOL(pcim_set_mwi); · line 4461

Quoted 10 lines
drivers/pci/pci.c +0 -4
@@ -4456,11 +4456,7 @@ EXPORT_SYMBOL(pcim_set_mwi);
  */
 int pci_try_set_mwi(struct pci_dev *dev)
 {
-#ifdef PCI_DISABLE_MWI
-	return 0;
-#else
 	return pci_set_mwi(dev);
-#endif
 }
 EXPORT_SYMBOL(pci_try_set_mwi);

If this is the case, why do we even need pci_try_set_mwi()? Why not just replace it with calls to pci_set_mwi() and then delete this one?

thanks,

greg k-h

#2 lore raw
Quoted 19 lines · Greg KH
Quoted 18 lines · Utkarsh Verma

Remove the unnecessary #ifdef PCI_DISABLE_MWI, because pci_set_mwi() performs the same check.

---
 drivers/pci/pci.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/pci/pci.c +0 -2
index aacf575c15cf..7d4c7c294ef2 100644
@@ -4456,11 +4456,7 @@ EXPORT_SYMBOL(pcim_set_mwi);
  */
 int pci_try_set_mwi(struct pci_dev *dev)
 {
-#ifdef PCI_DISABLE_MWI
-	return 0;
Quoted 8 lines

drivers/pci/pci.c EXPORT_SYMBOL(pcim_set_mwi); · line 4461

Quoted 5 lines
drivers/pci/pci.c +0 -2
-#else
 	return pci_set_mwi(dev);
-#endif
 }
 EXPORT_SYMBOL(pci_try_set_mwi);

If this is the case, why do we even need pci_try_set_mwi()? Why not just replace it with calls to pci_set_mwi() and then delete this one?

The only difference between the pci_set_mwi() and pci_try_set_mwi() is that, pci_set_mwi() is declared as __must_check which forces return value checking.

The reason why pci_try_set_mwi() was introduced in the first place was because it gives the drivers both options:
(1) most of the drivers don't require checking the return value, and they can safely ignore the errors values returned if any, so pci_try_set_mwi() can be used.
(2) But for some of the drivers it is nice to check the return values, and generate proper warnings for error handling. By using the pci_set_mwi(), we force the driver for proper error checking.

So both the functions are similar but have different purposes, and it seems a more appropriate design.
The whole argument about adding this function:
https://lore.kernel.org/linux-ide/[email protected]/

Also earlier there was a patch that removed the pci_try_set_mwi() and __must_check attribute from pci_set_mwi(), just like you wanted,
https://lore.kernel.org/linux-pci/[email protected]/
But it was not accepted because Bjorn wasn't convinced and he also gave the above argument and that we should not break something in the name of cleaning it up.

But it is safe to only remove the duplicate #ifdef block inside the pci_try_set_mwi().

Best Regards,
Utkarsh Verma