tee: optee: add missing of_node_put after of_device_is_available [Linux 5.0]

tee: optee: add missing of_node_put after of_device_is_available [Linux 5.0]

This Linux kernel change "tee: optee: add missing of_node_put after of_device_is_available" is included in the Linux 5.0 release. This change is authored by Julia Lawall <Julia.Lawall [at] lip6.fr> on Sat Feb 23 14:20:36 2019 +0100. The commit for this change in Linux stable tree is c7c0d8d (patch).

tee: optee: add missing of_node_put after of_device_is_available

Add an of_node_put when a tested device node is not available.

The semantic patch that fixes this problem is as follows
(http://coccinelle.lip6.fr):

// <smpl>
@@
identifier f;
local idexpression e;
expression x;
@@

e = f(...);
... when != of_node_put(e)
    when != x = e
    when != e = x
    when any
if (<+...of_device_is_available(e)...+>) {
  ... when != of_node_put(e)
(
  return e;
|
+ of_node_put(e);
  return ...;
)
}
// </smpl>

Fixes: db878f76b9ff ("tee: optee: take DT status property into account")
Signed-off-by: Julia Lawall <[email protected]>
Signed-off-by: Jens Wiklander <[email protected]>

There are 4 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 drivers/tee/optee/core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c
index e5efce3..947f9b2 100644
--- a/drivers/tee/optee/core.c
+++ b/drivers/tee/optee/core.c
@@ -699,8 +699,10 @@ static int __init optee_driver_init(void)
        return -ENODEV;

    np = of_find_matching_node(fw_np, optee_match);
-   if (!np || !of_device_is_available(np))
+   if (!np || !of_device_is_available(np)) {
+       of_node_put(np);
        return -ENODEV;
+   }

    optee = optee_probe(np);
    of_node_put(np);

Leave a Reply

Your email address will not be published. Required fields are marked *