From: Mark Brown <broonie@kernel.org>
To: Greg KH <gregkh@linuxfoundation.org>
Cc: Baolin Wang <baolin.wang@linaro.org>,
balbi@ti.com, linux-kernel@vger.kernel.org,
peter.chen@freescale.com, sojka@merica.cz,
stern@rowland.harvard.edu, andreas@gaisler.com,
linux-usb@vger.kernel.org,
device-mainlining@lists.linuxfoundation.org
Subject: Re: [PATCH 1/2] gadget: Introduce the usb charger framework
Date: Thu, 6 Aug 2015 19:30:29 +0100 [thread overview]
Message-ID: <20150806183029.GE20873@sirena.org.uk> (raw)
In-Reply-To: <20150806163905.GA6907@kroah.com>
[-- Attachment #1: Type: text/plain, Size: 1511 bytes --]
On Thu, Aug 06, 2015 at 09:39:05AM -0700, Greg KH wrote:
> On Thu, Aug 06, 2015 at 03:03:48PM +0800, Baolin Wang wrote:
> > +static void usb_charger_release(struct device *dev)
> > +{
> > + struct usb_charger *uchger = dev_get_drvdata(dev);
> > + if (!atomic_dec_and_test(&uchger->count)) {
> > + dev_err(dev, "The usb charger is still in use\n");
> Why is the "count" different from the reference count? You shouldn't be
> in this function if the reference count is not 0, so tie your "user"
> count to this one. Having two different reference counts is a nightmare
> and almost impossible to get right. And a huge red flag that the design
> is incorrect.
> > + return;
> You can't "fail" a release call, so you just leaked memory all over the
> floor here :(
Indeed. I did discuss this with Baolin off list but I'd missed the
dynamic allocation of devices for some reason.
> > + mutex_lock(&usb_charger_list_lock);
> > + list_for_each_entry(tmp, &usb_charger_list, entry) {
> > + if (!(strcmp(tmp->name, uchger->name))) {
> > + mutex_unlock(&usb_charger_list_lock);
> > + ret = -EEXIST;
> > + goto out;
> > + }
> > + }
> > + list_add_tail(&uchger->entry, &usb_charger_list);
> Why do you need a separate list? This subsystem's bus structure should
> own that list of devices, no need for a separate one (again, a huge red
> flag that the design is not correct.)
Right, if we dynamically allocate a device per charger then the lifetime
issues should go away and we get a list for free.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
next prev parent reply other threads:[~2015-08-06 18:31 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-06 7:03 [PATCH 0/2] Introduce usb charger framework to deal with the usb gadget power negotation Baolin Wang
2015-08-06 7:03 ` [PATCH 1/2] gadget: Introduce the usb charger framework Baolin Wang
2015-08-06 16:39 ` Greg KH
2015-08-06 18:30 ` Mark Brown [this message]
2015-08-07 5:48 ` Baolin Wang
2015-08-07 5:41 ` Peter Chen
2015-08-07 8:33 ` Baolin Wang
2015-08-06 7:03 ` [PATCH 2/2] gadget: Support for " Baolin Wang
2015-08-07 5:45 ` Peter Chen
2015-08-07 8:46 ` Baolin Wang
2015-08-07 9:07 ` Peter Chen
2015-08-07 9:22 ` Baolin Wang
2015-08-07 17:53 ` Greg KH
2015-08-08 6:23 ` Baolin Wang
2015-08-06 16:21 ` [PATCH 0/2] Introduce usb charger framework to deal with the usb gadget power negotation Felipe Balbi
2015-08-06 16:39 ` Greg KH
2015-08-07 5:34 ` Peter Chen
2015-08-07 8:19 ` Baolin Wang
2015-08-07 8:31 ` Peter Chen
2015-08-07 8:47 ` Baolin Wang
2015-08-07 17:52 ` Greg KH
2015-08-08 6:22 ` Baolin Wang
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=20150806183029.GE20873@sirena.org.uk \
--to=broonie@kernel.org \
--cc=andreas@gaisler.com \
--cc=balbi@ti.com \
--cc=baolin.wang@linaro.org \
--cc=device-mainlining@lists.linuxfoundation.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=peter.chen@freescale.com \
--cc=sojka@merica.cz \
--cc=stern@rowland.harvard.edu \
/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).