From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752088AbbGWFC7 (ORCPT ); Thu, 23 Jul 2015 01:02:59 -0400 Received: from devils.ext.ti.com ([198.47.26.153]:47310 "EHLO devils.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750702AbbGWFCu (ORCPT ); Thu, 23 Jul 2015 01:02:50 -0400 Date: Thu, 23 Jul 2015 00:02:40 -0500 From: Felipe Balbi To: Greg Kroah-Hartman CC: Felipe Balbi , Heikki Krogerus , ChengYi He , , Subject: Re: [PATCH] usb: ulpi: call put_device if device_register fails Message-ID: <20150723050240.GA18430@saruman.tx.rr.com> Reply-To: References: <20150618171236.GA18007@chengyihe-ThinkCentre-M82> <20150623105738.GD1296@kuha.fi.intel.com> <20150722213934.GA10425@kroah.com> <20150723020440.GB16806@saruman.tx.rr.com> <20150723031446.GA10588@kroah.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="IJpNTDwzlM2Ie8A6" Content-Disposition: inline In-Reply-To: <20150723031446.GA10588@kroah.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --IJpNTDwzlM2Ie8A6 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi, On Wed, Jul 22, 2015 at 08:14:46PM -0700, Greg Kroah-Hartman wrote: > On Wed, Jul 22, 2015 at 09:04:40PM -0500, Felipe Balbi wrote: > > On Wed, Jul 22, 2015 at 02:39:34PM -0700, Greg Kroah-Hartman wrote: > > > On Tue, Jun 23, 2015 at 01:57:38PM +0300, Heikki Krogerus wrote: > > > > On Fri, Jun 19, 2015 at 01:12:36AM +0800, ChengYi He wrote: > > > > > put_device is required to release the last reference to the devic= e. > > > > >=20 > > > > > Signed-off-by: ChengYi He > > > > > --- > > > > > drivers/usb/common/ulpi.c | 4 +++- > > > > > 1 file changed, 3 insertions(+), 1 deletion(-) > > > > >=20 > > > > > diff --git a/drivers/usb/common/ulpi.c b/drivers/usb/common/ulpi.c > > > > > index 0e6f968..bd25bdb 100644 > > > > > --- a/drivers/usb/common/ulpi.c > > > > > +++ b/drivers/usb/common/ulpi.c > > > > > @@ -184,8 +184,10 @@ static int ulpi_register(struct device *dev,= struct ulpi *ulpi) > > > > > request_module("ulpi:v%04xp%04x", ulpi->id.vendor, ulpi->id.pro= duct); > > > > > =20 > > > > > ret =3D device_register(&ulpi->dev); > > > > > - if (ret) > > > > > + if (ret) { > > > > > + put_device(&ulpi->dev); > > > >=20 > > > > If device_register returns failure, put_device has already been > > > > called. Check device_add in drivers/base/core.c. > > >=20 > > > Yes, please read the function, which says: > > > * NOTE: _Never_ directly free @dev after calling this function, even > > > * if it returned an error! Always use put_device() to give up your > > > * reference instead. > > >=20 > > > But, the problem is that the ulpi core doesn't "own" that struct devi= ce. > > > It comes from elsewhere. It comes from somewhere deep down in the dw3 > > > core, which is where I lost the path. Something needs to be fixed in > > > dwc3_probe() to properly clean up the device if it fails, which is not > > > happening right now. > > >=20 > > > So this patch would actually cause much bigger problems than fixing > > > anything, so it's wrong, but for a different reason than you are talk= ing > > > about here. > > >=20 > > > And ugh, the ulpi and dwc code binding together, what a mess, horrid.= =2E. > >=20 > > any suggestions ? DWC *is* the one implementing the bus. If there's a > > better way, we can certainly shuffle code around. >=20 > As dwc is the only thing using the bus, why is it drivers/usb/core/ ? musb also has a SW-accessible ULPI bus. And, IIRC, so does DWC2 ;-) > And the error path here is broken, the bus should be creating the device > (i.e. no subsystem should ever be registering a device it did not > create), so that it can properly clean things up when stuff goes wrong. >=20 > The whole subsys_init() is also a bad feeling that it's not architected > correctly, that shouldn't be needed, which is why I never took that > patch. Just noticed it came in through yours, I wanted it "broken" so > it would be fixed "properly" and not papered over like this. I just felt it would be better to 'fix' it for the -rc until it can be fixed *properly*. A follow up fix should incur no visible changes to drivers anyway. --=20 balbi --IJpNTDwzlM2Ie8A6 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJVsHVwAAoJEIaOsuA1yqREUZcQALYrUpQciQm55DLArZ55wXvE tibmheguIKVT7w7G8/4YwN4epLSZfq9QblMfLwarOlnVP5v0ifV3hUSQGGXw7Py6 omRGqvMEUOT96l7sScfotW3nSMoWyyR+x3wK46JEq0sAHevjnUvmsRy9F7LDr98y vBfVmfmRAREL1TmtGabhIBGrMOxb1wZwf4/3a1uwBWqHVbFUAR+RG9qlhqRz7ocp BYU973ctW199ZuTDQ99wd+2SNVLZGNj+Xo/AuuHrwURuOv2E45z8OuQSE/oUwnt2 HKxq9ajhPmzKS6Zf0bE4eGiHy2tr5XkhPeUw3QiVKFet/v7RIMciUaxabdK3oCWN hafXe71Z7HVKUj7Y5QkpVyQGayFvabmkD0s8+UC8CXzqNtgUqHnFiXINU1GtOpeM SWzkL6RFqd2DzdDYgPD7cKiFXcsQ1yv1LLKOwLxefyr57aGZc5n6tk3sxz99tEGv RHWFF+093sJKbQN70HrXaVs/cy7fOQ8vMRoAXkIJxTESQZ7fbcG1RTHl/fKJkk/n kLEQBdhhjUM+UrDj27HMMLRMQdCxgYAi33zD/+7JyZgeZoU3q2u0Pr3oRTJPOK9d 8UQHX7WudB39EKvlTLgUw4wDXdW5JNSqY/6cVoimkSDIShO2N/QpLV/x317vMw7D CGnojowFV++HdMUvW7iI =rgq6 -----END PGP SIGNATURE----- --IJpNTDwzlM2Ie8A6--