diff mbox series

[v3,2/3] usb: ulpi: Call of_node_put correctly

Message ID 20220127190004.1446909-3-sean.anderson@seco.com
State New
Headers show
Series usb: ulpi: Fixes and debugfs support | expand

Commit Message

Sean Anderson Jan. 27, 2022, 7 p.m. UTC
of_node_put should always be called on device nodes gotten from
of_get_*. Additionally, it should only be called after there are no
remaining users. To address the first issue, call of_node_put if later
steps in ulpi_register fail. To address the latter, call put_device if
device_register fails, which will call ulpi_dev_release if necessary.

Fixes: ef6a7bcfb01c ("usb: ulpi: Support device discovery via DT")
Signed-off-by: Sean Anderson <sean.anderson@seco.com>
---

Changes in v3:
- Add Fixes tag
- Call put_device if device_register fails

Changes in v2:
- New

 drivers/usb/common/ulpi.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Heikki Krogerus Jan. 31, 2022, 11:08 a.m. UTC | #1
On Thu, Jan 27, 2022 at 02:00:03PM -0500, Sean Anderson wrote:
> of_node_put should always be called on device nodes gotten from
> of_get_*. Additionally, it should only be called after there are no
> remaining users. To address the first issue, call of_node_put if later
> steps in ulpi_register fail. To address the latter, call put_device if
> device_register fails, which will call ulpi_dev_release if necessary.
> 
> Fixes: ef6a7bcfb01c ("usb: ulpi: Support device discovery via DT")
> Signed-off-by: Sean Anderson <sean.anderson@seco.com>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
> 
> Changes in v3:
> - Add Fixes tag
> - Call put_device if device_register fails
> 
> Changes in v2:
> - New
> 
>  drivers/usb/common/ulpi.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/common/ulpi.c b/drivers/usb/common/ulpi.c
> index c90a1ab705a3..dedcb749a02f 100644
> --- a/drivers/usb/common/ulpi.c
> +++ b/drivers/usb/common/ulpi.c
> @@ -245,12 +245,16 @@ static int ulpi_register(struct device *dev, struct ulpi *ulpi)
>  		return ret;
>  
>  	ret = ulpi_read_id(ulpi);
> -	if (ret)
> +	if (ret) {
> +		of_node_put(ulpi->dev.of_node);
>  		return ret;
> +	}
>  
>  	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);
> -- 
> 2.25.1

thanks,
diff mbox series

Patch

diff --git a/drivers/usb/common/ulpi.c b/drivers/usb/common/ulpi.c
index c90a1ab705a3..dedcb749a02f 100644
--- a/drivers/usb/common/ulpi.c
+++ b/drivers/usb/common/ulpi.c
@@ -245,12 +245,16 @@  static int ulpi_register(struct device *dev, struct ulpi *ulpi)
 		return ret;
 
 	ret = ulpi_read_id(ulpi);
-	if (ret)
+	if (ret) {
+		of_node_put(ulpi->dev.of_node);
 		return ret;
+	}
 
 	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);