Skip to contentSkip to conversation

jailhouse: Hold reference returned from of_find_xxx API

PATCH Juergen Gross via Virtualization 4 participants 7 messages Sep 15, 2022 – Sep 16, 2022 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

Juergen Gross via Virtualization

author Reviewed-by Juergen Gross
#1 lore raw
In reply to a message not in the archive
Quoted 7 lines · Liang He

In jailhouse_paravirt(), we should hold the reference returned from of_find_compatible_node() which has increased the refcount and then call of_node_put() with it when done.

Fixes 63338a38db95 ("jailhouse: Provide detection for non-x86 systems")

Juergen

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#2 lore raw
In reply to a message not in the archive

[ Adding author and reviewers of commit 63338a38db95 ]

Quoted 17 lines · Liang He

In jailhouse_paravirt(), we should hold the reference returned from of_find_compatible_node() which has increased the refcount and then call of_node_put() with it when done.

Fixes 63338a38db95 ("jailhouse: Provide detection for non-x86 systems")
---
 include/linux/hypervisor.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
include/linux/hypervisor.h +0 -0
index 9efbc54e35e5..7fe1e8c6211c 100644
@@ -27,7 +27,11 @@ static inline void hypervisor_pin_vcpu(int cpu)
 

include/linux/hypervisor.h static inline void hypervisor_pin_vcpu(int cpu) · line 36

Quoted 10 lines
include/linux/hypervisor.h +5 -1
 static inline bool jailhouse_paravirt(void)
 {
-	return of_find_compatible_node(NULL, NULL, "jailhouse,cell");
+	struct device_node *np = of_find_compatible_node(NULL, NULL, "jailhouse,cell");
+
+	of_node_put(np);
+
+	return np;
 }
 

Thank you for the fix, but returning a pointer from a function with a bool return type looks odd. Can we also fix that up please?

Regards,
Srivatsa
VMware Photon OS
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#3 lore raw
Quoted 21 lines · Srivatsa S. Bhat

[ Adding author and reviewers of commit 63338a38db95 ]

Quoted 17 lines · Liang He

In jailhouse_paravirt(), we should hold the reference returned from of_find_compatible_node() which has increased the refcount and then call of_node_put() with it when done.

Fixes 63338a38db95 ("jailhouse: Provide detection for non-x86 systems")
---
 include/linux/hypervisor.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
include/linux/hypervisor.h +0 -0
index 9efbc54e35e5..7fe1e8c6211c 100644
@@ -27,7 +27,11 @@ static inline void hypervisor_pin_vcpu(int cpu)
 
Quoted 14 lines

include/linux/hypervisor.h static inline void hypervisor_pin_vcpu(int cpu) · line 36

Quoted 10 lines
include/linux/hypervisor.h +5 -1
 static inline bool jailhouse_paravirt(void)
 {
-	return of_find_compatible_node(NULL, NULL, "jailhouse,cell");
+	struct device_node *np = of_find_compatible_node(NULL, NULL, "jailhouse,cell");
+
+	of_node_put(np);
+
+	return np;
 }
 

Thank you for the fix, but returning a pointer from a function with a bool return type looks odd. Can we also fix that up please?

Thanks for your review, how about following patch:

- return of_find_compatible_node(NULL, NULL, "jailhouse,cell");
+ struct device_node *np = of_find_compatible_node(NULL, NULL, "jailhouse,cell");
+
+ of_node_put(np);
+
+ return (np==NULL);

Quoted 4 lines

Regards,
Srivatsa
VMware Photon OS

#4 lore raw
Quoted 2 lines · Liang He
Quoted 1 line · Srivatsa S. Bhat

On 9/14/22 7:23 PM, Liang He wrote:

..

Quoted 16 lines
Quoted 4 lines
Quoted 4 lines

static inline bool jailhouse_paravirt(void)
{

(quoted diff) +1 -1
-    return of_find_compatible_node(NULL, NULL, "jailhouse,cell");
+    struct device_node *np = of_find_compatible_node(NULL, NULL, "jailhouse,cell");
Quoted 9 lines

Review

Quoted 5 lines
(quoted diff) +4 -0
+
+    of_node_put(np);
+
+    return np;
 }

Thank you for the fix, but returning a pointer from a function with a bool return type looks odd. Can we also fix that up please?

Thanks for your review, how about following patch:

Review

Quoted 6 lines
(quoted diff) +5 -1
-       return of_find_compatible_node(NULL, NULL, "jailhouse,cell");
+       struct device_node *np = of_find_compatible_node(NULL, NULL, "jailhouse,cell");
+
+       of_node_put(np);
+
+       return (np==NULL);

This will be opposite to the above. Perhaps you wanted

return !!np;

Also possible (but why?)

