usb: ulpi: call put_device if device_register fails
PATCH 1/1 usb: ulpi: call put_device if device_register fails
put_device is required to release the last reference to the device.
--- drivers/usb/common/ulpi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/usb/common/ulpi.c +3 -1
@@ -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.product); ret =device_register (&ulpi->dev); -if (ret) +if (ret) { +put_device (&ulpi->dev);return ret; + }dev_dbg (&ulpi->dev,"registered ULPI PHY: vendor %04x, product %04x\n" , ulpi->id.vendor, ulpi->id.product);
Signature · 1 line
1.9.1
Heikki Krogerus
maintainerQuoted 12 lines · ChengYi He
put_deviceis required to release the last reference to the device.Signed-off-by ChengYi He <[email protected]>--- drivers/usb/common/ulpi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/usb/common/ulpi.c +0
-0
drivers/usb/common/ulpi.c static int ulpi_register(struct device *dev, struct ulpi *ulpi) · line 188
Quoted 6 lines
drivers/usb/common/ulpi.c +2
-1@@ -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.product); ret =device_register (&ulpi->dev); -if (ret) +if (ret) { +put_device (&ulpi->dev);
If device_register returns failure, put_device has already been called. Check device_add in drivers/base/core.c.
Thanks,
Signature · 1 line
heikki
Greg Kroah-Hartman
maintainerQuoted 15 lines · Heikki Krogerus
Quoted 14 lines · ChengYi He
put_deviceis required to release the last reference to the device.Signed-off-by ChengYi He <[email protected]>--- drivers/usb/common/ulpi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/usb/common/ulpi.c +0
-0@@ -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.product);
Quoted 7 lines
drivers/usb/common/ulpi.c static int ulpi_register(struct device *dev, struct ulpi *ulpi) · line 188
Quoted 4 lines
drivers/usb/common/ulpi.c +2
-1ret =device_register (&ulpi->dev); -if (ret) +if (ret) { +put_device (&ulpi->dev);If
device_registerreturns failure,put_devicehas already been called. Checkdevice_addindrivers/base/core.c.
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.
But, the problem is that the ulpi core doesn't "own" that struct device. 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.
So this patch would actually cause much bigger problems than fixing anything, so it's wrong, but for a different reason than you are talking about here.
And ugh, the ulpi and dwc code binding together, what a mess, horrid...
greg k-h
Quoted 35 lines · Greg Kroah-Hartman
Quoted 15 lines · Heikki Krogerus
Quoted 14 lines · ChengYi He
put_deviceis required to release the last reference to the device.Signed-off-by ChengYi He <[email protected]>--- drivers/usb/common/ulpi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/usb/common/ulpi.c +0
-0@@ -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.product);Quoted 7 lines
drivers/usb/common/ulpi.c static int ulpi_register(struct device *dev, struct ulpi *ulpi) · line 188
Quoted 4 lines
drivers/usb/common/ulpi.c +2
-1ret =device_register (&ulpi->dev); -if (ret) +if (ret) { +put_device (&ulpi->dev);If
device_registerreturns failure,put_devicehas already been called. Checkdevice_addindrivers/base/core.c.Yes, please read the function, which says:
* NOTE: _Never_ directly free @dev after calling this function, even
* if it returned an error! Always useput_device()to give up your
* reference instead.But, the problem is that the ulpi core doesn't "own" that struct device. 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.
Quoted 5 lines
So this patch would actually cause much bigger problems than fixing anything, so it's wrong, but for a different reason than you are talking about here.
And ugh, the ulpi and dwc code binding together, what a mess, horrid...
any suggestions ? DWC *is* the one implementing the bus. If there's a better way, we can certainly shuffle code around.
Signature · 1 line
balbi
Greg Kroah-Hartman
maintainerQuoted 36 lines · Felipe Balbi
Quoted 35 lines · Greg Kroah-Hartman
Quoted 15 lines · Heikki Krogerus
Quoted 14 lines · ChengYi He
put_deviceis required to release the last reference to the device.Signed-off-by ChengYi He <[email protected]>--- drivers/usb/common/ulpi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/usb/common/ulpi.c +0
-0@@ -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.product);Quoted 7 lines
drivers/usb/common/ulpi.c static int ulpi_register(struct device *dev, struct ulpi *ulpi) · line 188
Quoted 4 lines
drivers/usb/common/ulpi.c +2
-1ret =device_register (&ulpi->dev); -if (ret) +if (ret) { +put_device (&ulpi->dev);If
device_registerreturns failure,put_devicehas already been called. Checkdevice_addindrivers/base/core.c.Yes, please read the function, which says:
* NOTE: _Never_ directly free @dev after calling this function, even
* if it returned an error! Always useput_device()to give up your
* reference instead.But, the problem is that the ulpi core doesn't "own" that struct device. 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.
Quoted 8 lines
Quoted 5 lines
So this patch would actually cause much bigger problems than fixing anything, so it's wrong, but for a different reason than you are talking about here.
And ugh, the ulpi and dwc code binding together, what a mess, horrid...
any suggestions ? DWC *is* the one implementing the bus. If there's a better way, we can certainly shuffle code around.
As dwc is the only thing using the bus, why is it drivers/usb/core/ ?
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.
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.
thanks,
greg k-h
Hi,
Quoted 41 lines · Greg Kroah-Hartman
Quoted 40 lines · Felipe Balbi
Quoted 39 lines · Greg Kroah-Hartman
Quoted 15 lines · Heikki Krogerus
Quoted 14 lines · ChengYi He
put_deviceis required to release the last reference to the device.Signed-off-by ChengYi He <[email protected]>--- drivers/usb/common/ulpi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/usb/common/ulpi.c +0
-0@@ -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.product);Quoted 7 lines
drivers/usb/common/ulpi.c static int ulpi_register(struct device *dev, struct ulpi *ulpi) · line 188
Quoted 4 lines
drivers/usb/common/ulpi.c +2
-1ret =device_register (&ulpi->dev); -if (ret) +if (ret) { +put_device (&ulpi->dev);If
device_registerreturns failure,put_devicehas already been called. Checkdevice_addindrivers/base/core.c.Yes, please read the function, which says:
* NOTE: _Never_ directly free @dev after calling this function, even
* if it returned an error! Always useput_device()to give up your
* reference instead.But, the problem is that the ulpi core doesn't "own" that struct device. 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.So this patch would actually cause much bigger problems than fixing anything, so it's wrong, but for a different reason than you are talking about here.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
And ugh, the ulpi and dwc code binding together, what a mess, horrid...
any suggestions ? DWC *is* the one implementing the bus. If there's a better way, we can certainly shuffle code around.
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 ;-)
Quoted 8 lines
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.
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.
Signature · 1 line
balbi
Greg Kroah-Hartman
maintainerQuoted 44 lines · Felipe Balbi
Hi,
Quoted 41 lines · Greg Kroah-Hartman
Quoted 40 lines · Felipe Balbi
Quoted 39 lines · Greg Kroah-Hartman
Quoted 15 lines · Heikki Krogerus
Quoted 14 lines · ChengYi He
put_deviceis required to release the last reference to the device.Signed-off-by ChengYi He <[email protected]>--- drivers/usb/common/ulpi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/usb/common/ulpi.c +0
-0@@ -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.product);Quoted 7 lines
drivers/usb/common/ulpi.c static int ulpi_register(struct device *dev, struct ulpi *ulpi) · line 188
Quoted 4 lines
drivers/usb/common/ulpi.c +2
-1ret =device_register (&ulpi->dev); -if (ret) +if (ret) { +put_device (&ulpi->dev);If
device_registerreturns failure,put_devicehas already been called. Checkdevice_addindrivers/base/core.c.Yes, please read the function, which says:
* NOTE: _Never_ directly free @dev after calling this function, even
* if it returned an error! Always useput_device()to give up your
* reference instead.But, the problem is that the ulpi core doesn't "own" that struct device. 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.So this patch would actually cause much bigger problems than fixing anything, so it's wrong, but for a different reason than you are talking about here.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
And ugh, the ulpi and dwc code binding together, what a mess, horrid...
any suggestions ? DWC *is* the one implementing the bus. If there's a better way, we can certainly shuffle code around.
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 ;-)
But they aren't calling ulpi_register(), so how can they be using this code?
Quoted 4 lines
Quoted 4 lines
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.
Quoted 8 lines
Quoted 4 lines
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.
I don't like fixes like this because no one now has any pressure to fix it "properly". Are you doing that work? If not, who is?
thanks,
greg k-h
Hi,
Quoted 50 lines · Greg Kroah-Hartman
Quoted 49 lines · Felipe Balbi
Hi,
Quoted 46 lines · Greg Kroah-Hartman
Quoted 44 lines · Felipe Balbi
Quoted 35 lines · Greg Kroah-Hartman
Quoted 15 lines · Heikki Krogerus
Quoted 14 lines · ChengYi He
put_deviceis required to release the last reference to the device.Signed-off-by ChengYi He <[email protected]>--- drivers/usb/common/ulpi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/usb/common/ulpi.c +0
-0@@ -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.product);Quoted 7 lines
drivers/usb/common/ulpi.c static int ulpi_register(struct device *dev, struct ulpi *ulpi) · line 188
Quoted 4 lines
drivers/usb/common/ulpi.c +2
-1ret =device_register (&ulpi->dev); -if (ret) +if (ret) { +put_device (&ulpi->dev);If
device_registerreturns failure,put_devicehas already been called. Checkdevice_addindrivers/base/core.c.Yes, please read the function, which says:
* NOTE: _Never_ directly free @dev after calling this function, even
* if it returned an error! Always useput_device()to give up your
* reference instead.But, the problem is that the ulpi core doesn't "own" that struct device. 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.Quoted 5 lines
So this patch would actually cause much bigger problems than fixing anything, so it's wrong, but for a different reason than you are talking about here.
And ugh, the ulpi and dwc code binding together, what a mess, horrid...
any suggestions ? DWC *is* the one implementing the bus. If there's a better way, we can certainly shuffle code around.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
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 ;-)
But they aren't calling
ulpi_register(), so how can they be using this code?
the thing was just added :-) It didn't exist before.
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
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.
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.
Quoted 6 lines
Quoted 3 lines
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.
I don't like fixes like this because no one now has any pressure to fix it "properly". Are you doing that work? If not, who is?
Heikki is author, I'd expect him to fix it up. We can also revert the fix if you prefer, I'm totally fine with that.
Signature · 1 line
balbi
Greg Kroah-Hartman
maintainerQuoted 5 lines · Felipe Balbi
Quoted 2 lines
I don't like fixes like this because no one now has any pressure to fix it "properly". Are you doing that work? If not, who is?
Heikki is author, I'd expect him to fix it up. We can also revert the fix if you prefer, I'm totally fine with that.
Let's leave it alone for now and see what happens...