lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Thu, 6 Aug 2015 19:30:29 +0100
From:	Mark Brown <broonie@...nel.org>
To:	Greg KH <gregkh@...uxfoundation.org>
Cc:	Baolin Wang <baolin.wang@...aro.org>, balbi@...com,
	linux-kernel@...r.kernel.org, peter.chen@...escale.com,
	sojka@...ica.cz, stern@...land.harvard.edu, andreas@...sler.com,
	linux-usb@...r.kernel.org,
	device-mainlining@...ts.linuxfoundation.org
Subject: Re: [PATCH 1/2] gadget: Introduce the usb charger framework

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.

Download attachment "signature.asc" of type "application/pgp-signature" (474 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