All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tom Gundersen <teg@jklm.no>
To: David Herrmann <dh.herrmann@gmail.com>
Cc: "dri-devel@lists.freedesktop.org" <dri-devel@lists.freedesktop.org>
Subject: Re: [PATCH v5 3/7] of/platform: expose of_platform_device_destroy()
Date: Fri, 2 Sep 2016 12:21:03 +0200	[thread overview]
Message-ID: <CAG-2HqXSxW-uaDPKPs8aFmO1WXd2M=4oo4xu3Ss3E_7WhY5ajQ@mail.gmail.com> (raw)
In-Reply-To: <20160902082245.7119-4-dh.herrmann@gmail.com>

On Fri, Sep 2, 2016 at 10:22 AM, David Herrmann <dh.herrmann@gmail.com> wrote:
> We already expose of_platform_device_create(), but give the caller no
> chance to revert its effect. Make sure we also provide the counterpart
> of_platform_device_destroy().
>
> This requires a small refactoring, since so far the internal destructor
> is used as iterator to for_each_device(), but we don't want to expose it
> with the "void *data" parameter. So provide
> of_platform_device_depopulate() as new iterator, which calls into
> of_platform_device_destroy().
>
> While at it, drop the unused 'children_left' argument by
> of_platform_notify(). It is a left-over that somehow was never removed.
>
> Signed-off-by: David Herrmann <dh.herrmann@gmail.com>

Reviewed-by: Tom Gundersen <teg@jklm.no>

