From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Xu Yang <xu.yang_2@nxp.com>
Cc: Alan Stern <stern@rowland.harvard.edu>,
Greg KH <gregkh@linuxfoundation.org>,
"benjamin.tissoires@redhat.com" <benjamin.tissoires@redhat.com>,
"hdegoede@redhat.com" <hdegoede@redhat.com>,
"ivan.orlov0322@gmail.com" <ivan.orlov0322@gmail.com>,
"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
dl-linux-imx <linux-imx@nxp.com>, Jun Li <jun.li@nxp.com>
Subject: Re: [EXT] Re: [PATCH] usb: roles: try to get/put all relevant modules
Date: Fri, 19 Jan 2024 15:21:59 +0200 [thread overview]
Message-ID: <Zapz8T2f8P+6+C24@kuha.fi.intel.com> (raw)
In-Reply-To: <DU2PR04MB8822BB1DCFB37AA96D0C55158C702@DU2PR04MB8822.eurprd04.prod.outlook.com>
On Fri, Jan 19, 2024 at 08:18:51AM +0000, Xu Yang wrote:
> Hi,
>
> >
> > On Thu, Jan 18, 2024 at 03:52:52PM +0000, Xu Yang wrote:
> > > I've tried your suggestion and it appears to be working fine. Now I'm not sure if
> > > the module get/put parts should be removed or to fix the NULL pointer issue. I'm
> > > working on this issue, so I have time to fix it. I think if first way is taken, the status
> > > of usb_role_switch device should be updated when it's registered/unregisterd. Or
> > > other issues will occur since the user doesn't know the change of usb_role_switch
> > > device.
> >
> > These really are questions for Heikki, not me. Can you at least show us
> > the patch you've been testing?
>
> I have a simple test based on below changes:
>
> diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c
> index ae41578bd014..d55a5d8d4fc4 100644
> --- a/drivers/usb/roles/class.c
> +++ b/drivers/usb/roles/class.c
> @@ -20,6 +20,7 @@ static const struct class role_class = {
>
> struct usb_role_switch {
> struct device dev;
> + struct module *module;
> struct mutex lock; /* device lock*/
> enum usb_role role;
>
> @@ -135,7 +136,7 @@ struct usb_role_switch *usb_role_switch_get(struct device *dev)
> usb_role_switch_match);
>
> if (!IS_ERR_OR_NULL(sw))
> - WARN_ON(!try_module_get(sw->dev.parent->driver->owner));
> + WARN_ON(!try_module_get(sw->module));
>
> return sw;
> }
> @@ -157,7 +158,7 @@ struct usb_role_switch *fwnode_usb_role_switch_get(struct fwnode_handle *fwnode)
> sw = fwnode_connection_find_match(fwnode, "usb-role-switch",
> NULL, usb_role_switch_match);
> if (!IS_ERR_OR_NULL(sw))
> - WARN_ON(!try_module_get(sw->dev.parent->driver->owner));
> + WARN_ON(!try_module_get(sw->module));
>
> return sw;
> }
> @@ -172,7 +173,7 @@ EXPORT_SYMBOL_GPL(fwnode_usb_role_switch_get);
> void usb_role_switch_put(struct usb_role_switch *sw)
> {
> if (!IS_ERR_OR_NULL(sw)) {
> - module_put(sw->dev.parent->driver->owner);
> + module_put(sw->module);
> put_device(&sw->dev);
> }
> }
> @@ -189,15 +190,18 @@ struct usb_role_switch *
> usb_role_switch_find_by_fwnode(const struct fwnode_handle *fwnode)
> {
> struct device *dev;
> + struct usb_role_switch *sw = NULL;
>
> if (!fwnode)
> return NULL;
>
> dev = class_find_device_by_fwnode(&role_class, fwnode);
> - if (dev)
> - WARN_ON(!try_module_get(dev->parent->driver->owner));
> + if(dev) {
> + sw = to_role_switch(dev);
> + WARN_ON(!try_module_get(sw->module));
> + }
>
> - return dev ? to_role_switch(dev) : NULL;
> + return sw;
> }
> EXPORT_SYMBOL_GPL(usb_role_switch_find_by_fwnode);
>
> @@ -339,6 +343,7 @@ usb_role_switch_register(struct device *parent,
> sw->get = desc->get;
>
> sw->dev.parent = parent;
> + sw->module = parent->driver->owner;
> sw->dev.fwnode = desc->fwnode;
> sw->dev.class = &role_class;
> sw->dev.type = &usb_role_dev_type;
This looks good to me.
--
heikki
next prev parent reply other threads:[~2024-01-19 13:22 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-12 8:01 [PATCH] usb: roles: try to get/put all relevant modules Xu Yang
2024-01-12 8:24 ` Greg KH
2024-01-12 8:26 ` Greg KH
2024-01-12 9:28 ` [EXT] " Xu Yang
2024-01-12 13:52 ` Greg KH
2024-01-15 3:02 ` Xu Yang
2024-01-15 6:54 ` Greg KH
2024-01-15 16:31 ` Alan Stern
2024-01-16 5:44 ` Xu Yang
2024-01-16 16:03 ` Alan Stern
2024-01-17 5:57 ` Xu Yang
2024-01-18 9:22 ` Heikki Krogerus
2024-01-18 9:53 ` Greg KH
2024-01-18 12:38 ` Heikki Krogerus
2024-01-18 14:54 ` Greg KH
2024-01-18 15:28 ` Alan Stern
2024-01-18 15:52 ` Xu Yang
2024-01-18 19:21 ` Alan Stern
2024-01-19 8:18 ` Xu Yang
2024-01-19 13:21 ` Heikki Krogerus [this message]
2024-01-19 14:53 ` Alan Stern
2024-01-19 11:13 ` Xu Yang
2024-01-19 15:00 ` Alan Stern
2024-01-19 15:23 ` Xu Yang
2024-01-19 16:22 ` Alan Stern
2024-01-22 2:32 ` Xu Yang
2024-01-18 15:29 ` Xu Yang
2024-01-14 12:25 ` Greg KH
2024-01-14 23:06 ` kernel test robot
2024-01-15 2:12 ` kernel test robot
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=Zapz8T2f8P+6+C24@kuha.fi.intel.com \
--to=heikki.krogerus@linux.intel.com \
--cc=benjamin.tissoires@redhat.com \
--cc=gregkh@linuxfoundation.org \
--cc=hdegoede@redhat.com \
--cc=ivan.orlov0322@gmail.com \
--cc=jun.li@nxp.com \
--cc=linux-imx@nxp.com \
--cc=linux-usb@vger.kernel.org \
--cc=stern@rowland.harvard.edu \
--cc=xu.yang_2@nxp.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