From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Andrzej Hajda <a.hajda@samsung.com>
Cc: tomi.valkeinen@ti.com, dri-devel@lists.freedesktop.org,
Jyri Sarha <jsarha@ti.com>
Subject: Re: [PATCH] drm/drm_bridge: adjust bridge module's refcount
Date: Wed, 30 Nov 2016 10:16:53 +0200 [thread overview]
Message-ID: <3152671.eHEai4eFKf@avalon> (raw)
In-Reply-To: <96054fcd-cd6c-2db5-5eb9-394d1f829c30@samsung.com>
Hi Andrzej,
On Wednesday 30 Nov 2016 09:11:56 Andrzej Hajda wrote:
> On 29.11.2016 22:12, Jyri Sarha wrote:
> > Store the module that provides the bridge and adjust its refcount
> > accordingly. The bridge module unload should not be allowed while the
> > bridge is attached.
>
> Module refcounting as a way of preventing driver from unbinding
> is quite popular, but as other developers said already is incorrect
> solution - it does not really prevent from unbinding and is a hack.
Absolutely, module refcounting must not be used as a way to prevent unbinding,
but it's still necessary to prevent functions from disappearing. The unbinding
race has to be fixed through reference counting to prevent objects from being
freed, but if an object contains function pointers that refer to code part of
a module, object refcounting won't prevent the code from being removed. Only
module refcounting helps there. The two techniques are thus complementary.
> > Signed-off-by: Jyri Sarha <jsarha@ti.com>
> > ---
> >
> > drivers/gpu/drm/drm_bridge.c | 15 ++++++++++++---
> > include/drm/drm_bridge.h | 11 ++++++++++-
> > 2 files changed, 22 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c
> > index 0ee052b..36d427b 100644
> > --- a/drivers/gpu/drm/drm_bridge.c
> > +++ b/drivers/gpu/drm/drm_bridge.c
> > @@ -61,22 +61,26 @@
> > static LIST_HEAD(bridge_list);
> >
> > /**
> > - * drm_bridge_add - add the given bridge to the global bridge list
> > + * __drm_bridge_add - add the given bridge to the global bridge list
> > *
> > * @bridge: bridge control structure
> > + * @module: module that provides this bridge
> > *
> > * RETURNS:
> > * Unconditionally returns Zero.
> > */
> > -int drm_bridge_add(struct drm_bridge *bridge)
> > +int __drm_bridge_add(struct drm_bridge *bridge, struct module *module)
> > {
> > +#ifdef MODULE
> > + bridge->module = module;
> > +#endif
> > mutex_lock(&bridge_lock);
> > list_add_tail(&bridge->list, &bridge_list);
> > mutex_unlock(&bridge_lock);
> >
> > return 0;
> > }
> > -EXPORT_SYMBOL(drm_bridge_add);
> > +EXPORT_SYMBOL(__drm_bridge_add);
> >
> > /**
> > * drm_bridge_remove - remove the given bridge from the global bridge
> > list
> > @@ -114,6 +118,9 @@ int drm_bridge_attach(struct drm_device *dev, struct
> > drm_bridge *bridge)
> > if (bridge->dev)
> > return -EBUSY;
> >
> > + if (!try_module_get(bridge->module))
> > + return -ENOENT;
> > +
>
> module field can be missing, will it compile in such case?
>
> > bridge->dev = dev;
> >
> > if (bridge->funcs->attach)
> > @@ -144,6 +151,8 @@ void drm_bridge_detach(struct drm_bridge *bridge)
> > if (bridge->funcs->detach)
> > bridge->funcs->detach(bridge);
> >
> > + module_put(bridge->module);
> > +
> > bridge->dev = NULL;
> > }
> > EXPORT_SYMBOL(drm_bridge_detach);
> > diff --git a/include/drm/drm_bridge.h b/include/drm/drm_bridge.h
> > index 530a1d6..d60d5d2 100644
> > --- a/include/drm/drm_bridge.h
> > +++ b/include/drm/drm_bridge.h
> > @@ -25,6 +25,7 @@
> >
> > #include <linux/list.h>
> > #include <linux/ctype.h>
> > +#include <linux/module.h>
> > #include <drm/drm_mode_object.h>
> > #include <drm/drm_modes.h>
> >
> > @@ -192,13 +193,21 @@ struct drm_bridge {
> > #ifdef CONFIG_OF
> > struct device_node *of_node;
> > #endif
> > +#ifdef MODULE
> > + struct module *module;
> > +#endif
> > struct list_head list;
> >
> > const struct drm_bridge_funcs *funcs;
> > void *driver_private;
> > };
> >
> > -int drm_bridge_add(struct drm_bridge *bridge);
> > +int __drm_bridge_add(struct drm_bridge *bridge, struct module *module);
> > +#ifdef MODULE
> > +#define drm_bridge_add(bridge) __drm_bridge_add(bridge, THIS_MODULE)
> > +#else
> > +#define drm_bridge_add(bridge) __drm_bridge_add(bridge, NULL)
> > +#endif
>
> If I remember correctly THIS_MODULE is NULL if MODULE is undefined.
> So the whole #ifdef here is unnecessary.
--
Regards,
Laurent Pinchart
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2016-11-30 8:16 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20161129211315epcas3p2a805abe8449509312f481ab7dcea96ef@epcas3p2.samsung.com>
2016-11-29 21:12 ` [PATCH] drm/drm_bridge: adjust bridge module's refcount Jyri Sarha
2016-11-29 21:30 ` Jyri Sarha
2016-11-29 22:06 ` Laurent Pinchart
2016-11-30 8:13 ` Daniel Vetter
2016-11-30 8:25 ` Laurent Pinchart
2016-11-30 9:12 ` Daniel Vetter
2016-11-30 9:56 ` Laurent Pinchart
2016-11-30 10:55 ` Daniel Vetter
2016-11-30 11:03 ` Laurent Pinchart
2016-11-30 13:09 ` Daniel Vetter
2016-12-01 7:07 ` Andrzej Hajda
2016-12-01 7:18 ` Daniel Vetter
2016-12-01 13:22 ` Andrzej Hajda
2016-12-01 15:12 ` Daniel Vetter
2016-12-02 6:49 ` Andrzej Hajda
2016-11-30 8:32 ` Jyri Sarha
2016-11-30 8:37 ` Laurent Pinchart
2016-11-30 8:55 ` Jyri Sarha
2016-11-30 9:03 ` Laurent Pinchart
2016-11-30 9:13 ` Jyri Sarha
2016-11-30 9:30 ` Laurent Pinchart
2016-11-30 8:11 ` Andrzej Hajda
2016-11-30 8:16 ` Laurent Pinchart [this message]
2016-11-30 9:26 ` Andrzej Hajda
2016-11-30 9:39 ` Laurent Pinchart
2016-12-01 6:50 ` Andrzej Hajda
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=3152671.eHEai4eFKf@avalon \
--to=laurent.pinchart@ideasonboard.com \
--cc=a.hajda@samsung.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=jsarha@ti.com \
--cc=tomi.valkeinen@ti.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).