> ---
>  drivers/of/platform.c       | 35 ++++++++++++++++++++++++++---------
>  include/linux/of_platform.h |  1 +
>  2 files changed, 27 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/of/platform.c b/drivers/of/platform.c
> index f39ccd5..f9bb563 100644
> --- a/drivers/of/platform.c
> +++ b/drivers/of/platform.c
> @@ -524,15 +524,18 @@ static int __init of_platform_default_populate_init(void)
>  arch_initcall_sync(of_platform_default_populate_init);
>  #endif
>
> -static int of_platform_device_destroy(struct device *dev, void *data)
> +/**
> + * of_platform_device_destroy - unregister an of_device
> + * @dev: device to unregister
> + *
> + * This is the inverse operation of of_platform_device_create(). It unregisters
> + * the passed device, if registered.
> + */
> +void of_platform_device_destroy(struct device *dev)
>  {
>         /* Do not touch devices not populated from the device tree */
>         if (!dev->of_node || !of_node_check_flag(dev->of_node, OF_POPULATED))
> -               return 0;
> -
> -       /* Recurse for any nodes that were treated as busses */
> -       if (of_node_check_flag(dev->of_node, OF_POPULATED_BUS))
> -               device_for_each_child(dev, NULL, of_platform_device_destroy);
> +               return;
>
>         if (dev->bus == &platform_bus_type)
>                 platform_device_unregister(to_platform_device(dev));
> @@ -544,6 +547,20 @@ static int of_platform_device_destroy(struct device *dev, void *data)
>         of_dma_deconfigure(dev);
>         of_node_clear_flag(dev->of_node, OF_POPULATED);
>         of_node_clear_flag(dev->of_node, OF_POPULATED_BUS);
> +}
> +EXPORT_SYMBOL(of_platform_device_destroy);
> +
> +static int of_platform_device_depopulate(struct device *dev, void *data)
> +{
> +       /* Do not touch devices not populated from the device tree */
> +       if (!dev->of_node || !of_node_check_flag(dev->of_node, OF_POPULATED))
> +               return 0;
> +
> +       /* Recurse for any nodes that were treated as busses */
> +       if (of_node_check_flag(dev->of_node, OF_POPULATED_BUS))
> +               device_for_each_child(dev, NULL, of_platform_device_depopulate);
> +
> +       of_platform_device_destroy(dev);
>         return 0;
>  }
>
> @@ -562,7 +579,8 @@ static int of_platform_device_destroy(struct device *dev, void *data)
>  void of_platform_depopulate(struct device *parent)
>  {
>         if (parent->of_node && of_node_check_flag(parent->of_node, OF_POPULATED_BUS)) {
> -               device_for_each_child(parent, NULL, of_platform_device_destroy);
> +               device_for_each_child(parent, NULL,
> +                                     of_platform_device_depopulate);
>                 of_node_clear_flag(parent->of_node, OF_POPULATED_BUS);
>         }
>  }
> @@ -574,7 +592,6 @@ static int of_platform_notify(struct notifier_block *nb,
>  {
>         struct of_reconfig_data *rd = arg;
>         struct platform_device *pdev_parent, *pdev;
> -       bool children_left;
>
>         switch (of_reconfig_get_state_change(action, rd)) {
>         case OF_RECONFIG_CHANGE_ADD:
> @@ -612,7 +629,7 @@ static int of_platform_notify(struct notifier_block *nb,
>                         return NOTIFY_OK;       /* no? not meant for us */
>
>                 /* unregister takes one ref away */
> -               of_platform_device_destroy(&pdev->dev, &children_left);
> +               of_platform_device_depopulate(&pdev->dev, NULL);
>
>                 /* and put the reference of the find */
>                 of_dev_put(pdev);
> diff --git a/include/linux/of_platform.h b/include/linux/of_platform.h
> index 956a100..a9017d3 100644
> --- a/include/linux/of_platform.h
> +++ b/include/linux/of_platform.h
> @@ -63,6 +63,7 @@ extern struct platform_device *of_find_device_by_node(struct device_node *np);
>  extern struct platform_device *of_platform_device_create(struct device_node *np,
>                                                    const char *bus_id,
>                                                    struct device *parent);
> +extern void of_platform_device_destroy(struct device *dev);
>
>  extern int of_platform_bus_probe(struct device_node *root,
>                                  const struct of_device_id *matches,
> --
> 2.9.3
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2016-09-02 10:21 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-02  8:22 [PATCH v5 0/7] drm: add simpledrm driver David Herrmann
2016-09-02  8:22 ` [PATCH v5 1/7] x86/sysfb: add support for 64bit EFI lfb_base David Herrmann
2016-09-02 10:20   ` Tom Gundersen
2016-09-02  8:22 ` [PATCH v5 2/7] x86/sysfb: fix lfb_size calculation David Herrmann
2016-09-02 10:20   ` Tom Gundersen
2016-09-02  8:22 ` [PATCH v5 3/7] of/platform: expose of_platform_device_destroy() David Herrmann
2016-09-02 10:21   ` Tom Gundersen [this message]
2016-09-02  8:22 ` [PATCH v5 4/7] video: add generic framebuffer eviction David Herrmann
2016-09-02 10:21   ` Tom Gundersen
2016-09-03 12:06   ` Noralf Trønnes
2016-09-05 11:19     ` David Herrmann
2016-09-05 16:36       ` Noralf Trønnes
2016-09-02  8:22 ` [PATCH v5 5/7] drm: switch to sysfb_evict_conflicts() David Herrmann
2016-09-03 12:13   ` Noralf Trønnes
2016-09-02  8:22 ` [PATCH v5 6/7] drm: add SimpleDRM driver David Herrmann
2016-09-02 12:45   ` Tom Gundersen
2016-09-03 12:01   ` Noralf Trønnes
2016-09-03 12:05     ` David Herrmann
2016-09-05 16:39   ` Noralf Trønnes
2016-09-02  8:22 ` [PATCH v5 7/7] drm/simpledrm: add fbdev fallback support David Herrmann
2016-09-03 12:04   ` Noralf Trønnes
2016-09-03 17:15     ` Noralf Trønnes
2016-09-05 11:21       ` David Herrmann
2021-03-10  2:50 ` [PATCH v5 0/7] drm: add simpledrm driver nerdopolis
2021-03-10  9:10   ` Thomas Zimmermann
2021-03-10 13:52     ` nerdopolis
2021-03-12  3:49     ` nerdopolis
2021-03-12  8:03       ` Thomas Zimmermann
2021-03-12 13:25         ` nerdopolis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAG-2HqXSxW-uaDPKPs8aFmO1WXd2M=4oo4xu3Ss3E_7WhY5ajQ@mail.gmail.com' \
    --to=teg@jklm.no \
    --cc=dh.herrmann@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.