Message ID | 20250211-aux-device-create-helper-v3-2-7edb50524909@baylibre.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | driver core: auxiliary bus: add device creation helper | expand |
On Tue, Feb 11, 2025 at 06:27:59PM +0100, Jerome Brunet wrote: > The auxiliary device creation of this driver is simple enough to > use the available auxiliary device creation helper. > > Use it and remove some boilerplate code. > > Signed-off-by: Jerome Brunet <jbrunet@baylibre.com> > --- > drivers/reset/reset-mpfs.c | 52 +++------------------------------------------- > 1 file changed, 3 insertions(+), 49 deletions(-) > > diff --git a/drivers/reset/reset-mpfs.c b/drivers/reset/reset-mpfs.c > index 574e59db83a4fcf30b60cb5f638607a2ec7b0580..bbea64862181877eb7ae51fdaa9e50ffac17c908 100644 > --- a/drivers/reset/reset-mpfs.c > +++ b/drivers/reset/reset-mpfs.c > @@ -155,62 +155,16 @@ static int mpfs_reset_probe(struct auxiliary_device *adev, > return devm_reset_controller_register(dev, rcdev); > } > > -static void mpfs_reset_unregister_adev(void *_adev) > -{ > - struct auxiliary_device *adev = _adev; > - > - auxiliary_device_delete(adev); > - auxiliary_device_uninit(adev); > -} > - > -static void mpfs_reset_adev_release(struct device *dev) > -{ > - struct auxiliary_device *adev = to_auxiliary_dev(dev); > - > - kfree(adev); > -} > - > -static struct auxiliary_device *mpfs_reset_adev_alloc(struct device *clk_dev) > -{ > - struct auxiliary_device *adev; > - int ret; > - > - adev = kzalloc(sizeof(*adev), GFP_KERNEL); > - if (!adev) > - return ERR_PTR(-ENOMEM); > - > - adev->name = "reset-mpfs"; > - adev->dev.parent = clk_dev; > - adev->dev.release = mpfs_reset_adev_release; > - adev->id = 666u; > - > - ret = auxiliary_device_init(adev); > - if (ret) { > - kfree(adev); > - return ERR_PTR(ret); > - } > - > - return adev; > -} > - > int mpfs_reset_controller_register(struct device *clk_dev, void __iomem *base) > { > struct auxiliary_device *adev; > - int ret; > > - adev = mpfs_reset_adev_alloc(clk_dev); > + adev = devm_auxiliary_device_create(clk_dev, "reset-mpfs", > + (__force void *)base, 666u); Moving the boilerplate into a helper makes sense: Acked-by: Conor Dooley <conor.dooley@microchip.com> One think that's always felt a bit meh to me is this id number stuff, I just threw in 666 for meme value. The whole thing seems super arbitrary, do any of the users of this helper actually put meaningful values into the id parameter? > if (IS_ERR(adev)) > return PTR_ERR(adev); > > - ret = auxiliary_device_add(adev); > - if (ret) { > - auxiliary_device_uninit(adev); > - return ret; > - } > - > - adev->dev.platform_data = (__force void *)base; > - > - return devm_add_action_or_reset(clk_dev, mpfs_reset_unregister_adev, adev); > + return 0; > } > EXPORT_SYMBOL_NS_GPL(mpfs_reset_controller_register, "MCHP_CLK_MPFS"); > > > -- > 2.45.2 >
On Thu 13 Feb 2025 at 17:59, Conor Dooley <conor@kernel.org> wrote: > On Tue, Feb 11, 2025 at 06:27:59PM +0100, Jerome Brunet wrote: >> The auxiliary device creation of this driver is simple enough to >> use the available auxiliary device creation helper. >> >> Use it and remove some boilerplate code. >> >> Signed-off-by: Jerome Brunet <jbrunet@baylibre.com> >> --- >> drivers/reset/reset-mpfs.c | 52 +++------------------------------------------- >> 1 file changed, 3 insertions(+), 49 deletions(-) >> >> diff --git a/drivers/reset/reset-mpfs.c b/drivers/reset/reset-mpfs.c >> index 574e59db83a4fcf30b60cb5f638607a2ec7b0580..bbea64862181877eb7ae51fdaa9e50ffac17c908 100644 >> --- a/drivers/reset/reset-mpfs.c >> +++ b/drivers/reset/reset-mpfs.c >> @@ -155,62 +155,16 @@ static int mpfs_reset_probe(struct auxiliary_device *adev, >> return devm_reset_controller_register(dev, rcdev); >> } >> >> -static void mpfs_reset_unregister_adev(void *_adev) >> -{ >> - struct auxiliary_device *adev = _adev; >> - >> - auxiliary_device_delete(adev); >> - auxiliary_device_uninit(adev); >> -} >> - >> -static void mpfs_reset_adev_release(struct device *dev) >> -{ >> - struct auxiliary_device *adev = to_auxiliary_dev(dev); >> - >> - kfree(adev); >> -} >> - >> -static struct auxiliary_device *mpfs_reset_adev_alloc(struct device *clk_dev) >> -{ >> - struct auxiliary_device *adev; >> - int ret; >> - >> - adev = kzalloc(sizeof(*adev), GFP_KERNEL); >> - if (!adev) >> - return ERR_PTR(-ENOMEM); >> - >> - adev->name = "reset-mpfs"; >> - adev->dev.parent = clk_dev; >> - adev->dev.release = mpfs_reset_adev_release; >> - adev->id = 666u; >> - >> - ret = auxiliary_device_init(adev); >> - if (ret) { >> - kfree(adev); >> - return ERR_PTR(ret); >> - } >> - >> - return adev; >> -} >> - >> int mpfs_reset_controller_register(struct device *clk_dev, void __iomem *base) >> { >> struct auxiliary_device *adev; >> - int ret; >> >> - adev = mpfs_reset_adev_alloc(clk_dev); >> + adev = devm_auxiliary_device_create(clk_dev, "reset-mpfs", >> + (__force void *)base, 666u); > > Moving the boilerplate into a helper makes sense: > Acked-by: Conor Dooley <conor.dooley@microchip.com> > > One think that's always felt a bit meh to me is this id number stuff, > I just threw in 666 for meme value. :) > The whole thing seems super > arbitrary, do any of the users of this helper actually put meaningful > values into the id parameter? In example changes I've sent, no. In other simple usages (those using container_of()) of the auxiliary bus, I think there are a few that uses 0 and 1 for 2 instances. I guess your question is "do we really need this parameter here ?" We could remove it and still address 90% of the original target. Keeping it leaves the door open in case the figure above does not hold and it is pretty cheap to do. It could also enable drivers requiring an IDA to use the helper, possibly. > >> if (IS_ERR(adev)) >> return PTR_ERR(adev); >> >> - ret = auxiliary_device_add(adev); >> - if (ret) { >> - auxiliary_device_uninit(adev); >> - return ret; >> - } >> - >> - adev->dev.platform_data = (__force void *)base; >> - >> - return devm_add_action_or_reset(clk_dev, mpfs_reset_unregister_adev, adev); >> + return 0; >> } >> EXPORT_SYMBOL_NS_GPL(mpfs_reset_controller_register, "MCHP_CLK_MPFS"); >> >> >> -- >> 2.45.2 >>
Hi, On Fri, Feb 14, 2025 at 12:59 AM Jerome Brunet <jbrunet@baylibre.com> wrote: > > > One think that's always felt a bit meh to me is this id number stuff, > > I just threw in 666 for meme value. > > :) > > > The whole thing seems super > > arbitrary, do any of the users of this helper actually put meaningful > > values into the id parameter? > > In example changes I've sent, no. > > In other simple usages (those using container_of()) of the auxiliary > bus, I think there are a few that uses 0 and 1 for 2 instances. > > I guess your question is "do we really need this parameter here ?" > > We could remove it and still address 90% of the original target. > > Keeping it leaves the door open in case the figure above does not hold > and it is pretty cheap to do. It could also enable drivers requiring an > IDA to use the helper, possibly. FWIW, once you resolve the conflicts in drm-misc with ti-sn65dsi86 you'll need the ID value. ;-) There was a big-ol' discussion here: https://lore.kernel.org/r/8c2df6a903f87d4932586b25f1d3bd548fe8e6d1.1729180470.git.geert+renesas@glider.be I eventually pushed v2 of the patch: https://lore.kernel.org/r/7a68a0e3f927e26edca6040067fb653eb06efb79.1733840089.git.geert+renesas@glider.be -Doug
On Fri, Feb 14, 2025 at 07:25:59AM -0800, Doug Anderson wrote: > Hi, > > On Fri, Feb 14, 2025 at 12:59 AM Jerome Brunet <jbrunet@baylibre.com> wrote: > > > > > One think that's always felt a bit meh to me is this id number stuff, > > > I just threw in 666 for meme value. > > > > :) > > > > > The whole thing seems super > > > arbitrary, do any of the users of this helper actually put meaningful > > > values into the id parameter? > > > > In example changes I've sent, no. > > > > In other simple usages (those using container_of()) of the auxiliary > > bus, I think there are a few that uses 0 and 1 for 2 instances. > > > > I guess your question is "do we really need this parameter here ?" > > > > We could remove it and still address 90% of the original target. > > > > Keeping it leaves the door open in case the figure above does not hold > > and it is pretty cheap to do. It could also enable drivers requiring an > > IDA to use the helper, possibly. > > FWIW, once you resolve the conflicts in drm-misc with ti-sn65dsi86 > you'll need the ID value. ;-) > > There was a big-ol' discussion here: > > https://lore.kernel.org/r/8c2df6a903f87d4932586b25f1d3bd548fe8e6d1.1729180470.git.geert+renesas@glider.be > > I eventually pushed v2 of the patch: > > https://lore.kernel.org/r/7a68a0e3f927e26edca6040067fb653eb06efb79.1733840089.git.geert+renesas@glider.be Think it makes sense to have a "simplified" wrapper for the cases where the id has no meaning then? Not really a fan of the drivers coming up with magic numbers.
diff --git a/drivers/reset/reset-mpfs.c b/drivers/reset/reset-mpfs.c index 574e59db83a4fcf30b60cb5f638607a2ec7b0580..bbea64862181877eb7ae51fdaa9e50ffac17c908 100644 --- a/drivers/reset/reset-mpfs.c +++ b/drivers/reset/reset-mpfs.c @@ -155,62 +155,16 @@ static int mpfs_reset_probe(struct auxiliary_device *adev, return devm_reset_controller_register(dev, rcdev); } -static void mpfs_reset_unregister_adev(void *_adev) -{ - struct auxiliary_device *adev = _adev; - - auxiliary_device_delete(adev); - auxiliary_device_uninit(adev); -} - -static void mpfs_reset_adev_release(struct device *dev) -{ - struct auxiliary_device *adev = to_auxiliary_dev(dev); - - kfree(adev); -} - -static struct auxiliary_device *mpfs_reset_adev_alloc(struct device *clk_dev) -{ - struct auxiliary_device *adev; - int ret; - - adev = kzalloc(sizeof(*adev), GFP_KERNEL); - if (!adev) - return ERR_PTR(-ENOMEM); - - adev->name = "reset-mpfs"; - adev->dev.parent = clk_dev; - adev->dev.release = mpfs_reset_adev_release; - adev->id = 666u; - - ret = auxiliary_device_init(adev); - if (ret) { - kfree(adev); - return ERR_PTR(ret); - } - - return adev; -} - int mpfs_reset_controller_register(struct device *clk_dev, void __iomem *base) { struct auxiliary_device *adev; - int ret; - adev = mpfs_reset_adev_alloc(clk_dev); + adev = devm_auxiliary_device_create(clk_dev, "reset-mpfs", + (__force void *)base, 666u); if (IS_ERR(adev)) return PTR_ERR(adev); - ret = auxiliary_device_add(adev); - if (ret) { - auxiliary_device_uninit(adev); - return ret; - } - - adev->dev.platform_data = (__force void *)base; - - return devm_add_action_or_reset(clk_dev, mpfs_reset_unregister_adev, adev); + return 0; } EXPORT_SYMBOL_NS_GPL(mpfs_reset_controller_register, "MCHP_CLK_MPFS");
The auxiliary device creation of this driver is simple enough to use the available auxiliary device creation helper. Use it and remove some boilerplate code. Signed-off-by: Jerome Brunet <jbrunet@baylibre.com> --- drivers/reset/reset-mpfs.c | 52 +++------------------------------------------- 1 file changed, 3 insertions(+), 49 deletions(-)