Use devm_mfd_add_devices() for adding MFD child devices and
devm_regmap_add_irq_chip() for IRQ chip registration.
This reduces the amount of required cleanup.
Signed-off-by: Alexander Kurz <akurz@blala.de>
---
drivers/mfd/mc13xxx-core.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/mfd/mc13xxx-core.c b/drivers/mfd/mc13xxx-core.c
index 920797b806ce..091c9171b2b7 100644
--- a/drivers/mfd/mc13xxx-core.c
+++ b/drivers/mfd/mc13xxx-core.c
@@ -381,7 +381,7 @@ static int mc13xxx_add_subdevice_pdata(struct mc13xxx *mc13xxx,
if (!cell.name)
return -ENOMEM;
- return mfd_add_devices(mc13xxx->dev, -1, &cell, 1, NULL, 0,
+ return devm_mfd_add_devices(mc13xxx->dev, -1, &cell, 1, NULL, 0,
regmap_irq_get_domain(mc13xxx->irq_data));
}
@@ -455,8 +455,9 @@ int mc13xxx_common_init(struct device *dev)
mc13xxx->irq_chip.irqs = mc13xxx->irqs;
mc13xxx->irq_chip.num_irqs = ARRAY_SIZE(mc13xxx->irqs);
- ret = regmap_add_irq_chip(mc13xxx->regmap, mc13xxx->irq, IRQF_ONESHOT,
- 0, &mc13xxx->irq_chip, &mc13xxx->irq_data);
+ ret = devm_regmap_add_irq_chip(dev, mc13xxx->regmap, mc13xxx->irq,
+ IRQF_ONESHOT, 0, &mc13xxx->irq_chip,
+ &mc13xxx->irq_data);
if (ret)
return ret;
@@ -502,8 +503,6 @@ void mc13xxx_common_exit(struct device *dev)
{
struct mc13xxx *mc13xxx = dev_get_drvdata(dev);
- mfd_remove_devices(dev);
- regmap_del_irq_chip(mc13xxx->irq, mc13xxx->irq_data);
mutex_destroy(&mc13xxx->lock);
}
EXPORT_SYMBOL_GPL(mc13xxx_common_exit);
--
2.39.5
Hi Alexander,
On Sun, Sep 14, 2025 at 07:37:19PM +0000, Alexander Kurz wrote:
> Use devm_mfd_add_devices() for adding MFD child devices and
> devm_regmap_add_irq_chip() for IRQ chip registration.
>
> This reduces the amount of required cleanup.
>
> Signed-off-by: Alexander Kurz <akurz@blala.de>
> ---
> drivers/mfd/mc13xxx-core.c | 9 ++++-----
> 1 file changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/mfd/mc13xxx-core.c b/drivers/mfd/mc13xxx-core.c
> index 920797b806ce..091c9171b2b7 100644
> --- a/drivers/mfd/mc13xxx-core.c
> +++ b/drivers/mfd/mc13xxx-core.c
> @@ -381,7 +381,7 @@ static int mc13xxx_add_subdevice_pdata(struct mc13xxx *mc13xxx,
> if (!cell.name)
> return -ENOMEM;
>
> - return mfd_add_devices(mc13xxx->dev, -1, &cell, 1, NULL, 0,
> + return devm_mfd_add_devices(mc13xxx->dev, -1, &cell, 1, NULL, 0,
> regmap_irq_get_domain(mc13xxx->irq_data));
> }
>
> @@ -455,8 +455,9 @@ int mc13xxx_common_init(struct device *dev)
> mc13xxx->irq_chip.irqs = mc13xxx->irqs;
> mc13xxx->irq_chip.num_irqs = ARRAY_SIZE(mc13xxx->irqs);
>
> - ret = regmap_add_irq_chip(mc13xxx->regmap, mc13xxx->irq, IRQF_ONESHOT,
> - 0, &mc13xxx->irq_chip, &mc13xxx->irq_data);
> + ret = devm_regmap_add_irq_chip(dev, mc13xxx->regmap, mc13xxx->irq,
> + IRQF_ONESHOT, 0, &mc13xxx->irq_chip,
> + &mc13xxx->irq_data);
> if (ret)
> return ret;
>
> @@ -502,8 +503,6 @@ void mc13xxx_common_exit(struct device *dev)
> {
> struct mc13xxx *mc13xxx = dev_get_drvdata(dev);
>
> - mfd_remove_devices(dev);
> - regmap_del_irq_chip(mc13xxx->irq, mc13xxx->irq_data);
> mutex_destroy(&mc13xxx->lock);
This causes the mutex be destroyed while the sub-devices are still
present. The power button will try to call mc13xxx_lock() and
mc13xxx_unlock() and of mutex debugging is enabled you'll get errors.
I'd remove mutex_destroy() as well (and transitively get rid of
mc13xxx_common_exit()) and then look into getting rid of mc13xxx_lock()
and mc13xxx_unlock() because, as I mentioned in another email, they are
IMO not needed.
But this version of the patch is broken as far as I can tell.
Thanks.
--
Dmitry
Hi Dimitry
On Tue, 16 Sep 2025, Dmitry Torokhov wrote:
> Hi Alexander,
>
> On Sun, Sep 14, 2025 at 07:37:19PM +0000, Alexander Kurz wrote:
> > Use devm_mfd_add_devices() for adding MFD child devices and
> > devm_regmap_add_irq_chip() for IRQ chip registration.
> >
> > This reduces the amount of required cleanup.
> >
> > Signed-off-by: Alexander Kurz <akurz@blala.de>
> > ---
> > drivers/mfd/mc13xxx-core.c | 9 ++++-----
> > 1 file changed, 4 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/mfd/mc13xxx-core.c b/drivers/mfd/mc13xxx-core.c
> > index 920797b806ce..091c9171b2b7 100644
> > --- a/drivers/mfd/mc13xxx-core.c
> > +++ b/drivers/mfd/mc13xxx-core.c
> > @@ -381,7 +381,7 @@ static int mc13xxx_add_subdevice_pdata(struct mc13xxx *mc13xxx,
> > if (!cell.name)
> > return -ENOMEM;
> >
> > - return mfd_add_devices(mc13xxx->dev, -1, &cell, 1, NULL, 0,
> > + return devm_mfd_add_devices(mc13xxx->dev, -1, &cell, 1, NULL, 0,
> > regmap_irq_get_domain(mc13xxx->irq_data));
> > }
> >
> > @@ -455,8 +455,9 @@ int mc13xxx_common_init(struct device *dev)
> > mc13xxx->irq_chip.irqs = mc13xxx->irqs;
> > mc13xxx->irq_chip.num_irqs = ARRAY_SIZE(mc13xxx->irqs);
> >
> > - ret = regmap_add_irq_chip(mc13xxx->regmap, mc13xxx->irq, IRQF_ONESHOT,
> > - 0, &mc13xxx->irq_chip, &mc13xxx->irq_data);
> > + ret = devm_regmap_add_irq_chip(dev, mc13xxx->regmap, mc13xxx->irq,
> > + IRQF_ONESHOT, 0, &mc13xxx->irq_chip,
> > + &mc13xxx->irq_data);
> > if (ret)
> > return ret;
> >
> > @@ -502,8 +503,6 @@ void mc13xxx_common_exit(struct device *dev)
> > {
> > struct mc13xxx *mc13xxx = dev_get_drvdata(dev);
> >
> > - mfd_remove_devices(dev);
> > - regmap_del_irq_chip(mc13xxx->irq, mc13xxx->irq_data);
> > mutex_destroy(&mc13xxx->lock);
>
> This causes the mutex be destroyed while the sub-devices are still
> present. The power button will try to call mc13xxx_lock() and
> mc13xxx_unlock() and of mutex debugging is enabled you'll get errors.
Thanks for noting this, actually I have introduced this change
in v4 of this series.
> I'd remove mutex_destroy() as well (and transitively get rid of
> mc13xxx_common_exit()) and then look into getting rid of mc13xxx_lock()
> and mc13xxx_unlock() because, as I mentioned in another email, they are
> IMO not needed.
I would prefer not to extend the scope of this series even further
and just drop this patch for v5.
There are still more issues todo with mc13xxx, e.g. mc13xxx-led does
not work since commit 78efa53e715e ("leds: Init leds class earlier").
Cleaning up potentially legacy mutex is just one more topic on this list.
>
> But this version of the patch is broken as far as I can tell.
>
> Thanks.
>
> --
> Dmitry
>
Thanks, Alexander
On Tue, 16 Sep 2025, Dmitry Torokhov wrote:
> Hi Alexander,
>
> On Sun, Sep 14, 2025 at 07:37:19PM +0000, Alexander Kurz wrote:
> > Use devm_mfd_add_devices() for adding MFD child devices and
> > devm_regmap_add_irq_chip() for IRQ chip registration.
> >
> > This reduces the amount of required cleanup.
> >
> > Signed-off-by: Alexander Kurz <akurz@blala.de>
> > ---
> > drivers/mfd/mc13xxx-core.c | 9 ++++-----
> > 1 file changed, 4 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/mfd/mc13xxx-core.c b/drivers/mfd/mc13xxx-core.c
> > index 920797b806ce..091c9171b2b7 100644
> > --- a/drivers/mfd/mc13xxx-core.c
> > +++ b/drivers/mfd/mc13xxx-core.c
> > @@ -381,7 +381,7 @@ static int mc13xxx_add_subdevice_pdata(struct mc13xxx *mc13xxx,
> > if (!cell.name)
> > return -ENOMEM;
> >
> > - return mfd_add_devices(mc13xxx->dev, -1, &cell, 1, NULL, 0,
> > + return devm_mfd_add_devices(mc13xxx->dev, -1, &cell, 1, NULL, 0,
> > regmap_irq_get_domain(mc13xxx->irq_data));
> > }
> >
> > @@ -455,8 +455,9 @@ int mc13xxx_common_init(struct device *dev)
> > mc13xxx->irq_chip.irqs = mc13xxx->irqs;
> > mc13xxx->irq_chip.num_irqs = ARRAY_SIZE(mc13xxx->irqs);
> >
> > - ret = regmap_add_irq_chip(mc13xxx->regmap, mc13xxx->irq, IRQF_ONESHOT,
> > - 0, &mc13xxx->irq_chip, &mc13xxx->irq_data);
> > + ret = devm_regmap_add_irq_chip(dev, mc13xxx->regmap, mc13xxx->irq,
> > + IRQF_ONESHOT, 0, &mc13xxx->irq_chip,
> > + &mc13xxx->irq_data);
> > if (ret)
> > return ret;
> >
> > @@ -502,8 +503,6 @@ void mc13xxx_common_exit(struct device *dev)
> > {
> > struct mc13xxx *mc13xxx = dev_get_drvdata(dev);
> >
> > - mfd_remove_devices(dev);
> > - regmap_del_irq_chip(mc13xxx->irq, mc13xxx->irq_data);
> > mutex_destroy(&mc13xxx->lock);
>
> This causes the mutex be destroyed while the sub-devices are still
> present. The power button will try to call mc13xxx_lock() and
> mc13xxx_unlock() and of mutex debugging is enabled you'll get errors.
>
> I'd remove mutex_destroy() as well (and transitively get rid of
> mc13xxx_common_exit()) and then look into getting rid of mc13xxx_lock()
> and mc13xxx_unlock() because, as I mentioned in another email, they are
> IMO not needed.
>
> But this version of the patch is broken as far as I can tell.
Thanks for the input Dmitry.
I have removed the patch until this gets resolved.
--
Lee Jones [李琼斯]
On Sun, 14 Sep 2025 19:37:19 +0000, Alexander Kurz wrote:
> Use devm_mfd_add_devices() for adding MFD child devices and
> devm_regmap_add_irq_chip() for IRQ chip registration.
>
> This reduces the amount of required cleanup.
>
>
Applied, thanks!
[4/8] mfd: mc13xxx: Use devm_mfd_add_devices and devm_regmap_add_irq_chip
commit: c5f395868781099e54a220bd5d6dc60c698c8c72
--
Lee Jones [李琼斯]
© 2016 - 2026 Red Hat, Inc.