[v2,1/2] cdx: call of_node_put() on error path

Message ID 2e66efc4-a13a-4774-8c9d-763455fe4834@moroto.mountain
State New
Headers
Series [v2,1/2] cdx: call of_node_put() on error path |

Commit Message

Dan Carpenter Jan. 2, 2024, 1:10 p.m. UTC
  Add a missing call to of_node_put(np) on error.

There was a second error path where "np" was NULL, but that situation is
impossible.  The for_each_compatible_node() loop iterator is always
non-NULL.  Just deleted that error path.

Fixes: 54b406e10f03 ("cdx: Remove cdx controller list from cdx bus system")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
v2: Christophe JAILLET pointed out this bug so I added this patch
    to the patchset.

 drivers/cdx/cdx.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
  

Comments

Gangurde, Abhijit Jan. 4, 2024, 9:06 a.m. UTC | #1
[AMD Official Use Only - General]

> Add a missing call to of_node_put(np) on error.
>
> There was a second error path where "np" was NULL, but that situation is
> impossible.  The for_each_compatible_node() loop iterator is always
> non-NULL.  Just deleted that error path.
>
> Fixes: 54b406e10f03 ("cdx: Remove cdx controller list from cdx bus system")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---
Acked-by: Abhijit Gangurde <abhijit.gangurde@amd.com>

Thanks,
Abhijit
  

Patch

diff --git a/drivers/cdx/cdx.c b/drivers/cdx/cdx.c
index d84d153078d7..40035dd2e299 100644
--- a/drivers/cdx/cdx.c
+++ b/drivers/cdx/cdx.c
@@ -572,12 +572,11 @@  static ssize_t rescan_store(const struct bus_type *bus,
 
 	/* Rescan all the devices */
 	for_each_compatible_node(np, NULL, compat_node_name) {
-		if (!np)
-			return -EINVAL;
-
 		pd = of_find_device_by_node(np);
-		if (!pd)
+		if (!pd) {
+			of_node_put(np);
 			return -EINVAL;
+		}
 
 		cdx = platform_get_drvdata(pd);
 		if (cdx && cdx->controller_registered && cdx->ops->scan)