On Mon, Dec 17, 2018 at 04:01:59PM +0100, Thierry Reding wrote:
> From: Thierry Reding <[email protected]>
> 
> Add device-managed equivalents of the mbox_controller_register() and
> mbox_controller_unregister() functions that can be used to have the
> devres infrastructure automatically unregister mailbox controllers on
> driver probe failure or driver removal. This can help remove a lot of
> boiler plate code from drivers.
> 
> Signed-off-by: Thierry Reding <[email protected]>
> ---
>  drivers/mailbox/mailbox.c          | 70 ++++++++++++++++++++++++++++++
>  include/linux/mailbox_controller.h |  5 +++
>  2 files changed, 75 insertions(+)
> 
> diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c
> index 674b35f402f5..eb781e2b19cb 100644
> --- a/drivers/mailbox/mailbox.c
> +++ b/drivers/mailbox/mailbox.c
> @@ -515,3 +515,73 @@ void mbox_controller_unregister(struct mbox_controller 
> *mbox)
>       mutex_unlock(&con_mutex);
>  }
>  EXPORT_SYMBOL_GPL(mbox_controller_unregister);
> +
> +static void __devm_mbox_controller_unregister(struct device *dev, void *res)
> +{
> +     struct mbox_controller *mbox = res;
> +
> +     mbox_controller_unregister(mbox);

This looks wrong to me. See below for details.

[...]

> +int devm_mbox_controller_register(struct device *dev,
> +                               struct mbox_controller *mbox)
> +{
> +     struct mbox_controller **ptr;
> +     int err;
> +
> +     ptr = devres_alloc(__devm_mbox_controller_unregister, sizeof(*ptr),
> +                        GFP_KERNEL);

devres_alloc returns devres->data as ptr above

> +     if (!ptr)
> +             return -ENOMEM;
> +
> +     err = mbox_controller_register(mbox);
> +     if (err < 0) {
> +             devres_free(ptr);
> +             return err;
> +     }
> +
> +     devres_add(dev, ptr);
> +     *ptr = mbox;

And ...release is called with devres->data so we need *ptr
in devm_mbox_controller_unregister and not ptr itself something like:

        struct mbox_controller **mbox = res;
        mbox_controller_unregister(*mbox);

With above fixed:

Reviewed-by: Sudeep Holla <[email protected]>

--
Regards,
Sudeep

Reply via email to