Commit 394febc9 authored by Christophe JAILLET's avatar Christophe JAILLET Committed by Greg Kroah-Hartman

misc/pvpanic: Make 'pvpanic_probe()' resource managed

Simplify code and turn 'pvpanic_probe()' into a managed resource version.
This simplify callers that don't need to do some clean-up on error in the
probe and on remove.

Update pvpanic-mmio.c and pvpanic-pci.c accordingly.

'pvpanic_remove()' don't need to be exported anymore.
Suggested-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: default avatarAndy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: default avatarChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Link: https://lore.kernel.org/r/9212cdc8c1e5c187a2f1129a6190085c2a10d28a.1621665058.git.christophe.jaillet@wanadoo.frSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent a224db27
...@@ -104,18 +104,7 @@ static int pvpanic_mmio_probe(struct platform_device *pdev) ...@@ -104,18 +104,7 @@ static int pvpanic_mmio_probe(struct platform_device *pdev)
pi->capability &= ioread8(base); pi->capability &= ioread8(base);
pi->events = pi->capability; pi->events = pi->capability;
dev_set_drvdata(dev, pi); return devm_pvpanic_probe(dev, pi);
return pvpanic_probe(pi);
}
static int pvpanic_mmio_remove(struct platform_device *pdev)
{
struct pvpanic_instance *pi = dev_get_drvdata(&pdev->dev);
pvpanic_remove(pi);
return 0;
} }
static const struct of_device_id pvpanic_mmio_match[] = { static const struct of_device_id pvpanic_mmio_match[] = {
...@@ -138,6 +127,5 @@ static struct platform_driver pvpanic_mmio_driver = { ...@@ -138,6 +127,5 @@ static struct platform_driver pvpanic_mmio_driver = {
.dev_groups = pvpanic_mmio_dev_groups, .dev_groups = pvpanic_mmio_dev_groups,
}, },
.probe = pvpanic_mmio_probe, .probe = pvpanic_mmio_probe,
.remove = pvpanic_mmio_remove,
}; };
module_platform_driver(pvpanic_mmio_driver); module_platform_driver(pvpanic_mmio_driver);
...@@ -73,7 +73,6 @@ ATTRIBUTE_GROUPS(pvpanic_pci_dev); ...@@ -73,7 +73,6 @@ ATTRIBUTE_GROUPS(pvpanic_pci_dev);
static int pvpanic_pci_probe(struct pci_dev *pdev, static int pvpanic_pci_probe(struct pci_dev *pdev,
const struct pci_device_id *ent) const struct pci_device_id *ent)
{ {
struct device *dev = &pdev->dev;
struct pvpanic_instance *pi; struct pvpanic_instance *pi;
void __iomem *base; void __iomem *base;
int ret; int ret;
...@@ -97,23 +96,13 @@ static int pvpanic_pci_probe(struct pci_dev *pdev, ...@@ -97,23 +96,13 @@ static int pvpanic_pci_probe(struct pci_dev *pdev,
pi->capability &= ioread8(base); pi->capability &= ioread8(base);
pi->events = pi->capability; pi->events = pi->capability;
dev_set_drvdata(dev, pi); return devm_pvpanic_probe(&pdev->dev, pi);
return pvpanic_probe(pi);
}
static void pvpanic_pci_remove(struct pci_dev *pdev)
{
struct pvpanic_instance *pi = dev_get_drvdata(&pdev->dev);
pvpanic_remove(pi);
} }
static struct pci_driver pvpanic_pci_driver = { static struct pci_driver pvpanic_pci_driver = {
.name = "pvpanic-pci", .name = "pvpanic-pci",
.id_table = pvpanic_pci_id_tbl, .id_table = pvpanic_pci_id_tbl,
.probe = pvpanic_pci_probe, .probe = pvpanic_pci_probe,
.remove = pvpanic_pci_remove,
.driver = { .driver = {
.dev_groups = pvpanic_pci_dev_groups, .dev_groups = pvpanic_pci_dev_groups,
}, },
......
...@@ -60,22 +60,10 @@ static struct notifier_block pvpanic_panic_nb = { ...@@ -60,22 +60,10 @@ static struct notifier_block pvpanic_panic_nb = {
.priority = 1, /* let this called before broken drm_fb_helper */ .priority = 1, /* let this called before broken drm_fb_helper */
}; };
int pvpanic_probe(struct pvpanic_instance *pi) static void pvpanic_remove(void *param)
{
if (!pi || !pi->base)
return -EINVAL;
spin_lock(&pvpanic_lock);
list_add(&pi->list, &pvpanic_list);
spin_unlock(&pvpanic_lock);
return 0;
}
EXPORT_SYMBOL_GPL(pvpanic_probe);
void pvpanic_remove(struct pvpanic_instance *pi)
{ {
struct pvpanic_instance *pi_cur, *pi_next; struct pvpanic_instance *pi_cur, *pi_next;
struct pvpanic_instance *pi = param;
if (!pi) if (!pi)
return; return;
...@@ -89,7 +77,19 @@ void pvpanic_remove(struct pvpanic_instance *pi) ...@@ -89,7 +77,19 @@ void pvpanic_remove(struct pvpanic_instance *pi)
} }
spin_unlock(&pvpanic_lock); spin_unlock(&pvpanic_lock);
} }
EXPORT_SYMBOL_GPL(pvpanic_remove);
int devm_pvpanic_probe(struct device *dev, struct pvpanic_instance *pi)
{
if (!pi || !pi->base)
return -EINVAL;
spin_lock(&pvpanic_lock);
list_add(&pi->list, &pvpanic_list);
spin_unlock(&pvpanic_lock);
return devm_add_action_or_reset(dev, pvpanic_remove, pi);
}
EXPORT_SYMBOL_GPL(devm_pvpanic_probe);
static int pvpanic_init(void) static int pvpanic_init(void)
{ {
......
...@@ -15,7 +15,6 @@ struct pvpanic_instance { ...@@ -15,7 +15,6 @@ struct pvpanic_instance {
struct list_head list; struct list_head list;
}; };
int pvpanic_probe(struct pvpanic_instance *pi); int devm_pvpanic_probe(struct device *dev, struct pvpanic_instance *pi);
void pvpanic_remove(struct pvpanic_instance *pi);
#endif /* PVPANIC_H_ */ #endif /* PVPANIC_H_ */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment