mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 RESEND] phy: Fix error handling in tegra_xusb_port_init
@ 2025-03-03  7:27 Ma Ke
  2025-03-03 15:51 ` Thierry Reding
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Ma Ke @ 2025-03-03  7:27 UTC (permalink / raw)
  To: jckuo, vkoul, kishon, thierry.reding, jonathanh
  Cc: linux-phy, linux-tegra, linux-kernel, akpm, Ma Ke, stable

If device_add() fails, do not use device_unregister() for error
handling. device_unregister() consists two functions: device_del() and
put_device(). device_unregister() should only be called after
device_add() succeeded because device_del() undoes what device_add()
does if successful. Change device_unregister() to put_device() call
before returning from the function.

As comment of device_add() says, 'if device_add() succeeds, you should
call device_del() when you want to get rid of it. If device_add() has
not succeeded, use only put_device() to drop the reference count'.

Found by code review.

Cc: stable@vger.kernel.org
Fixes: 53d2a715c240 ("phy: Add Tegra XUSB pad controller support")
Signed-off-by: Ma Ke <make24@iscas.ac.cn>
---
Changes in v2:
- modified the bug description as suggestions.
---
 drivers/phy/tegra/xusb.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/phy/tegra/xusb.c b/drivers/phy/tegra/xusb.c
index 79d4814d758d..c89df95aa6ca 100644
--- a/drivers/phy/tegra/xusb.c
+++ b/drivers/phy/tegra/xusb.c
@@ -548,16 +548,16 @@ static int tegra_xusb_port_init(struct tegra_xusb_port *port,
 
 	err = dev_set_name(&port->dev, "%s-%u", name, index);
 	if (err < 0)
-		goto unregister;
+		goto put_device;
 
 	err = device_add(&port->dev);
 	if (err < 0)
-		goto unregister;
+		goto put_device;
 
 	return 0;
 
-unregister:
-	device_unregister(&port->dev);
+put_device:
+	put_device(&port->dev);
 	return err;
 }
 
-- 
2.25.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 RESEND] phy: Fix error handling in tegra_xusb_port_init
  2025-03-03  7:27 [PATCH v2 RESEND] phy: Fix error handling in tegra_xusb_port_init Ma Ke
@ 2025-03-03 15:51 ` Thierry Reding
  2025-05-08 22:17 ` Thierry Reding
  2025-05-14 11:31 ` Vinod Koul
  2 siblings, 0 replies; 8+ messages in thread
From: Thierry Reding @ 2025-03-03 15:51 UTC (permalink / raw)
  To: Ma Ke
  Cc: jckuo, vkoul, kishon, jonathanh, linux-phy, linux-tegra,
	linux-kernel, akpm, stable

[-- Attachment #1: Type: text/plain, Size: 1068 bytes --]

On Mon, Mar 03, 2025 at 03:27:39PM +0800, Ma Ke wrote:
> If device_add() fails, do not use device_unregister() for error
> handling. device_unregister() consists two functions: device_del() and
> put_device(). device_unregister() should only be called after
> device_add() succeeded because device_del() undoes what device_add()
> does if successful. Change device_unregister() to put_device() call
> before returning from the function.
> 
> As comment of device_add() says, 'if device_add() succeeds, you should
> call device_del() when you want to get rid of it. If device_add() has
> not succeeded, use only put_device() to drop the reference count'.
> 
> Found by code review.
> 
> Cc: stable@vger.kernel.org
> Fixes: 53d2a715c240 ("phy: Add Tegra XUSB pad controller support")
> Signed-off-by: Ma Ke <make24@iscas.ac.cn>
> ---
> Changes in v2:
> - modified the bug description as suggestions.
> ---
>  drivers/phy/tegra/xusb.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)

Acked-by: Thierry Reding <treding@nvidia.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 RESEND] phy: Fix error handling in tegra_xusb_port_init
  2025-03-03  7:27 [PATCH v2 RESEND] phy: Fix error handling in tegra_xusb_port_init Ma Ke
  2025-03-03 15:51 ` Thierry Reding
@ 2025-05-08 22:17 ` Thierry Reding
  2025-05-14 11:31 ` Vinod Koul
  2 siblings, 0 replies; 8+ messages in thread
From: Thierry Reding @ 2025-05-08 22:17 UTC (permalink / raw)
  To: Ma Ke
  Cc: jckuo, vkoul, kishon, jonathanh, linux-phy, linux-tegra,
	linux-kernel, akpm, stable

[-- Attachment #1: Type: text/plain, Size: 1117 bytes --]

On Mon, Mar 03, 2025 at 03:27:39PM +0800, Ma Ke wrote:
> If device_add() fails, do not use device_unregister() for error
> handling. device_unregister() consists two functions: device_del() and
> put_device(). device_unregister() should only be called after
> device_add() succeeded because device_del() undoes what device_add()
> does if successful. Change device_unregister() to put_device() call
> before returning from the function.
> 
> As comment of device_add() says, 'if device_add() succeeds, you should
> call device_del() when you want to get rid of it. If device_add() has
> not succeeded, use only put_device() to drop the reference count'.
> 
> Found by code review.
> 
> Cc: stable@vger.kernel.org
> Fixes: 53d2a715c240 ("phy: Add Tegra XUSB pad controller support")
> Signed-off-by: Ma Ke <make24@iscas.ac.cn>
> ---
> Changes in v2:
> - modified the bug description as suggestions.
> ---
>  drivers/phy/tegra/xusb.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)

Vinod, Kishon,

looks like this was never picked up. Can you apply this?

Thanks,
Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 RESEND] phy: Fix error handling in tegra_xusb_port_init
  2025-03-03  7:27 [PATCH v2 RESEND] phy: Fix error handling in tegra_xusb_port_init Ma Ke
  2025-03-03 15:51 ` Thierry Reding
  2025-05-08 22:17 ` Thierry Reding
@ 2025-05-14 11:31 ` Vinod Koul
  2 siblings, 0 replies; 8+ messages in thread
