From: "Michael Walle" <mwalle@kernel.org>
To: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>
Cc: <linux-usb@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] usb: gadget: f_acm: make bInterfaceProtocol configurable
Date: Wed, 31 Jul 2024 22:11:00 +0200 [thread overview]
Message-ID: <D33ZXDVKL33Z.1SDI3XDBGZIO8@kernel.org> (raw)
In-Reply-To: <2024073145-treat-winnings-3bb4@gregkh>
Hi Greg,
On Wed Jul 31, 2024 at 11:16 AM CEST, Greg Kroah-Hartman wrote:
> On Wed, Jul 31, 2024 at 10:57:04AM +0200, Michael Walle wrote:
> > Hi Greg,
> >
> > On Wed Jul 31, 2024 at 10:32 AM CEST, Greg Kroah-Hartman wrote:
> > > On Tue, Jul 30, 2024 at 09:43:37PM +0200, Michael Walle wrote:
> > > > struct f_serial_opts {
> > > > struct usb_function_instance func_inst;
> > > > u8 port_num;
> > > > + u8 protocol;
> > > > +
> > > > + struct mutex lock;
> > > > + int refcnt;
> > >
> > > Attempting to "roll your own" reference count is almost never a good
> > > idea. If you really need one, please use the proper in-kernel apis for
> > > this. But you need to justify it as well, I didn't see why this was
> > > needed at all.
> >
> > Honestly, I couldn't grok all that usb gadget magic, so I've looked
> > at similar gadgets and took that from there:
> > grep refcnt drivers/usb/gadget/function/ -r
> >
> > They are all doing the same, so maybe that code is old or didn't use
> > the proper APIs back then.
>
> It's old code, please do things properly.
Sorry, I have to come back to this. What do you have in mind?
The mutex is needed in any case to protect the members of
f_serial_ops from concurrent access between the .bind() and the
configfs write.
Which leaves us with refcnt. I don't think refcount_t is suitable
here. For example, refcount_inc() will warn if you increment from
0; which makes sense for resource reference counting. But doesn't
make sense in this case; there is no resource handling or freeing if
the refcnt is 0. It just prohibits the write to the configfs
attribute if refcnt != 0, that is, there is at least one instance of
the gadget function.
Maybe I should just rename "refcnt" to "users" and add a comment to
the mutex what it will protect.
What do you think?
-michael
prev parent reply other threads:[~2024-07-31 20:11 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-30 19:43 [PATCH] usb: gadget: f_acm: make bInterfaceProtocol configurable Michael Walle
2024-07-31 8:32 ` Greg Kroah-Hartman
2024-07-31 8:57 ` Michael Walle
2024-07-31 9:16 ` Greg Kroah-Hartman
2024-07-31 20:11 ` Michael Walle [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=D33ZXDVKL33Z.1SDI3XDBGZIO8@kernel.org \
--to=mwalle@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.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.