devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Chunfeng Yun <chunfeng.yun@mediatek.com>
Cc: Felipe Balbi <felipe.balbi@linux.intel.com>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	linux-usb@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org
Subject: Re: [PATCH v4] usb: create usb_debug_root for gadget only
Date: Tue, 4 Jun 2019 11:14:43 +0200	[thread overview]
Message-ID: <20190604091443.GA458@kroah.com> (raw)
In-Reply-To: <1559638754.8487.71.camel@mhfsdcap03>

On Tue, Jun 04, 2019 at 04:59:14PM +0800, Chunfeng Yun wrote:
> On Tue, 2019-06-04 at 09:37 +0200, Greg Kroah-Hartman wrote:
> > On Tue, Jun 04, 2019 at 03:34:07PM +0800, Chunfeng Yun wrote:
> > > When CONFIG_USB is not set, and CONFIG_USB_GADGET is set,
> > > there is an issue, e.g.:
> > > 
> > > drivers/usb/mtu3/mtu3_debugfs.o: in function 'ssusb_debugfs_create_root':
> > > mtu3_debugfs.c:(.text+0xba3): undefined reference to 'usb_debug_root'
> > > 
> > > usb_debug_root is currently only built when host is supported
> > > (CONFIG_USB is set), for convenience, we also want it created when
> > > gadget only is enabled, this patch try to support it.
> > > 
> > > Reported-by: Randy Dunlap <rdunlap@infradead.org>
> > > Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
> > > ---
> > > v4:
> > >   move common API into common.c suggested by Felipe
> > > 
> > > v3:
> > >   1. still create usb_debug_root for gadget only
> > >   2. abandon mtu3's change
> > >   3. drop acked-by Randy
> > > 
> > > v2(resend): add acked-by Randy
> > > 
> > > v1: fix mtu3's build error, replace usb_debug_root by NULL;
> > > ---
> > >  drivers/usb/common/common.c   | 26 ++++++++++++++++++++++++++
> > >  drivers/usb/core/usb.c        | 16 ++++------------
> > >  drivers/usb/gadget/udc/core.c |  3 +++
> > >  include/linux/usb.h           |  2 ++
> > >  4 files changed, 35 insertions(+), 12 deletions(-)
> > > 
> > > diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c
> > > index 18f5dcf58b0d..c52e9c9f58ec 100644
> > > --- a/drivers/usb/common/common.c
> > > +++ b/drivers/usb/common/common.c
> > > @@ -15,6 +15,7 @@
> > >  #include <linux/usb/of.h>
> > >  #include <linux/usb/otg.h>
> > >  #include <linux/of_platform.h>
> > > +#include <linux/debugfs.h>
> > >  
> > >  static const char *const ep_type_names[] = {
> > >  	[USB_ENDPOINT_XFER_CONTROL] = "ctrl",
> > > @@ -139,6 +140,31 @@ enum usb_dr_mode usb_get_dr_mode(struct device *dev)
> > >  }
> > >  EXPORT_SYMBOL_GPL(usb_get_dr_mode);
> > >  
> > > +struct dentry *usb_debug_root;
> > > +EXPORT_SYMBOL_GPL(usb_debug_root);
> > > +
> > > +static atomic_t usb_debug_root_refcnt = ATOMIC_INIT(0);
> > 
> > Ick, no.
> > 
> > > +
> > > +struct dentry *usb_debugfs_init(void)
> > > +{
> > > +	if (!usb_debug_root)
> > > +		usb_debug_root = debugfs_create_dir("usb", NULL);
> > > +
> > > +	atomic_inc(&usb_debug_root_refcnt);
> > > +
> > > +	return usb_debug_root;
> > > +}
> > > +EXPORT_SYMBOL_GPL(usb_debugfs_init);
> > > +
> > > +void usb_debugfs_cleanup(void)
> > > +{
> > > +	if (atomic_dec_and_test(&usb_debug_root_refcnt)) {
> > > +		debugfs_remove_recursive(usb_debug_root);
> > > +		usb_debug_root = NULL;
> > > +	}
> > > +}
> > > +EXPORT_SYMBOL_GPL(usb_debugfs_cleanup);
> > 
> > Only remove the debugfs subdir if the usbcore module is removed. 
> Both usbcore module and gadget module will use this "usb" subdir now.
> Gadget module may still use it when remove usbcore module.

Did you try to remove the usb-common module with the udc gadget module
remaining loaded with this change in place?  I think you will find that
it is impossible given that the udc gadget module now depends on a
symbol in the usb-common code.

So again, just use the module reference counting logic to drive this
functionality, don't create an atomic variable that duplicates the
logic we already have in place today.

thanks,

greg k-h

      reply	other threads:[~2019-06-04  9:14 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-04  7:34 [PATCH v4] usb: create usb_debug_root for gadget only Chunfeng Yun
2019-06-04  7:37 ` Greg Kroah-Hartman
2019-06-04  7:47   ` Felipe Balbi
2019-06-04  8:24     ` Greg Kroah-Hartman
2019-06-04  9:13       ` Chunfeng Yun
2019-06-04  9:28       ` Greg Kroah-Hartman
2019-06-04  8:59   ` Chunfeng Yun
2019-06-04  9:14     ` Greg Kroah-Hartman [this message]

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=20190604091443.GA458@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=chunfeng.yun@mediatek.com \
    --cc=devicetree@vger.kernel.org \
    --cc=felipe.balbi@linux.intel.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=matthias.bgg@gmail.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).