[PATCH v4 2/2] power: supply: max17042: add platform driver variant
Dzmitry Sankouski
dsankouski at gmail.com
Sat Nov 30 03:38:21 PST 2024
пт, 29 нояб. 2024 г. в 17:03, Amit Singh Tomar <amitsinght at marvell.com>:
>
> Hi,
>
> >
> > The solution here add and option to use max17042 driver as a MFD
> > sub device, thus allowing any additional functionality be implemented as
> > another sub device. This will help to reduce code duplication in MFD
> > fuel gauge drivers.
> >
> > Signed-off-by: Dzmitry Sankouski <dsankouski at gmail.com>
> > ---
> > Changes in v4:
> > - rename module_init and module_exit fuctions
> > - rework max17042_init
> > - assign chip_type in probe function
> > - pass i2c_client as pointer on pointer, to use same pointer created in
> > MFD. This allows devm_regmap_init_i2c to cleanup gracefully.
> >
> > Changes in v3:
> > - pass dev pointer in max17042_probe
> > - remove prints
> > ---
> > drivers/power/supply/max17042_battery.c | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------
> > 1 file changed, 92 insertions(+), 24 deletions(-)
> >
> > diff --git a/drivers/power/supply/max17042_battery.c b/drivers/power/supply/max17042_battery.c
(...)
> > +static int max17042_platform_probe(struct platform_device *pdev)
> > +{
> > + struct device *dev = &pdev->dev;
> > + struct i2c_client **i2c = dev_get_platdata(dev);
> This seems a bit unusual; can't we just use:
> struct i2c_client *i2c = dev_get_platdata(&pdev->dev); instead?
> > + const struct platform_device_id *id = platform_get_device_id(pdev);
> > +
> > + if (!i2c)
> > + return -EINVAL;
> > +
> > + return max17042_probe(*i2c, dev, id->driver_data);
> and then just pass "i2c" here ?
This leads to hang on freeing devm resources, when unloading modules.
Platform driver version intended to be used as MFD sub device, where mfd
creates a dummy i2c client, and passes it to max17042 via platform data.
Sequence is: insmod MFD; insmod max17042; rmmod max17042; rmmod MFD; hang here.
My guess is that it is caused by a new pointer to the i2c-client. New pointer
created at `platform_device_add_data` function call in `mfd_add_device`.
Since C is pass by value, new pointer is assigned to platform device data.
--
Best regards,
Dzmitry
More information about the linux-arm-kernel
mailing list