From: Vinod Koul @ 2025-05-14 11:31 UTC (permalink / raw)
  To: jckuo, kishon, thierry.reding, jonathanh, Ma Ke
  Cc: linux-phy, linux-tegra, linux-kernel, akpm, stable


On Mon, 03 Mar 2025 15:27:39 +0800, Ma Ke wrote:
> If device_add() fails, do not use device_unregister() for error
> handling. device_unregister() consists two functions: device_del() and
> put_device(). device_unregister() should only be called after
> device_add() succeeded because device_del() undoes what device_add()
> does if successful. Change device_unregister() to put_device() call
> before returning from the function.
> 
> [...]

Applied, thanks!

[1/1] phy: Fix error handling in tegra_xusb_port_init
      commit: b2ea5f49580c0762d17d80d8083cb89bc3acf74f

Best regards,
-- 
~Vinod



^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 RESEND] phy: Fix error handling in tegra_xusb_port_init
@ 2025-02-25  2:31 Ma Ke
  0 siblings, 0 replies; 8+ messages in thread
From: Ma Ke @ 2025-02-25  2:31 UTC (permalink / raw)
  To: jckuo, vkoul, kishon, thierry.reding, jonathanh
  Cc: linux-phy, linux-tegra, linux-kernel, akpm, Ma Ke, stable

If device_add() fails, do not use device_unregister() for error
handling. device_unregister() consists two functions: device_del() and
put_device(). device_unregister() should only be called after
device_add() succeeded because device_del() undoes what device_add()
does if successful. Change device_unregister() to put_device() call
before returning from the function.

As comment of device_add() says, 'if device_add() succeeds, you should
call device_del() when you want to get rid of it. If device_add() has
not succeeded, use only put_device() to drop the reference count'.

Found by code review.

Cc: stable@vger.kernel.org
Fixes: 53d2a715c240 ("phy: Add Tegra XUSB pad controller support")
Signed-off-by: Ma Ke <make24@iscas.ac.cn>
---
Changes in v2:
- modified the bug description as suggestions.
---
 drivers/phy/tegra/xusb.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/phy/tegra/xusb.c b/drivers/phy/tegra/xusb.c
index 79d4814d758d..c89df95aa6ca 100644
--- a/drivers/phy/tegra/xusb.c
+++ b/drivers/phy/tegra/xusb.c
@@ -548,16 +548,16 @@ static int tegra_xusb_port_init(struct tegra_xusb_port *port,
 
 	err = dev_set_name(&port->dev, "%s-%u", name, index);
 	if (err < 0)
-		goto unregister;
+		goto put_device;
 
 	err = device_add(&port->dev);
 	if (err < 0)
-		goto unregister;
+		goto put_device;
 
 	return 0;
 
-unregister:
-	device_unregister(&port->dev);
+put_device:
+	put_device(&port->dev);
 	return err;
 }
 
-- 
2.25.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 RESEND] phy: Fix error handling in tegra_xusb_port_init
@ 2025-02-17  1:06 Ma Ke
  0 siblings, 0 replies; 8+ messages in thread
From: Ma Ke @ 2025-02-17  1:06 UTC (permalink / raw)
  To: jckuo, vkoul, kishon, thierry.reding, jonathanh
  Cc: linux-phy, linux-tegra, linux-kernel, Ma Ke, stable

If device_add() fails, do not use device_unregister() for error
handling. device_unregister() consists two functions: device_del() and
put_device(). device_unregister() should only be called after
device_add() succeeded because device_del() undoes what device_add()
does if successful. Change device_unregister() to put_device() call
before returning from the function.

As comment of device_add() says, 'if device_add() succeeds, you should
call device_del() when you want to get rid of it. If device_add() has
not succeeded, use only put_device() to drop the reference count'.

Found by code review.

Cc: stable@vger.kernel.org
Fixes: 53d2a715c240 ("phy: Add Tegra XUSB pad controller support")
Signed-off-by: Ma Ke <make24@iscas.ac.cn>
---
Changes in v2:
- modified the bug description as suggestions.
---
 drivers/phy/tegra/xusb.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/phy/tegra/xusb.c b/drivers/phy/tegra/xusb.c
