Re: [PATCH] staging: fieldbus: simplify devm_anybuss_host_common_probe
From: Sven Van Asbroeck
Date: Fri Apr 09 2021 - 07:59:15 EST
Hello Tian, thank you for the contribution. See below.
On Fri, Apr 9, 2021 at 4:33 AM Tian Tao <tiantao6@xxxxxxxxxxxxx> wrote:
>
> Use devm_add_action_or_reset() instead of devres_alloc() and
> devres_add(), which works the same. This will simplify the
> code. There is no functional changes.
>
> Signed-off-by: Tian Tao <tiantao6@xxxxxxxxxxxxx>
> ---
> drivers/staging/fieldbus/anybuss/host.c | 20 ++++++++------------
> 1 file changed, 8 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/staging/fieldbus/anybuss/host.c b/drivers/staging/fieldbus/anybuss/host.c
> index 549cb7d5..2924e68 100644
> --- a/drivers/staging/fieldbus/anybuss/host.c
> +++ b/drivers/staging/fieldbus/anybuss/host.c
> @@ -1406,7 +1406,7 @@ void anybuss_host_common_remove(struct anybuss_host *host)
> }
> EXPORT_SYMBOL_GPL(anybuss_host_common_remove);
>
> -static void host_release(struct device *dev, void *res)
> +static void host_release(void *res)
> {
> struct anybuss_host **dr = res;
You're expecting a double pointer as the argument here...
>
> @@ -1417,21 +1417,17 @@ struct anybuss_host * __must_check
> devm_anybuss_host_common_probe(struct device *dev,
> const struct anybuss_ops *ops)
> {
> - struct anybuss_host **dr;
> struct anybuss_host *host;
> -
> - dr = devres_alloc(host_release, sizeof(struct anybuss_host *),
> - GFP_KERNEL);
> - if (!dr)
> - return ERR_PTR(-ENOMEM);
> + int ret;
>
> host = anybuss_host_common_probe(dev, ops);
> - if (IS_ERR(host)) {
> - devres_free(dr);
> + if (IS_ERR(host))
> return host;
> - }
> - *dr = host;
> - devres_add(dev, dr);
> +
> + ret = devm_add_action_or_reset(dev, host_release, host);
... yet you pass in a single pointer here. Is that going to work?
> + if (ret)
> + return ERR_PTR(ret);
> +
> return host;
> }
> EXPORT_SYMBOL_GPL(devm_anybuss_host_common_probe);
> --
> 2.7.4
>