return np ? true : false;

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#5 lore raw
Quoted 22 lines · Andy Shevchenko
Quoted 2 lines · Liang He
Quoted 1 line · Srivatsa S. Bhat

On 9/14/22 7:23 PM, Liang He wrote:

..

Quoted 16 lines
Quoted 4 lines
Quoted 4 lines

static inline bool jailhouse_paravirt(void)
{

(quoted diff) +1 -1
-    return of_find_compatible_node(NULL, NULL, "jailhouse,cell");
+    struct device_node *np = of_find_compatible_node(NULL, NULL, "jailhouse,cell");
Quoted 9 lines

Review

Quoted 5 lines
(quoted diff) +4 -0
+
+    of_node_put(np);
+
+    return np;
 }

Thank you for the fix, but returning a pointer from a function with a bool return type looks odd. Can we also fix that up please?

Thanks for your review, how about following patch:

Quoted 9 lines

Review

Quoted 6 lines
(quoted diff) +5 -1
-       return of_find_compatible_node(NULL, NULL, "jailhouse,cell");
+       struct device_node *np = of_find_compatible_node(NULL, NULL, "jailhouse,cell");
+
+       of_node_put(np);
+
+       return (np==NULL);

This will be opposite to the above. Perhaps you wanted

Sorry, I wanted to use 'np!=NULL'

Quoted 7 lines

return !!np;

Also possible (but why?)

return np ? true : false;

So, can I chose 'return np?true: false;' as the final patch?

Thanks,

Liang

Quoted 2 lines

-- >With Best Regards,
Andy Shevchenko

#6 lore raw
Quoted 4 lines · Liang He
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Liang He
Quoted 1 line · Srivatsa S. Bhat

On 9/14/22 7:23 PM, Liang He wrote:

...

Quoted 26 lines
Quoted 15 lines
Quoted 15 lines
Quoted 4 lines
Quoted 4 lines

static inline bool jailhouse_paravirt(void)
{

(quoted diff) +1 -1
-    return of_find_compatible_node(NULL, NULL, "jailhouse,cell");
+    struct device_node *np = of_find_compatible_node(NULL, NULL, "jailhouse,cell");
Quoted 8 lines

Review

Quoted 5 lines
(quoted diff) +4 -0
+
+    of_node_put(np);
+
+    return np;
 }

Thank you for the fix, but returning a pointer from a function with a bool return type looks odd. Can we also fix that up please?

Thanks for your review, how about following patch:

Quoted 8 lines

Review

Quoted 6 lines
(quoted diff) +5 -1
-       return of_find_compatible_node(NULL, NULL, "jailhouse,cell");
+       struct device_node *np = of_find_compatible_node(NULL, NULL, "jailhouse,cell");
+
+       of_node_put(np);
+
+       return (np==NULL);

This will be opposite to the above. Perhaps you wanted

Sorry, I wanted to use 'np!=NULL'

Quoted 7 lines
Quoted 5 lines

return !!np;

Also possible (but why?)

return np ? true : false;

So, can I chose 'return np?true: false;' as the final patch?

Of course you can, it's up to the maintainer(s) what to accept.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#7 lore raw
Quoted 36 lines · Andy Shevchenko
Quoted 4 lines · Liang He
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Liang He
Quoted 1 line · Srivatsa S. Bhat

On 9/14/22 7:23 PM, Liang He wrote:

...

Quoted 28 lines
Quoted 15 lines
Quoted 15 lines
Quoted 4 lines
Quoted 4 lines

static inline bool jailhouse_paravirt(void)
{

(quoted diff) +1 -1
-    return of_find_compatible_node(NULL, NULL, "jailhouse,cell");
+    struct device_node *np = of_find_compatible_node(NULL, NULL, "jailhouse,cell");
Quoted 8 lines

Review

Quoted 5 lines
(quoted diff) +4 -0
+
+    of_node_put(np);
+
+    return np;
 }

Thank you for the fix, but returning a pointer from a function with a bool return type looks odd. Can we also fix that up please?

Thanks for your review, how about following patch:

Quoted 8 lines

Review

Quoted 6 lines
(quoted diff) +5 -1
-       return of_find_compatible_node(NULL, NULL, "jailhouse,cell");
+       struct device_node *np = of_find_compatible_node(NULL, NULL, "jailhouse,cell");
+
+       of_node_put(np);
+
+       return (np==NULL);

This will be opposite to the above. Perhaps you wanted

Sorry, I wanted to use 'np!=NULL'

Quoted 2 lines

return !!np;

Quoted 11 lines
Quoted 5 lines
Quoted 3 lines

Also possible (but why?)

return np ? true : false;

So, can I chose 'return np?true: false;' as the final patch?

Of course you can, it's up to the maintainer(s) what to accept.

Signature · 2 lines
With Best Regards,
Andy Shevchenko

Thanks, I will do it now.