i2c: ismt: improve usage of devres API
Subsystems (2)
PATCH 1/6 i2c: ismt: improve usage of devres API
pcim_release() will release any requested region. There is no need to duplicate this effort in the driver.
--- drivers/i2c/busses/i2c-ismt.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-)
drivers/i2c/busses/i2c-ismt.c +5 -13
@@ -904,8 +904,7 @@ ismt_probe(struct pci_dev *pdev, const struct pci_device_id *id) priv->smba =pcim_iomap (pdev,SMBBAR , len);if (!priv->smba) {dev_err (&pdev->dev,"Unable to ioremap SMBus BAR\n" ); - err = -ENODEV ; - goto fail; +return -ENODEV ; } if ((pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0) ||
@@ -915,32 +914,26 @@ ismt_probe(struct pci_dev *pdev, const struct pci_device_id *id) DMA_BIT_MASK(32)) != 0)) {dev_err (&pdev->dev,"pci_set_dma_mask fail %p\n" , pdev); - err = -ENODEV ; - goto fail; +return -ENODEV ; } } err =ismt_dev_init (priv);if (err) - goto fail; +return err;ismt_hw_init (priv); err =ismt_int_init (priv);if (err) - goto fail; +return err; err =i2c_add_adapter (&priv->adapter);if (err) {dev_err (&pdev->dev,"Failed to add SMBus iSMT adapter\n" ); - err = -ENODEV ; - goto fail; +return -ENODEV ; }return 0 ; - -fail: -pci_release_region (pdev,SMBBAR ); -return err; }/**
@@ -952,7 +945,6 @@ static void ismt_remove(struct pci_dev *pdev)struct ismt_priv *priv =pci_get_drvdata (pdev);i2c_del_adapter (&priv->adapter); -pci_release_region (pdev,SMBBAR ); }/**
Signature · 1 line
2.5.1
PATCH 2/6 i2c: ismt: PCI core handles power state for us
In reply to a message not in the archiveThere is no need to repeat the work that is already done in the PCI driver core. Remove suspend and resume callbacks.
Note that there is no more calls performed to enable or disable a PCI device during suspend-resume cycle. Nowadays they seems to be superflous. Someone can read more in [1].
[1] https://www.kernel.org/doc/ols/2009/ols2009-pages-319-330.pdf
--- drivers/i2c/busses/i2c-ismt.c | 33 --------------------------------- 1 file changed, 33 deletions(-)
drivers/i2c/busses/i2c-ismt.c +0 -33
@@ -947,44 +947,11 @@ static void ismt_remove(struct pci_dev *pdev)i2c_del_adapter (&priv->adapter); } -/** -* ismt_suspend() - place the device in suspend -* @pdev: PCI-Express device -* @mesg: PM message -*/ -#ifdef CONFIG_PM -static int ismt_suspend (struct pci_dev *pdev,pm_message_t mesg) -{ -pci_save_state (pdev); -pci_set_power_state (pdev,pci_choose_state (pdev, mesg)); -return 0 ; -} - -/** -* ismt_resume() - PCI resume code -* @pdev: PCI-Express device -*/ -static int ismt_resume (struct pci_dev *pdev) -{ -pci_set_power_state (pdev,PCI_D0 ); -pci_restore_state (pdev); -return pci_enable_device (pdev); -} - -#else - -#define ismt_suspend NULL -#define ismt_resume NULL - -#endif -static struct pci_driver ismt_driver = { .name ="ismt_smbus" , .id_table = ismt_ids, .probe = ismt_probe, .remove = ismt_remove, - .suspend = ismt_suspend, - .resume = ismt_resume, };module_pci_driver (ismt_driver);
Signature · 1 line
2.5.1
PATCH 3/6 i2c: ismt: do not duplicate msi_enabled flag
In reply to a message not in the archivestruct pci_dev already has a flag to track if MSI is enabled or not. Use it directly.
--- drivers/i2c/busses/i2c-ismt.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/i2c/busses/i2c-ismt.c +1 -5
@@ -172,7 +172,6 @@ struct ismt_priv {u8 head;/* ring buffer head pointer */ struct completion cmp;/* interrupt completion */ u8 dma_buffer[I2C_SMBUS_BLOCK_MAX +1 ];/* temp R/W data buffer */ -bool using_msi;/* type of interrupt flag */ };/**
@@ -398,7 +397,7 @@ static int ismt_access(struct i2c_adapter *adap, u16 addr, desc->tgtaddr_rw =ISMT_DESC_ADDR_RW (addr, read_write);/* Initialize common control bits */ -if (likely (priv->using_msi)) +if (likely (pci_dev_msi_enabled (priv->pci_dev))) desc->control =ISMT_DESC_INT |ISMT_DESC_FAIR ;else desc->control =ISMT_DESC_FAIR ;
@@ -806,7 +805,6 @@ static int ismt_int_init(struct ismt_priv *priv) goto intx; } - priv->using_msi = true; goto done;/* Try using legacy interrupts */
@@ -822,8 +820,6 @@ intx:return -ENODEV ; } - priv->using_msi = false; - done:return 0 ; }
Signature · 1 line
2.5.1
PATCH 4/6 i2c: ismt: propagate actual error code
In reply to a message not in the archivePropagate actual return code when requesting interrupt fails.
--- drivers/i2c/busses/i2c-ismt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-ismt.c +1 -1
@@ -817,7 +817,7 @@ intx: priv);if (err) {dev_err (&priv->pci_dev->dev,"no usable interrupts\n" ); -return -ENODEV ; +return err; } done:
Signature · 1 line
2.5.1
PATCH 5/6 i2c: ismt: issue a warning when fail to request MSI
In reply to a message not in the archiveIssue the warning in all error paths when unable to register MSI or its handler.
--- drivers/i2c/busses/i2c-ismt.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/i2c/busses/i2c-ismt.c +5 -6
@@ -788,11 +788,8 @@ static int ismt_int_init(struct ismt_priv *priv)/* Try using MSI interrupts */ err =pci_enable_msi (priv->pci_dev); -if (err) { -dev_warn (&priv->pci_dev->dev, -"Unable to use MSI interrupts, falling back to legacy\n" ); +if (err) goto intx; - } err = devm_request_irq(&priv->pci_dev->dev, priv->pci_dev->irq,
@@ -805,10 +802,13 @@ static int ismt_int_init(struct ismt_priv *priv) goto intx; } - goto done; +return 0 ;/* Try using legacy interrupts */ intx: +dev_warn (&priv->pci_dev->dev, +"Unable to use MSI interrupts, falling back to legacy\n" ); + err = devm_request_irq(&priv->pci_dev->dev, priv->pci_dev->irq, ismt_do_interrupt,
@@ -820,7 +820,6 @@ intx:return err; } -done:return 0 ; }
Signature · 1 line
2.5.1
PATCH 6/6 i2c: ismt: mark register space with __iomem
In reply to a message not in the archiveThis fixes the code to suppress sparse warnings like:
drivers/i2c/busses/i2c-ismt.c:725:36: warning: incorrect type in argument 2 (different address spaces)drivers/i2c/busses/i2c-ismt.c:725:36: expected void volatile [noderef] <asn:2>*addrdrivers/i2c/busses/i2c-ismt.c:725:36: got void *
--- drivers/i2c/busses/i2c-ismt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-ismt.c +1 -1
@@ -165,7 +165,7 @@ struct ismt_desc {struct ismt_priv {struct i2c_adapter adapter; -void *smba;/* PCI BAR */ +void __iomem *smba;/* PCI BAR */ struct pci_dev *pci_dev;struct ismt_desc *hw;/* descriptor virt base addr */ dma_addr_t io_rng_dma;/* descriptor HW base addr */
Signature · 1 line
2.5.1
Quoted 3 lines · Andy Shevchenko
pcim_release()will release any requested region. There is no need to duplicate
this effort in the driver.
Any comments on that clean up series?
Quoted 72 lines
Signed-off-by Andy Shevchenko <[email protected]>--- drivers/i2c/busses/i2c-ismt.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-)drivers/i2c/busses/i2c renamed from drivers/i2c/busses/i2c-ismt.c +0
-1-ismt.cindex f994712..b7a68b5 100644
drivers/i2c/busses/i2c-ismt.c +1
-2@@ -904,8 +904,7 @@ ismt_probe(struct pci_dev *pdev, const struct pci_device_id *id) priv->smba = pcim_iomap(pdev, SMBBAR, len);if (!priv->smba) {dev_err (&pdev->dev,"Unable to ioremap SMBus BAR\n"); - err = -ENODEV ; - goto fail; +return -ENODEV ; }drivers/i2c/busses/i2c-ismt.c +4
-11if ((pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0) ||@@ -915,32 +914,26 @@ ismt_probe(struct pci_dev *pdev, const struct pci_device_id *id) DMA_BIT_MASK(32)) != 0)) { dev_err(&pdev->dev, "pci_set_dma_mask fail %p\n", pdev); - err = -ENODEV ; - goto fail; +return -ENODEV ; } } err =ismt_dev_init (priv);if (err) - goto fail; +return err;ismt_hw_init (priv); err =ismt_int_init (priv);if (err) - goto fail; +return err; err =i2c_add_adapter (&priv->adapter);if (err) {dev_err (&pdev->dev,"Failed to add SMBus iSMT adapter\n"); - err = -ENODEV ; - goto fail; +return -ENODEV ; }return 0 ; - -fail: -pci_release_region (pdev,SMBBAR ); -return err; }/** @@ -952,7 +945,6 @@ static void ismt_remove(struct pci_dev *pdev)struct ismt_priv *priv =pci_get_drvdata (pdev);i2c_del_adapter (&priv->adapter); -pci_release_region (pdev,SMBBAR ); }/**
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Mika Westerberg
Reviewed-byQuoted 6 lines · Andy Shevchenko
Quoted 3 lines · Andy Shevchenko
pcim_release()will release any requested region. There is no need to duplicate
this effort in the driver.Any comments on that clean up series?
FWIW the whole series looks good to me,
Re: [PATCH 2/6] i2c: ismt: PCI core handles power state for us
In reply to Andy ShevchenkoQuoted 10 lines · Andy Shevchenko
There is no need to repeat the work that is already done in the PCI driver core. Remove suspend and resume callbacks.
Note that there is no more calls performed to enable or disable a PCI device during suspend-resume cycle. Nowadays they seems to be superflous. Someone can read more in [1].
[1] https://www.kernel.org/doc/ols/2009/ols2009-pages-319-330.pdf
Signed-off-by Andy Shevchenko <[email protected]>
Checkpatch said:
WARNING: 'superflous' may be misspelled - perhaps 'superfluous'? #6:
superflous. Someone can read more in [1].
total: 0 errors, 1 warnings, 0 checks, 44 lines checked
Fixed it here.
Wolfram Sang
AppliedQuoted 11 lines · Mika Westerberg
Quoted 6 lines · Andy Shevchenko
Quoted 3 lines · Andy Shevchenko
pcim_release()will release any requested region. There is no need to duplicate
this effort in the driver.Any comments on that clean up series?
FWIW the whole series looks good to me,
Reviewed-by Mika Westerberg <[email protected]>
Applied all to for-next, thanks!