index 79d4814d758d..c89df95aa6ca 100644
--- a/drivers/phy/tegra/xusb.c
+++ b/drivers/phy/tegra/xusb.c
@@ -548,16 +548,16 @@ static int tegra_xusb_port_init(struct tegra_xusb_port *port,
 
 	err = dev_set_name(&port->dev, "%s-%u", name, index);
 	if (err < 0)
-		goto unregister;
+		goto put_device;
 
 	err = device_add(&port->dev);
 	if (err < 0)
-		goto unregister;
+		goto put_device;
 
 	return 0;
 
-unregister:
-	device_unregister(&port->dev);
+put_device:
+	put_device(&port->dev);
 	return err;
 }
 
-- 
2.25.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 RESEND] phy: Fix error handling in tegra_xusb_port_init
@ 2025-01-19  7:10 Ma Ke
  0 siblings, 0 replies; 8+ messages in thread
From: Ma Ke @ 2025-01-19  7:10 UTC (permalink / raw)
  To: jckuo, vkoul, kishon, thierry.reding, jonathanh
  Cc: linux-phy, linux-tegra, linux-kernel, Ma Ke, stable

If device_add() fails, do not use device_unregister() for error
handling. device_unregister() consists two functions: device_del() and
put_device(). device_unregister() should only be called after
device_add() succeeded because device_del() undoes what device_add()
does if successful. Change device_unregister() to put_device() call
before returning from the function.

As comment of device_add() says, 'if device_add() succeeds, you should
call device_del() when you want to get rid of it. If device_add() has
not succeeded, use only put_device() to drop the reference count'.

Found by code review.

Cc: stable@vger.kernel.org
Fixes: 53d2a715c240 ("phy: Add Tegra XUSB pad controller support")
Signed-off-by: Ma Ke <make24@iscas.ac.cn>
---
Changes in v2:
- modified the bug description as suggestions.
---
 drivers/phy/tegra/xusb.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/phy/tegra/xusb.c b/drivers/phy/tegra/xusb.c
index 79d4814d758d..c89df95aa6ca 100644
--- a/drivers/phy/tegra/xusb.c
+++ b/drivers/phy/tegra/xusb.c
@@ -548,16 +548,16 @@ static int tegra_xusb_port_init(struct tegra_xusb_port *port,
 
 	err = dev_set_name(&port->dev, "%s-%u", name, index);
 	if (err < 0)
-		goto unregister;
+		goto put_device;
 
 	err = device_add(&port->dev);
 	if (err < 0)
-		goto unregister;
+		goto put_device;
 
 	return 0;
 
-unregister:
-	device_unregister(&port->dev);
+put_device:
+	put_device(&port->dev);
 	return err;
 }
 
-- 
2.25.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 RESEND] phy: Fix error handling in tegra_xusb_port_init
@ 2025-01-19  6:56 Ma Ke
  0 siblings, 0 replies; 8+ messages in thread
From: Ma Ke @ 2025-01-19  6:56 UTC (permalink / raw)
  To: jckuo, vkoul, kishon, thierry.reding, jonathanh
  Cc: linux-phy, linux-tegra, linux-kernel, Ma Ke

If device_add() fails, do not use device_unregister() for error
handling. device_unregister() consists two functions: device_del() and
put_device(). device_unregister() should only be called after
device_add() succeeded because device_del() undoes what device_add()
does if successful. Change device_unregister() to put_device() call
before returning from the function.

As comment of device_add() says, 'if device_add() succeeds, you should
call device_del() when you want to get rid of it. If device_add() has
not succeeded, use only put_device() to drop the reference count'.

Found by code review.

Signed-off-by: Ma Ke <make24@iscas.ac.cn>
---
 drivers/phy/tegra/xusb.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/phy/tegra/xusb.c b/drivers/phy/tegra/xusb.c
index 79d4814d758d..c89df95aa6ca 100644
--- a/drivers/phy/tegra/xusb.c
+++ b/drivers/phy/tegra/xusb.c
@@ -548,16 +548,16 @@ static int tegra_xusb_port_init(struct tegra_xusb_port *port,
 
 	err = dev_set_name(&port->dev, "%s-%u", name, index);
 	if (err < 0)
-		goto unregister;
+		goto put_device;
 
 	err = device_add(&port->dev);
 	if (err < 0)
-		goto unregister;
+		goto put_device;
 
 	return 0;
 
-unregister:
-	device_unregister(&port->dev);
+put_device:
+	put_device(&port->dev);
 	return err;
 }
 
-- 
2.25.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-05-14 11:31 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-03  7:27 [PATCH v2 RESEND] phy: Fix error handling in tegra_xusb_port_init Ma Ke
2025-03-03 15:51 ` Thierry Reding
2025-05-08 22:17 ` Thierry Reding
2025-05-14 11:31 ` Vinod Koul
  -- strict thread matches above, loose matches on Subject: below --
2025-02-25  2:31 Ma Ke
2025-02-17  1:06 Ma Ke
2025-01-19  7:10 Ma Ke
2025-01-19  6:56 Ma Ke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®