linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] phy: tegra: xusb: Fix NULL vs IS_ERR_OR_NULL checking
@ 2021-12-12  6:50 Miaoqian Lin
  2021-12-12 14:31 ` Dmitry Osipenko
  0 siblings, 1 reply; 5+ messages in thread
From: Miaoqian Lin @ 2021-12-12  6:50 UTC (permalink / raw)
  Cc: linmq006, JC Kuo, Kishon Vijay Abraham I, Vinod Koul,
	Thierry Reding, Jonathan Hunter, linux-phy, linux-tegra,
	linux-kernel

The tegra_xusb_find_port_node() function may return error pointer when
kasprintf() return NULL. Using IS_ERR_OR_NULL to check the return value
of tegra_xusb_find_port_node() to catch this.

Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
 drivers/phy/tegra/xusb.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/phy/tegra/xusb.c b/drivers/phy/tegra/xusb.c
index 963de5913e50..52c2f85c67c3 100644
--- a/drivers/phy/tegra/xusb.c
+++ b/drivers/phy/tegra/xusb.c
@@ -472,7 +472,7 @@ tegra_xusb_find_port(struct tegra_xusb_padctl *padctl, const char *type,
 	struct device_node *np;
 
 	np = tegra_xusb_find_port_node(padctl, type, index);
-	if (!np)
+	if (IS_ERR_OR_NULL(np))
 		return NULL;
 
 	list_for_each_entry(port, &padctl->ports, list) {
@@ -763,7 +763,7 @@ static int tegra_xusb_add_usb2_port(struct tegra_xusb_padctl *padctl,
 	 * marked as disabled there is no reason to register it.
 	 */
 	np = tegra_xusb_find_port_node(padctl, "usb2", index);
-	if (!np || !of_device_is_available(np))
+	if (IS_ERR_OR_NULL(np) || !of_device_is_available(np))
 		goto out;
 
 	usb2 = kzalloc(sizeof(*usb2), GFP_KERNEL);
@@ -829,7 +829,7 @@ static int tegra_xusb_add_ulpi_port(struct tegra_xusb_padctl *padctl,
 	int err = 0;
 
 	np = tegra_xusb_find_port_node(padctl, "ulpi", index);
-	if (!np || !of_device_is_available(np))
+	if (IS_ERR_OR_NULL(np) || !of_device_is_available(np))
 		goto out;
 
 	ulpi = kzalloc(sizeof(*ulpi), GFP_KERNEL);
@@ -884,7 +884,7 @@ static int tegra_xusb_add_hsic_port(struct tegra_xusb_padctl *padctl,
 	int err = 0;
 
 	np = tegra_xusb_find_port_node(padctl, "hsic", index);
-	if (!np || !of_device_is_available(np))
+	if (IS_ERR_OR_NULL(np) || !of_device_is_available(np))
 		goto out;
 
 	hsic = kzalloc(sizeof(*hsic), GFP_KERNEL);
@@ -970,7 +970,7 @@ static int tegra_xusb_add_usb3_port(struct tegra_xusb_padctl *padctl,
 	 * hence return 0 instead of an error to allow ports to be optional.
 	 */
 	np = tegra_xusb_find_port_node(padctl, "usb3", index);
-	if (!np || !of_device_is_available(np))
+	if (IS_ERR_OR_NULL(np) || !of_device_is_available(np))
 		goto out;
 
 	usb3 = kzalloc(sizeof(*usb3), GFP_KERNEL);
@@ -1035,7 +1035,7 @@ static int tegra_xusb_find_unused_usb3_port(struct tegra_xusb_padctl *padctl)
 
 	for (i = 0; i < padctl->soc->ports.usb3.count; i++) {
 		np = tegra_xusb_find_port_node(padctl, "usb3", i);
-		if (!np || !of_device_is_available(np))
+		if (IS_ERR_OR_NULL(np) || !of_device_is_available(np))
 			return i;
 	}
 
-- 
2.17.1


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

* Re: [PATCH] phy: tegra: xusb: Fix NULL vs IS_ERR_OR_NULL checking
  2021-12-12  6:50 [PATCH] phy: tegra: xusb: Fix NULL vs IS_ERR_OR_NULL checking Miaoqian Lin
@ 2021-12-12 14:31 ` Dmitry Osipenko
  2021-12-13  2:05   ` [PATCH v2] phy: tegra: xusb: Fix return value of tegra_xusb_find_port_node function Miaoqian Lin
  0 siblings, 1 reply; 5+ messages in thread
From: Dmitry Osipenko @ 2021-12-12 14:31 UTC (permalink / raw)
  To: Miaoqian Lin
  Cc: JC Kuo, Kishon Vijay Abraham I, Vinod Koul, Thierry Reding,
	Jonathan Hunter, linux-phy, linux-tegra, linux-kernel

12.12.2021 09:50, Miaoqian Lin пишет:
> The tegra_xusb_find_port_node() function may return error pointer when
> kasprintf() return NULL. Using IS_ERR_OR_NULL to check the return value
> of tegra_xusb_find_port_node() to catch this.
> 
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> ---
>  drivers/phy/tegra/xusb.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)

Instead of changing the 6 lines and making code less readable, you could
change a single line.

diff --git a/drivers/phy/tegra/xusb.c b/drivers/phy/tegra/xusb.c
index 963de5913e50..aa5237eacd29 100644
--- a/drivers/phy/tegra/xusb.c
+++ b/drivers/phy/tegra/xusb.c
@@ -455,7 +455,7 @@ tegra_xusb_find_port_node(struct tegra_xusb_padctl
*padctl, const char *type,
        name = kasprintf(GFP_KERNEL, "%s-%u", type, index);
        if (!name) {
                of_node_put(ports);
-               return ERR_PTR(-ENOMEM);
+               return NULL;
        }
        np = of_get_child_by_name(ports, name);
        kfree(name);

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

* [PATCH v2] phy: tegra: xusb: Fix return value of tegra_xusb_find_port_node function
  2021-12-12 14:31 ` Dmitry Osipenko
