mei: simplify error handling via devres function.
Subsystems (2)
Use devm_ and pcim_ functions to make error handling simpler and code smaller and tidier.
Based on original patch by
mei: me: use managed functions pcim_* and devm_* Andy Shevchenko <[email protected]>
https://lkml.org/lkml/2016/2/1/339
--- drivers/misc/mei/hw-me.c | 13 +++--- drivers/misc/mei/hw-me.h | 4 +- drivers/misc/mei/hw-txe.c | 8 ++-- drivers/misc/mei/hw-txe.h | 2 +- drivers/misc/mei/pci-me.c | 74 +++++++++--------------------- drivers/misc/mei/pci-txe.c | 112 ++++++++++++++------------------------------- 6 files changed, 69 insertions(+), 144 deletions(-)
drivers/misc/mei/hw-me.c +6 -7
@@ -1384,21 +1384,21 @@ const struct mei_cfg mei_me_pch8_sps_cfg = { };/** -* mei_me_dev_init - allocates and initializes the mei device structure +* devm_mei_me_init - allocates and initializes the mei device structure * * @pdev: The pci device structure * @cfg: per device generation config * -* Return: The mei_device_device pointer on success, NULL on failure. +* Return: The mei_device pointer on success, NULL on failure. */ -struct mei_device *mei_me_dev_init (struct pci_dev *pdev, -const struct mei_cfg *cfg) +struct mei_device *devm_mei_me_init (struct pci_dev *pdev, +const struct mei_cfg *cfg) {struct mei_device *dev;struct mei_me_hw *hw; - dev =kzalloc (sizeof (struct mei_device ) + -sizeof (struct mei_me_hw ),GFP_KERNEL ); + dev =devm_kzalloc (&pdev->dev,sizeof (struct mei_device ) + +sizeof (struct mei_me_hw ),GFP_KERNEL );if (!dev)return NULL ; hw =to_me_hw (dev);
@@ -1407,4 +1407,3 @@ struct mei_device *mei_me_dev_init(struct pci_dev *pdev, hw->cfg = cfg;return dev; } -
drivers/misc/mei/hw-me.h +2 -2
@@ -70,8 +70,8 @@ extern const struct mei_cfg mei_me_pch_cpt_pbg_cfg;extern const struct mei_cfg mei_me_pch8_cfg;extern const struct mei_cfg mei_me_pch8_sps_cfg; -struct mei_device *mei_me_dev_init (struct pci_dev *pdev, -const struct mei_cfg *cfg); +struct mei_device *devm_mei_me_init (struct pci_dev *pdev, +const struct mei_cfg *cfg);int mei_me_pg_enter_sync (struct mei_device *dev);int mei_me_pg_exit_sync (struct mei_device *dev);
drivers/misc/mei/hw-txe.c +4 -4
@@ -1196,19 +1196,19 @@ static const struct mei_hw_ops mei_txe_hw_ops = { };/** -* mei_txe_dev_init - allocates and initializes txe hardware specific structure +* devm_mei_txe_init - allocates and initializes txe hardware specific structure * * @pdev: pci device * * Return: struct mei_device * on success or NULL */ -struct mei_device *mei_txe_dev_init (struct pci_dev *pdev) +struct mei_device *devm_mei_txe_init (struct pci_dev *pdev) {struct mei_device *dev;struct mei_txe_hw *hw; - dev =kzalloc (sizeof (struct mei_device ) + -sizeof (struct mei_txe_hw ),GFP_KERNEL ); + dev =devm_kzalloc (&pdev->dev,sizeof (struct mei_device ) + +sizeof (struct mei_txe_hw ),GFP_KERNEL );if (!dev)return NULL ;
drivers/misc/mei/hw-txe.h +1 -1
@@ -62,7 +62,7 @@ static inline struct mei_device *hw_txe_to_mei(struct mei_txe_hw *hw) return container_of((void *)hw, struct mei_device, hw); } -struct mei_device *mei_txe_dev_init (struct pci_dev *pdev); +struct mei_device *devm_mei_txe_init (struct pci_dev *pdev);irqreturn_t mei_txe_irq_quick_handler (int irq,void *dev_id);irqreturn_t mei_txe_irq_thread_handler (int irq,void *dev_id);
drivers/misc/mei/pci-me.c +22 -52
151 lines not on this page · raw message
drivers/misc/mei/pci-txe.c +34 -78
204 lines not on this page · raw message
Signature · 1 line
2.7.4
Quoted 8 lines · Tomas Winkler
Use
devm_andpcim_functions to make error handling simpler and code smaller and tidier.Based on original patch by
mei: me: use managed functions pcim_* and devm_* Andy Shevchenko <[email protected]>
https://lkml.org/lkml/2016/2/1/339
I have some comments on it, but need to go right now. So, I will look to this during weekend.
Quoted 537 lines
Cc Andy Shevchenko <[email protected]>Signed-off-by Tomas Winkler <[email protected]>Signed-off-by Alexander Usyskin <[email protected]>---
drivers/misc/mei/hw-me.c | 13 +++---
drivers/misc/mei/hw-me.h | 4 +-drivers/misc/mei/hw-txe.c | 8 ++-- drivers/misc/mei/hw-txe.h | 2 +- drivers/misc/mei/pci-me.c | 74 +++++++++--------------------- drivers/misc/mei/pci-txe.c | 112 ++++++++++++++-------------------- ----------- 6 files changed, 69 insertions(+), 144 deletions(-)drivers/misc/mei/hw-me.c +0
-0@@ -1384,21 +1384,21 @@ const struct mei_cfg mei_me_pch8_sps_cfg = { };
/**
- *mei_me_dev_init- allocates and initializes the mei device structure
+ *devm_mei_me_init- allocates and initializes the mei device structure
*
* @pdev: The pci device structure
* @cfg: per device generation config
*
- * Return: Themei_device_devicepointer on success, NULL on failure.
+ * Return: Themei_devicepointer on success, NULL on failure. */drivers/misc/mei/hw-me.c +2
-2-struct mei_device *mei_me_dev_init (struct pci_dev *pdev, - const struct mei_cfg *cfg) +struct mei_device *devm_mei_me_init (struct pci_dev *pdev, + const struct mei_cfg *cfg){
structmei_device*dev;
structmei_me_hw*hw;drivers/misc/mei/hw-me.c +2
-2- dev =kzalloc (sizeof (struct mei_device ) + - sizeof(struct mei_me_hw), GFP_KERNEL); + dev =devm_kzalloc (&pdev->dev,sizeof (struct mei_device ) + + sizeof(struct mei_me_hw), GFP_KERNEL);if (!dev)
return NULL;
hw =to_me_hw(dev);drivers/misc/mei/hw-me.c +0
-0@@ -1407,4 +1407,3 @@ struct mei_device *mei_me_dev_init(structpci_dev *pdev, hw->cfg = cfg; return dev;}
drivers/misc/mei/hw-me.c +0
-1-drivers/misc/mei/hw-me.h +0
-0@@ -70,8 +70,8 @@ extern const struct mei_cfg mei_me_pch_cpt_pbg_cfg; extern const struct mei_cfg mei_me_pch8_cfg; extern const struct mei_cfg mei_me_pch8_sps_cfg;drivers/misc/mei/hw-me.h +2
-2-struct mei_device *mei_me_dev_init (struct pci_dev *pdev, - const struct mei_cfg *cfg); +struct mei_device *devm_mei_me_init (struct pci_dev *pdev, + const struct mei_cfg *cfg);
intmei_me_pg_enter_sync(struct mei_device *dev); intmei_me_pg_exit_sync(struct mei_device *dev);drivers/misc/mei/hw-txe.c +0
-0@@ -1196,19 +1196,19 @@ static const struct mei_hw_ops mei_txe_hw_ops = { };
/**
- *mei_txe_dev_init- allocates and initializes txe hardware specific structure
+ *devm_mei_txe_init- allocates and initializes txe hardware specific structure
*
* @pdev: pci device
*
* Return: structmei_device* on success or NULL
*/drivers/misc/mei/hw-txe.c +1
-1-struct mei_device *mei_txe_dev_init (struct pci_dev *pdev) +struct mei_device *devm_mei_txe_init (struct pci_dev *pdev){
structmei_device*dev;
structmei_txe_hw*hw;drivers/misc/mei/hw-txe.c +2
-2- dev =kzalloc (sizeof (struct mei_device ) + - sizeof(struct mei_txe_hw), GFP_KERNEL); + dev =devm_kzalloc (&pdev->dev,sizeof (struct mei_device ) + + sizeof(struct mei_txe_hw), GFP_KERNEL);if (!dev)
return NULL;drivers/misc/mei/hw-txe.h +0
-0@@ -62,7 +62,7 @@ static inline struct mei_device *hw_txe_to_mei(struct mei_txe_hw *hw) return container_of((void *)hw, struct mei_device, hw); }drivers/misc/mei/hw-txe.h +1
-1-struct mei_device *mei_txe_dev_init (struct pci_dev *pdev); +struct mei_device *devm_mei_txe_init (struct pci_dev *pdev);
irqreturn_tmei_txe_irq_quick_handler(int irq, void *dev_id);irqreturn_tmei_txe_irq_thread_handler(int irq, void *dev_id);drivers/misc/mei/pci-me.c +0
-0@@ -149,18 +149,18 @@ static int mei_me_probe(struct pci_dev *pdev, const struct pci_device_id *ent) return -ENODEV;
/* enable pci dev */drivers/misc/mei/pci-me.c +1
-1- err =pci_enable_device (pdev); + err =pcim_enable_device (pdev);if (err) {
dev_err(&pdev->dev, "failed to enable pci device.\n");
goto end;
}
/* set PCI host mastering */pci_set_master(pdev);drivers/misc/mei/pci-me.c +1
-2-/* pci request regions for mei driver */ - err =pci_request_regions (pdev,KBUILD_MODNAME ); +/* pci request regions and mapping IO device memory for mei driver */
drivers/misc/mei/pci-me.c +1
-0+ err =pcim_iomap_regions (pdev,BIT (0 ),KBUILD_MODNAME );if (err) {
dev_err(&pdev->dev, "failed to get pci regions.\n");drivers/misc/mei/pci-me.c +1
-1- goto disable_device; + goto end;}
if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(64))||drivers/misc/mei/pci-me.c +1
-1@@ -173,37 +173,31 @@ static int mei_me_probe(struct pci_dev *pdev, const struct pci_device_id *ent) } if (err) { dev_err(&pdev->dev, "No usable DMA configuration, aborting\n"); - goto release_regions; + goto end; }
-
/* allocates and initializes the mei dev structure */drivers/misc/mei/pci-me.c +1
-1- dev =mei_me_dev_init (pdev, cfg); + dev =devm_mei_me_init (pdev, cfg);if (!dev) {
err =-ENOMEM;drivers/misc/mei/pci-me.c +1
-1- goto release_regions; + goto end;}
hw =to_me_hw(dev);drivers/misc/mei/pci-me.c +0
-4-/* mapping IO device memory */ - hw->mem_addr =pci_iomap (pdev,0 ,0 ); -if (!hw->mem_addr) { - dev_err(&pdev->dev, "mapping I/O device memoryfailure.\n");
drivers/misc/mei/pci-me.c +2
-3- err = -ENOMEM ; - goto free_device; - } + hw->mem_addr =pcim_iomap_table (pdev)[0 ]; +
pci_enable_msi(pdev);
/* request and enable interrupt */ irqflags =pci_dev_msi_enabled(pdev)?IRQF_ONESHOT:IRQF_SHARED;drivers/misc/mei/pci-me.c +4
-4- err =request_threaded_irq (pdev->irq, - mei_me_irq_quick_handler, - mei_me_irq_thread_handler, - irqflags,KBUILD_MODNAME , dev); + err = devm_request_threaded_irq(&pdev->dev, pdev->irq, + mei_me_irq_quick_handler, + mei_me_irq_thread_handler, + irqflags, KBUILD_MODNAME,dev);
if (err) {
dev_err(&pdev->dev, "request_threaded_irqfailure. irq = %d\n",
pdev->irq);drivers/misc/mei/pci-me.c +1
-1- goto disable_msi; + goto end;}
if (mei_start(dev)) {drivers/misc/mei/pci-me.c +0
-0@@ -241,17 +235,8 @@ static int mei_me_probe(struct pci_dev *pdev, const struct pci_device_id *ent)release_irq:
mei_cancel_work(dev);
mei_disable_interrupts(dev);drivers/misc/mei/pci-me.c +0
-10-free_irq (pdev->irq, dev); -disable_msi: -pci_disable_msi (pdev); -pci_iounmap (pdev, hw->mem_addr); -free_device: -kfree (dev); -release_regions: -pci_release_regions (pdev); -disable_device: -pci_disable_device (pdev);end:
drivers/misc/mei/pci-me.c +1
-0+pci_set_drvdata (pdev,NULL );
dev_err(&pdev->dev, "initialization failed.\n"); return err;
}drivers/misc/mei/pci-me.c +0
-1@@ -267,7 +252,6 @@ static int mei_me_probe(struct pci_dev *pdev, const struct pci_device_id *ent) static void mei_me_remove(struct pci_dev *pdev) { struct mei_device *dev; -struct mei_me_hw *hw;
dev =pci_get_drvdata(pdev);
if (!dev)drivers/misc/mei/pci-me.c +0
-0@@ -276,33 +260,19 @@ static void mei_me_remove(struct pci_dev *pdev) if (mei_pg_is_enabled(dev)) pm_runtime_get_noresume(&pdev->dev);drivers/misc/mei/pci-me.c +0
-3- hw =to_me_hw (dev); - -
dev_dbg(&pdev->dev, "stop\n");mei_stop(dev);
if (!pci_dev_run_wake(pdev))mei_me_unset_pm_domain(dev);drivers/misc/mei/pci-me.c +0
-1-/* disable interrupts */
mei_disable_interrupts(dev);drivers/misc/mei/pci-me.c +0
-6-free_irq (pdev->irq, dev); -pci_disable_msi (pdev); - -if (hw->mem_addr) -pci_iounmap (pdev, hw->mem_addr); -
mei_deregister(dev);drivers/misc/mei/pci-me.c +1
-6-kfree (dev); - -pci_release_regions (pdev); -pci_disable_device (pdev); - - +pci_set_drvdata (pdev,NULL );}
+
#ifdefCONFIG_PM_SLEEP
static intmei_me_pci_suspend(struct device *device){drivers/misc/mei/pci-me.c +0
-0@@ -318,7 +288,7 @@ static int mei_me_pci_suspend(struct device *device)
mei_disable_interrupts(dev);drivers/misc/mei/pci-me.c +1
-1-free_irq (pdev->irq, dev); +devm_free_irq (&pdev->dev, pdev->irq, dev);
pci_disable_msi(pdev);
return 0;drivers/misc/mei/pci-me.c +0
-0@@ -340,10 +310,10 @@ static int mei_me_pci_resume(struct device *device)irqflags =
pci_dev_msi_enabled(pdev)?IRQF_ONESHOT:IRQF_SHARED;
/* request and enable interrupt */drivers/misc/mei/pci-me.c +4
-4- err =request_threaded_irq (pdev->irq, - mei_me_irq_quick_handler, - mei_me_irq_thread_handler, - irqflags,KBUILD_MODNAME , dev); + err = devm_request_threaded_irq(&pdev->dev, pdev->irq, + mei_me_irq_quick_handler, + mei_me_irq_thread_handler, + irqflags, KBUILD_MODNAME,dev);
if (err) {
dev_err(&pdev->dev, "request_threaded_irqfailed: irq = %d.\n",drivers/misc/mei/pci-txe.c +0
-0@@ -52,17 +52,6 @@ static inline void mei_txe_set_pm_domain(struct mei_device *dev) {} static inline void mei_txe_unset_pm_domain(struct mei_device *dev) {} #endif /* CONFIG_PM */
-static voidmei_txe_pci_iounmap(struct pci_dev *pdev, struct mei_txe_hw *hw)drivers/misc/mei/pci-txe.c +0
-10-{ -int i; - -for (i =SEC_BAR ; i <NUM_OF_MEM_BARS ; i++) { -if (hw->mem_addr[i]) { -pci_iounmap (pdev, hw->mem_addr[i]); - hw->mem_addr[i] =NULL ; - } - } -}/**
*mei_txe_probe- Device Initialization Routine *drivers/misc/mei/pci-txe.c +1
-1@@ -75,22 +64,22 @@ static int mei_txe_probe(struct pci_dev *pdev, const struct pci_device_id *ent) { struct mei_device *dev; struct mei_txe_hw *hw; +const int mask =BIT (SEC_BAR ) |BIT (BRIDGE_BAR ); int err; -int i;
/* enable pci dev */drivers/misc/mei/pci-txe.c +1
-1- err =pci_enable_device (pdev); + err =pcim_enable_device (pdev);if (err) {
dev_err(&pdev->dev, "failed to enable pci device.\n");
goto end;
}
/* set PCI host mastering */pci_set_master(pdev);drivers/misc/mei/pci-txe.c +1
-2-/* pci request regions for mei driver */ - err =pci_request_regions (pdev,KBUILD_MODNAME ); +/* pci request regions and mapping IO device memory for mei driver */
drivers/misc/mei/pci-txe.c +1
-0+ err =pcim_iomap_regions (pdev, mask,KBUILD_MODNAME );if (err) {
dev_err(&pdev->dev, "failed to get pci regions.\n");drivers/misc/mei/pci-txe.c +1
-1- goto disable_device; + goto end;}
err =pci_set_dma_mask(pdev, DMA_BIT_MASK(36));drivers/misc/mei/pci-txe.c +0
-0@@ -98,28 +87,18 @@ static int mei_txe_probe(struct pci_dev *pdev, const struct pci_device_id *ent) err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); if (err) {
dev_err(&pdev->dev, "No suitable DMA available.\n");drivers/misc/mei/pci-txe.c +1
-1- goto release_regions; + goto end;}
}
/* allocates and initializes the mei dev structure */drivers/misc/mei/pci-txe.c +1
-1- dev =mei_txe_dev_init (pdev); + dev =devm_mei_txe_init (pdev);if (!dev) {
err =-ENOMEM;drivers/misc/mei/pci-txe.c +1
-1- goto release_regions; + goto end;}
hw =to_txe_hw(dev);drivers/misc/mei/pci-txe.c +0
-6- -/* mapping IO device memory */ -for (i =SEC_BAR ; i <NUM_OF_MEM_BARS ; i++) { - hw->mem_addr[i] =pci_iomap (pdev, i,0 ); -if (!hw->mem_addr[i]) { - dev_err(&pdev->dev, "mapping I/O devicememory failure.\n");
drivers/misc/mei/pci-txe.c +1
-5- err = -ENOMEM ; - goto free_device; - } - } - + memcpy(hw->mem_addr, pcim_iomap_table(pdev), sizeof(hw-Quoted 1 line
mem_addr));
pci_enable_msi(pdev);drivers/misc/mei/pci-txe.c +0
-0@@ -128,19 +107,21 @@ static int mei_txe_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
/* request and enable interrupt */
if (pci_dev_msi_enabled(pdev))drivers/misc/mei/pci-txe.c +1
-4- err =request_threaded_irq (pdev->irq, -NULL , - mei_txe_irq_thread_handler, -IRQF_ONESHOT ,KBUILD_MODNAME , dev); + err = devm_request_threaded_irq(&pdev->dev, pdev-Quoted 1 line
irq,
drivers/misc/mei/pci-txe.c +2
-0+NULL , + mei_txe_irq_thread_handler,
drivers/misc/mei/pci-txe.c +1
-0+ IRQF_ONESHOT,
KBUILD_MODNAME,drivers/misc/mei/pci-txe.c +1
-0+ dev);else
drivers/misc/mei/pci-txe.c +1
-4- err =request_threaded_irq (pdev->irq, - mei_txe_irq_quick_handler, - mei_txe_irq_thread_handler, -IRQF_SHARED ,KBUILD_MODNAME , dev); + err = devm_request_threaded_irq(&pdev->dev, pdev-Quoted 1 line
irq,
drivers/misc/mei/pci-txe.c +1
-0+ mei_txe_irq_quick_handler,
drivers/misc/mei/pci-txe.c +1
-0+ mei_txe_irq_thread_handler,
drivers/misc/mei/pci-txe.c +1
-0+ IRQF_SHARED,
KBUILD_MODNAME,drivers/misc/mei/pci-txe.c +1
-0+ dev);if (err) {
dev_err(&pdev->dev, "mei:request_threaded_irqfailure. irq = %d\n",
pdev->irq);drivers/misc/mei/pci-txe.c +1
-1- goto free_device; + goto end;}
if (mei_start(dev)) {drivers/misc/mei/pci-txe.c +0
-0@@ -173,24 +154,10 @@ static int mei_txe_probe(struct pci_dev *pdev, const struct pci_device_id *ent)stop:
mei_stop(dev);
release_irq:
-
mei_cancel_work(dev);drivers/misc/mei/pci-txe.c +0
-2- -/* disable interrupts */
mei_disable_interrupts(dev);drivers/misc/mei/pci-txe.c +0
-12- -free_irq (pdev->irq, dev); -pci_disable_msi (pdev); - -free_device: -mei_txe_pci_iounmap (pdev, hw); - -kfree (dev); -release_regions: -pci_release_regions (pdev); -disable_device: -pci_disable_device (pdev);end:
drivers/misc/mei/pci-txe.c +1
-0+pci_set_drvdata (pdev,NULL );
dev_err(&pdev->dev, "initialization failed.\n"); return err;
}drivers/misc/mei/pci-txe.c +0
-1@@ -206,38 +173,25 @@ static int mei_txe_probe(struct pci_dev *pdev, const struct pci_device_id *ent) static void mei_txe_remove(struct pci_dev *pdev) { struct mei_device *dev; -struct mei_txe_hw *hw;
dev =pci_get_drvdata(pdev);
if (!dev) {drivers/misc/mei/pci-txe.c +1
-1-dev_err (&pdev->dev,"mei: dev =NULL\n" ); +dev_err (&pdev->dev,"mei: dev == NULL\n" );return;
}
pm_runtime_get_noresume(&pdev->dev);drivers/misc/mei/pci-txe.c +0
-2- hw =to_txe_hw (dev); -
mei_stop(dev);
if (!pci_dev_run_wake(pdev))mei_txe_unset_pm_domain(dev);drivers/misc/mei/pci-txe.c +0
-1-/* disable interrupts */
mei_disable_interrupts(dev);drivers/misc/mei/pci-txe.c +0
-6-free_irq (pdev->irq, dev); -pci_disable_msi (pdev); - -pci_set_drvdata (pdev,NULL ); - -mei_txe_pci_iounmap (pdev, hw);
mei_deregister(dev);drivers/misc/mei/pci-txe.c +1
-4-kfree (dev); - -pci_release_regions (pdev); -pci_disable_device (pdev); +pci_set_drvdata (pdev,NULL );}
drivers/misc/mei/pci-txe.c +0
-0@@ -256,7 +210,7 @@ static int mei_txe_pci_suspend(struct device *device)
mei_disable_interrupts(dev);drivers/misc/mei/pci-txe.c +1
-1-free_irq (pdev->irq, dev); +devm_free_irq (&pdev->dev, pdev->irq, dev);
pci_disable_msi(pdev);
return 0;drivers/misc/mei/pci-txe.c +0
-0@@ -278,15 +232,17 @@ static int mei_txe_pci_resume(struct device *device)
/* request and enable interrupt */
if (pci_dev_msi_enabled(pdev))drivers/misc/mei/pci-txe.c +1
-4- err =request_threaded_irq (pdev->irq, -NULL , - mei_txe_irq_thread_handler, -IRQF_ONESHOT ,KBUILD_MODNAME , dev); + err = devm_request_threaded_irq(&pdev->dev, pdev-Quoted 1 line
irq,
drivers/misc/mei/pci-txe.c +2
-0+NULL , + mei_txe_irq_thread_handler,
drivers/misc/mei/pci-txe.c +1
-0+ IRQF_ONESHOT,
KBUILD_MODNAME,drivers/misc/mei/pci-txe.c +1
-0+ dev);else
drivers/misc/mei/pci-txe.c +1
-4- err =request_threaded_irq (pdev->irq, - mei_txe_irq_quick_handler, - mei_txe_irq_thread_handler, -IRQF_SHARED ,KBUILD_MODNAME , dev); + err = devm_request_threaded_irq(&pdev->dev, pdev-Quoted 1 line
irq,
drivers/misc/mei/pci-txe.c +1
-0+ mei_txe_irq_quick_handler,
drivers/misc/mei/pci-txe.c +1
-0+ mei_txe_irq_thread_handler,
drivers/misc/mei/pci-txe.c +1
-0+ IRQF_SHARED,
KBUILD_MODNAME,drivers/misc/mei/pci-txe.c +1
-0+ dev);if (err) {
dev_err(&pdev->dev, "request_threaded_irqfailed: irq = %d.\n",
pdev->irq);
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Quoted 7 lines · Tomas Winkler
Use
devm_andpcim_functions to make error handling simpler and code smaller and tidier.Based on original patch by
mei: me: use managed functions pcim_* and devm_* Andy Shevchenko <[email protected]>
https://lkml.org/lkml/2016/2/1/339
Perhaps you may leave SoB.
But let me review the code.
Quoted 6 lines
Cc Andy Shevchenko <[email protected]>Signed-off-by Tomas Winkler <[email protected]>Signed-off-by Alexander Usyskin <[email protected]>- * Return: The
mei_device_devicepointer on success, NULL on failure.
+ * Return: Themei_devicepointer on success, NULL on failure.
This is not related.
drivers/misc/mei/hw-me.c const struct mei_cfg mei_me_pch8_sps_cfg = { · line 1395
Quoted 4 lines
drivers/misc/mei/hw-me.c +2
-2-struct mei_device *mei_me_dev_init (struct pci_dev *pdev, -const struct mei_cfg *cfg) +struct mei_device *devm_mei_me_init (struct pci_dev *pdev, +const struct mei_cfg *cfg)
It's not exactly in devm_ namespace. (They have no corresponding devm_*_fini, etc.)
Better to leave same name in spite of calling devm_* inside.
drivers/misc/mei/hw-txe.c static const struct mei_hw_ops mei_txe_hw_ops = { · line 1205
Quoted 2 lines
drivers/misc/mei/hw-txe.c +1
-1-struct mei_device *mei_txe_dev_init (struct pci_dev *pdev) +struct mei_device *devm_mei_txe_init (struct pci_dev *pdev)
Ditto.
Quoted 3 lines
end:
+
pci_set_drvdata(pdev, NULL);
Not needed.
drivers/misc/mei/pci-me.c static void mei_me_remove(struct pci_dev *pdev) · line 263
Quoted 12 lines
static void
mei_me_remove(struct pci_dev *pdev){ struct mei_device *dev;drivers/misc/mei/pci-me.c +1
-1-struct mei_me_hw *hw; dev =pci_get_drvdata (pdev);if (!dev)@@ -276,33 +260,19 @@ static void mei_me_remove(struct pci_dev *pdev)if (mei_pg_is_enabled (dev))pm_runtime_get_noresume (&pdev->dev); +pci_set_drvdata (pdev,NULL );
Ditto.
drivers/misc/mei/pci-me.c static int mei_me_pci_suspend(struct device *device) · line 292
Quoted 3 lines
drivers/misc/mei/pci-me.c +1
-1-free_irq (pdev->irq, dev); +devm_free_irq (&pdev->dev, pdev->irq, dev);pci_disable_msi (pdev);
All three not needed
drivers/misc/mei/pci-txe.c static int mei_txe_probe(struct pci_dev *pdev, const struct pci_device_id *ent) · line 68
Quoted 8 lines
drivers/misc/mei/pci-txe.c +1
-0return 0 ;@@ -75,22 +64,22 @@ static int mei_txe_probe(struct pci_dev *pdev, const struct pci_device_id *ent) {struct mei_device *dev;struct mei_txe_hw *hw; +const int mask =BIT (SEC_BAR ) |BIT (BRIDGE_BAR );
First line?
drivers/misc/mei/pci-txe.c static int mei_txe_probe(struct pci_dev *pdev, const struct pci_device_id *ent) · line 101
Quoted 1 line
drivers/misc/mei/pci-txe.c +1
-0+memcpy (hw->mem_addr,pcim_iomap_table (pdev),sizeof (hw->mem_addr));
Why?
It is kept by PCI core, you don't need a copy.
drivers/misc/mei/pci-me.c static int mei_me_probe(struct pci_dev *pdev, const struct pci_device_id *ent) · line 239
Quoted 3 lines
drivers/misc/mei/pci-me.c +1
-0end: +pci_set_drvdata (pdev,NULL );
Redundant.
drivers/misc/mei/pci-txe.c static int mei_txe_probe(struct pci_dev *pdev, const struct pci_device_id *ent) · line 194
Quoted 4 lines
drivers/misc/mei/pci-txe.c +1
-0static void mei_txe_remove (struct pci_dev *pdev) { +pci_set_drvdata (pdev,NULL );
Ditto.
drivers/misc/mei/pci-me.c static int mei_txe_pci_suspend(struct device *device) · line 212
Quoted 5 lines
drivers/misc/mei/pci-me.c +1
-1@@ -256,7 +210,7 @@ static int mei_txe_pci_suspend(struct device *device) -free_irq (pdev->irq, dev); +devm_free_irq (&pdev->dev, pdev->irq, dev);pci_disable_msi (pdev);
All are redundant.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 7 lines
Quoted 3 lines · Tomas Winkler
Use
devm_andpcim_functions to make error handling simpler and code smaller and tidier.
Quoted 7 lines
Quoted 4 lines
Based on original patch by
mei: me: use managed functions pcim_* and devm_* Andy Shevchenko <[email protected]>
https://lkml.org/lkml/2016/2/1/339Perhaps you may leave SoB.
But let me review the code.
No problem, though we also had some internal code before, you were just first to send it out ;)
Quoted 10 lines
Quoted 7 lines
Cc Andy Shevchenko <[email protected]>Signed-off-by Tomas Winkler <[email protected]>Signed-off-by Alexander Usyskin <[email protected]>- * Return: The
mei_device_devicepointer on success, NULL on failure.
+ * Return: Themei_devicepointer on success, NULL on failure.This is not related.
Quoted 7 lines
drivers/misc/mei/hw-me.c const struct mei_cfg mei_me_pch8_sps_cfg = { · line 1395
Quoted 4 lines
drivers/misc/mei/hw-me.c +2
-2-struct mei_device *mei_me_dev_init (struct pci_dev *pdev, -const struct mei_cfg *cfg) +struct mei_device *devm_mei_me_init (struct pci_dev *pdev, +const struct mei_cfg *cfg)It's not exactly in
devm_namespace. (They have no corresponding devm_*_fini, etc.) Better to leave same name in spite of calling devm_* inside.
Okay, got it.
Quoted 11 lines
drivers/misc/mei/hw-txe.c static const struct mei_hw_ops mei_txe_hw_ops = { · line 1205
Quoted 3 lines
drivers/misc/mei/hw-txe.c +1
-1-struct mei_device *mei_txe_dev_init (struct pci_dev *pdev) +struct mei_device *devm_mei_txe_init (struct pci_dev *pdev)Ditto.
Quoted 3 lines
end:
+
pci_set_drvdata(pdev, NULL);Not needed.
Please explain, we rely on pci_get_drvdata() returning NULL when unregistered.
Quoted 13 lines
drivers/misc/mei/pci-me.c static void mei_me_remove(struct pci_dev *pdev) · line 263
Quoted 12 lines
static void mei_me_remove(struct pci_dev *pdev) { struct mei_device *dev;drivers/misc/mei/pci-me.c +1
-1-struct mei_me_hw *hw; dev =pci_get_drvdata (pdev);if (!dev)@@ -276,33 +260,19 @@ static void mei_me_remove(struct pci_dev *pdev)if (mei_pg_is_enabled (dev))pm_runtime_get_noresume (&pdev->dev); +pci_set_drvdata (pdev,NULL );
Quoted 7 lines
Ditto.
drivers/misc/mei/pci-me.c static int mei_me_pci_suspend(struct device *device) · line 292
Quoted 3 lines
drivers/misc/mei/pci-me.c +1
-1-free_irq (pdev->irq, dev); +devm_free_irq (&pdev->dev, pdev->irq, dev);pci_disable_msi (pdev);All three not needed
I believe we need it on suspend as we are going over irq request again in resume. Please provide more info you if you still insist.
Quoted 11 lines
drivers/misc/mei/pci-txe.c static int mei_txe_probe(struct pci_dev *pdev, · line 68
Quoted 9 lines
drivers/misc/mei/pci-txe.c +1
-0return 0 ;@@ -75,22 +64,22 @@ static int mei_txe_probe(struct pci_dev *pdev, const struct pci_device_id *ent) {struct mei_device *dev;struct mei_txe_hw *hw; +const int mask =BIT (SEC_BAR ) |BIT (BRIDGE_BAR );First line?
Please be more verbose.
Quoted 6 lines
Review static int mei_txe_probe(struct pci_dev *pdev, · line 70
Quoted 3 lines
(quoted diff) +2
-0+ memcpy(hw->mem_addr, pcim_iomap_table(pdev), + sizeof(hw->mem_addr));Why?
It is kept by PCI core, you don't need a copy.
There is no simple accessor for that, it's easier to copy the two dwords then going over the function calls.
Quoted 12 lines
drivers/misc/mei/pci-me.c static int mei_me_probe(struct pci_dev *pdev, const struct pci_device_id *ent) · line 239
Quoted 3 lines
drivers/misc/mei/pci-me.c +1
-0end: +pci_set_drvdata (pdev,NULL );Redundant.
drivers/misc/mei/pci-me.c static void mei_me_remove(struct pci_dev *pdev) · line 273
Quoted 3 lines
drivers/misc/mei/pci-me.c +1
-0static void mei_txe_remove (struct pci_dev *pdev) { +pci_set_drvdata (pdev,NULL );Ditto.
Quoted 8 lines
drivers/misc/mei/pci-me.c static int mei_txe_pci_suspend(struct device · line 213
Quoted 6 lines
drivers/misc/mei/pci-me.c +1
-1@@ -256,7 +210,7 @@ static int mei_txe_pci_suspend(struct device *device) -free_irq (pdev->irq, dev); +devm_free_irq (&pdev->dev, pdev->irq, dev);pci_disable_msi (pdev);All are redundant.
Thanks
Tomas
Quoted 6 lines · Tomas
Quoted 6 lines
drivers/misc/mei/hw-txe.c static const struct mei_hw_ops mei_txe_hw_ops = { · line 1205
Quoted 3 lines
drivers/misc/mei/hw-txe.c +1
-1-struct mei_device *mei_txe_dev_init (struct pci_dev *pdev) +struct mei_device *devm_mei_txe_init (struct pci_dev *pdev)Ditto.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
end:
+ pci_set_drvdata(pdev, NULL);Not needed.
Please explain, we rely on
pci_get_drvdata()returning NULL when unregistered.
PCI core will take care about this one. Actually device core for any of user of struct device.
See __device_release_driver() for the details.
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
- free_irq(pdev->irq, dev);
+ devm_free_irq(&pdev->dev,pdev->irq, dev);pci_disable_msi(pdev);All three not needed
I believe we need it on suspend as we are going over irq request again in resume. Please provide more info you if you still insist.
Ah, sorry, I missed that these are suspend/resume hooks.
So, Can you elaborate a bit why you need to disable interrupts during system suspend?
(Basically in this case better not to use devm_request_*irq() at all)
Quoted 11 lines
Quoted 9 lines
drivers/misc/mei/pci-txe.c static int mei_txe_probe(struct pci_dev *pdev, · line 67
Quoted 7 lines
return 0;
drivers/misc/mei/pci-txe.c +1
-0@@ -75,22 +64,22 @@ static int mei_txe_probe(struct pci_dev *pdev, const struct pci_device_id *ent) { struct mei_device *dev; struct mei_txe_hw *hw; + const int mask = BIT(SEC_BAR) | BIT(BRIDGE_BAR);First line?
Please be more verbose.
Use reversed tree for definition block.
The longest lines with the assignment = first;
Then lines without assignment;
Then return code variable;
Flags for spin_lock -- depends.
Quoted 9 lines
Quoted 6 lines
Review static int mei_txe_probe(struct pci_dev *pdev, · line 69
Quoted 3 lines
(quoted diff) +2
-0+ memcpy(hw->mem_addr, pcim_iomap_table(pdev), + sizeof(hw->mem_addr));Why?
It is kept by PCI core, you don't need a copy.There is no simple accessor for that, it's easier to copy the two dwords then going over the function calls.
I'm not sure you need a copy. That function call just return the pointer to the table.
I remember 8250_pci used to have similar approach, now it's using whatever is kept by PCI core.
It's less error prone.
Quoted 7 lines
Quoted 7 lines
drivers/misc/mei/pci-me.c static int mei_txe_pci_suspend(struct device · line 212
Quoted 5 lines
drivers/misc/mei/pci-me.c +1
-1@@ -256,7 +210,7 @@ static int mei_txe_pci_suspend(struct device *device) - free_irq(pdev->irq, dev); + devm_free_irq(&pdev->dev, pdev->irq, dev); pci_disable_msi(pdev);All are redundant.
Yeah, same clarification as for above case with system sleep.
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Quoted 12 lines · Tomas
Quoted 10 lines
Quoted 10 lines
drivers/misc/mei/hw-txe.c static const struct mei_hw_ops mei_txe_hw_ops = { · line 1205
Quoted 4 lines
drivers/misc/mei/hw-txe.c +1
-1-struct mei_device *mei_txe_dev_init (struct pci_dev *pdev) +struct mei_device *devm_mei_txe_init (struct pci_dev *pdev)Ditto.
Quoted 2 lines
end:
+ pci_set_drvdata(pdev, NULL);
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Not needed.
Please explain, we rely on
pci_get_drvdata()returning NULL when unregistered.PCI core will take care about this one. Actually device core for any of user of struct device.
See__device_release_driver()for the details.
Okay, got it.
Quoted 11 lines
Quoted 10 lines
Quoted 7 lines
Quoted 5 lines
- free_irq(pdev->irq, dev);
+ devm_free_irq(&pdev->dev,pdev->irq, dev);pci_disable_msi(pdev);All three not needed
I believe we need it on suspend as we are going over irq request again in resume. Please provide more info you if you still insist.
Quoted 6 lines
Ah, sorry, I missed that these are suspend/resume hooks.
So, Can you elaborate a bit why you need to disable interrupts during system suspend?
(Basically in this case better not to use devm_request_*irq() at all)
MEI is used for manageability so the device might be alive also in S3 on some platforms, anyhow this might be reviewed more as we do disable interrupts explicitly on suspend. So far the current code has passed suspend/resume stress tests.
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
drivers/misc/mei/pci-txe.c static int mei_txe_probe(struct pci_dev *pdev, · line 67
Quoted 7 lines
return 0;
drivers/misc/mei/pci-txe.c +1
-0@@ -75,22 +64,22 @@ static int mei_txe_probe(struct pci_dev *pdev, const struct pci_device_id *ent) { struct mei_device *dev; struct mei_txe_hw *hw; + const int mask = BIT(SEC_BAR) | BIT(BRIDGE_BAR);First line?
Quoted 8 lines
Quoted 1 line
Please be more verbose.
Use reversed tree for definition block.
The longest lines with the assignment = first; Then lines without assignment; Then return code variable;
Flags for
spin_lock-- depends.
I haven't seen this rule in coding style doc, this is the first I'm seeing such request. W/o offence I prefer the current style.
Quoted 11 lines
Quoted 10 lines
Quoted 7 lines
Review static int mei_txe_probe(struct pci_dev *pdev, · line 69
Quoted 4 lines
(quoted diff) +2
-0+ memcpy(hw->mem_addr, pcim_iomap_table(pdev), +sizeof(hw->mem_addr));Why?
It is kept by PCI core, you don't need a copy.There is no simple accessor for that, it's easier to copy the two dwords then going over the function calls.
Quoted 7 lines
I'm not sure you need a copy. That function call just return the pointer to the table.
I remember 8250_pci used to have similar approach, now it's using whatever is kept by PCI core.
It's less error prone.
Yep, we definitely can use a pointer here .
Quoted 11 lines
Quoted 8 lines
Quoted 8 lines
drivers/misc/mei/pci-me.c static int mei_txe_pci_suspend(struct device · line 212
Quoted 6 lines
drivers/misc/mei/pci-me.c +1
-1@@ -256,7 +210,7 @@ static int mei_txe_pci_suspend(struct device *device) - free_irq(pdev->irq, dev); + devm_free_irq(&pdev->dev, pdev->irq, dev); pci_disable_msi(pdev);All are redundant.
Yeah, same clarification as for above case with system sleep.
Thanks for the review, will post v2, tomorrow as this will requires some more stress testing Thanks
Tomas
Quoted 13 lines · Tomas
Quoted 13 lines · Tomas
Quoted 9 lines
Quoted 6 lines
drivers/misc/mei/pci-me.c static int mei_me_pci_suspend(struct device *device) · line 292
Quoted 4 lines
drivers/misc/mei/pci-me.c +1
-1-free_irq (pdev->irq, dev); +devm_free_irq (&pdev->dev, pdev->irq, dev);pci_disable_msi (pdev);All three not needed
I believe we need it on suspend as we are going over irq request again in resume. Please provide more info you if you still insist.
Ah, sorry, I missed that these are suspend/resume hooks.
Quoted 8 lines
Quoted 4 lines
So, Can you elaborate a bit why you need to disable interrupts during system suspend?
(Basically in this case better not to use devm_request_*irq() at all)
MEI is used for manageability so the device might be alive also in S3 on some platforms, anyhow this might be reviewed more as we do disable interrupts explicitly on suspend. So far the current code has passed suspend/resume stress tests.
OK, so, I would recommend to use old variant with plain request_threaded_irq() / free_irq().
Those (IRQ related) functions somehow mistakenly got devm_*() variation. It's not first time where devm_*irq() is inconvenient in some ways.
Quoted 9 lines
Quoted 6 lines
Use reversed tree for definition block.
The longest lines with the assignment = first; Then lines without assignment; Then return code variable;
Flags for
spin_lock-- depends.I haven't seen this rule in coding style doc, this is the first I'm seeing such request. W/o offence I prefer the current style.
Yes, this is matter of style -- your choice.
Quoted 9 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/misc/mei/pci-me.c static int mei_txe_pci_suspend(struct device · line 212
Quoted 5 lines
drivers/misc/mei/pci-me.c +1
-1@@ -256,7 +210,7 @@ static int mei_txe_pci_suspend(struct device *device) -free_irq (pdev->irq, dev); +devm_free_irq (&pdev->dev, pdev->irq, dev);pci_disable_msi (pdev);All are redundant.
Thanks for the review, will post v2, tomorrow as this will requires some more stress testing
Take your time.
Signature · 2 lines
With Best Regards, Andy Shevchenko