@ 2021-12-13  2:05   ` Miaoqian Lin
  2021-12-13 10:24     ` Thierry Reding
  2021-12-14  7:37     ` Vinod Koul
  0 siblings, 2 replies; 5+ messages in thread
From: Miaoqian Lin @ 2021-12-13  2:05 UTC (permalink / raw)
  To: digetx
  Cc: jckuo, jonathanh, kishon, linmq006, linux-kernel, linux-phy,
	linux-tegra, thierry.reding, vkoul

callers of tegra_xusb_find_port_node() function only do NULL checking for
the return value. return NULL instead of ERR_PTR(-ENOMEM) to keep
consistent.

Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
 drivers/phy/tegra/xusb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/phy/tegra/xusb.c b/drivers/phy/tegra/xusb.c
index 963de5913e50..aa5237eacd29 100644
--- a/drivers/phy/tegra/xusb.c
+++ b/drivers/phy/tegra/xusb.c
@@ -455,7 +455,7 @@ tegra_xusb_find_port_node(struct tegra_xusb_padctl *padctl, const char *type,
 	name = kasprintf(GFP_KERNEL, "%s-%u", type, index);
 	if (!name) {
 		of_node_put(ports);
-		return ERR_PTR(-ENOMEM);
+		return NULL;
 	}
 	np = of_get_child_by_name(ports, name);
 	kfree(name);
-- 
2.17.1


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

* Re: [PATCH v2] phy: tegra: xusb: Fix return value of tegra_xusb_find_port_node function
  2021-12-13  2:05   ` [PATCH v2] phy: tegra: xusb: Fix return value of tegra_xusb_find_port_node function Miaoqian Lin
@ 2021-12-13 10:24     ` Thierry Reding
  2021-12-14  7:37     ` Vinod Koul
  1 sibling, 0 replies; 5+ messages in thread
From: Thierry Reding @ 2021-12-13 10:24 UTC (permalink / raw)
  To: Miaoqian Lin
  Cc: digetx, jckuo, jonathanh, kishon, linux-kernel, linux-phy,
	linux-tegra, vkoul

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

On Mon, Dec 13, 2021 at 02:05:07AM +0000, Miaoqian Lin wrote:
> callers of tegra_xusb_find_port_node() function only do NULL checking for
> the return value. return NULL instead of ERR_PTR(-ENOMEM) to keep
> consistent.
> 
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> ---
>  drivers/phy/tegra/xusb.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

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

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

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

* Re: [PATCH v2] phy: tegra: xusb: Fix return value of tegra_xusb_find_port_node function
  2021-12-13  2:05   ` [PATCH v2] phy: tegra: xusb: Fix return value of tegra_xusb_find_port_node function Miaoqian Lin
  2021-12-13 10:24     ` Thierry Reding
@ 2021-12-14  7:37     ` Vinod Koul
  1 sibling, 0 replies; 5+ messages in thread
From: Vinod Koul @ 2021-12-14  7:37 UTC (permalink / raw)
  To: Miaoqian Lin
  Cc: digetx, jckuo, jonathanh, kishon, linux-kernel, linux-phy,
	linux-tegra, thierry.reding

On 13-12-21, 02:05, Miaoqian Lin wrote:
> callers of tegra_xusb_find_port_node() function only do NULL checking for
> the return value. return NULL instead of ERR_PTR(-ENOMEM) to keep
> consistent.

Applied, thanks

-- 
~Vinod

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

end of thread, other threads:[~2021-12-14  7:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-12  6:50 [PATCH] phy: tegra: xusb: Fix NULL vs IS_ERR_OR_NULL checking Miaoqian Lin
2021-12-12 14:31 ` Dmitry Osipenko
2021-12-13  2:05   ` [PATCH v2] phy: tegra: xusb: Fix return value of tegra_xusb_find_port_node function Miaoqian Lin
2021-12-13 10:24     ` Thierry Reding
2021-12-14  7:37     ` Vinod Koul

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).