* [PATCH v2 0/3] powerpc/kernel: Simplify rtas_initialize()
@ 2017-01-23 22:49 Gavin Shan
2017-01-23 22:49 ` [PATCH v2 1/3] powerpc/kernel: Remove nested if statements in rtas_initialize() Gavin Shan
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Gavin Shan @ 2017-01-23 22:49 UTC (permalink / raw)
To: linuxppc-dev; +Cc: mpe, Gavin Shan
This simplifies rtas_initialize(), no functional changes introduced:
* PATCH[1/3] removes the unnecessary nested if statements.
* PATCH[2/3] uses of_property_read_u32() instead of converting the
property's data to target in CPU endian.
* PATCH[3/3] decreases RTAS device-tree node's refcount in error path.
v2:
* Set RTAS device-tree node to NULL if its base, or size, or both of
them can't be found.
Gavin Shan (3):
powerpc/kernel: Remove nested if statements in rtas_initialize()
powerpc/kernel: Use of_property_read_u32() in rtas_initialize()
powerpc/kernel: Fix unbalanced refcount on RTAS device node
arch/powerpc/kernel/rtas.c | 32 +++++++++++++++-----------------
1 file changed, 15 insertions(+), 17 deletions(-)
--
2.7.4
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/3] powerpc/kernel: Remove nested if statements in rtas_initialize()
2017-01-23 22:49 [PATCH v2 0/3] powerpc/kernel: Simplify rtas_initialize() Gavin Shan
@ 2017-01-23 22:49 ` Gavin Shan
2017-01-27 0:40 ` [v2, " Michael Ellerman
2017-01-23 22:49 ` [PATCH v2 2/3] powerpc/kernel: Use of_property_read_u32() " Gavin Shan
2017-01-23 22:49 ` [PATCH v2 3/3] powerpc/kernel: Fix unbalanced refcount on RTAS device node Gavin Shan
2 siblings, 1 reply; 5+ messages in thread
From: Gavin Shan @ 2017-01-23 22:49 UTC (permalink / raw)
To: linuxppc-dev; +Cc: mpe, Gavin Shan
This removes the unnecessary nested if statements in function
rtas_initialize(), to simplify the code. No functional changes
introduced.
Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
---
v2: Set device node to NULL when base or size isn't found
---
arch/powerpc/kernel/rtas.c | 33 ++++++++++++++++-----------------
1 file changed, 16 insertions(+), 17 deletions(-)
diff --git a/arch/powerpc/kernel/rtas.c b/arch/powerpc/kernel/rtas.c
index 112cc3b..9759dcb 100644
--- a/arch/powerpc/kernel/rtas.c
+++ b/arch/powerpc/kernel/rtas.c
@@ -1145,31 +1145,30 @@ asmlinkage int ppc_rtas(struct rtas_args __user *uargs)
void __init rtas_initialize(void)
{
unsigned long rtas_region = RTAS_INSTANTIATE_MAX;
+ const __be32 *basep, *entryp, *sizep;
/* Get RTAS dev node and fill up our "rtas" structure with infos
* about it.
*/
rtas.dev = of_find_node_by_name(NULL, "rtas");
- if (rtas.dev) {
- const __be32 *basep, *entryp, *sizep;
-
- basep = of_get_property(rtas.dev, "linux,rtas-base", NULL);
- sizep = of_get_property(rtas.dev, "rtas-size", NULL);
- if (basep != NULL && sizep != NULL) {
- rtas.base = __be32_to_cpu(*basep);
- rtas.size = __be32_to_cpu(*sizep);
- entryp = of_get_property(rtas.dev,
- "linux,rtas-entry", NULL);
- if (entryp == NULL) /* Ugh */
- rtas.entry = rtas.base;
- else
- rtas.entry = __be32_to_cpu(*entryp);
- } else
- rtas.dev = NULL;
- }
if (!rtas.dev)
return;
+ basep = of_get_property(rtas.dev, "linux,rtas-base", NULL);
+ sizep = of_get_property(rtas.dev, "rtas-size", NULL);
+ if (basep == NULL || sizep == NULL) {
+ rtas.dev = NULL;
+ return;
+ }
+
+ rtas.base = __be32_to_cpu(*basep);
+ rtas.size = __be32_to_cpu(*sizep);
+ entryp = of_get_property(rtas.dev, "linux,rtas-entry", NULL);
+ if (entryp == NULL) /* Ugh */
+ rtas.entry = rtas.base;
+ else
+ rtas.entry = __be32_to_cpu(*entryp);
+
/* If RTAS was found, allocate the RMO buffer for it and look for
* the stop-self token if any
*/
--
2.7.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 2/3] powerpc/kernel: Use of_property_read_u32() in rtas_initialize()
2017-01-23 22:49 [PATCH v2 0/3] powerpc/kernel: Simplify rtas_initialize() Gavin Shan
2017-01-23 22:49 ` [PATCH v2 1/3] powerpc/kernel: Remove nested if statements in rtas_initialize() Gavin Shan
@ 2017-01-23 22:49 ` Gavin Shan
2017-01-23 22:49 ` [PATCH v2 3/3] powerpc/kernel: Fix unbalanced refcount on RTAS device node Gavin Shan
2 siblings, 0 replies; 5+ messages in thread
From: Gavin Shan @ 2017-01-23 22:49 UTC (permalink / raw)
To: linuxppc-dev; +Cc: mpe, Gavin Shan
This uses of_property_read_u32() in rtas_initialize() so that we
needn't explicitly care the CPU's endian.
Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
---
arch/powerpc/kernel/rtas.c | 20 +++++++++-----------
1 file changed, 9 insertions(+), 11 deletions(-)
diff --git a/arch/powerpc/kernel/rtas.c b/arch/powerpc/kernel/rtas.c
index 9759dcb..ba5a4cc 100644
--- a/arch/powerpc/kernel/rtas.c
+++ b/arch/powerpc/kernel/rtas.c
@@ -1145,7 +1145,8 @@ asmlinkage int ppc_rtas(struct rtas_args __user *uargs)
void __init rtas_initialize(void)
{
unsigned long rtas_region = RTAS_INSTANTIATE_MAX;
- const __be32 *basep, *entryp, *sizep;
+ u32 base, size, entry;
+ int no_base, no_size, no_entry;
/* Get RTAS dev node and fill up our "rtas" structure with infos
* about it.
@@ -1154,20 +1155,17 @@ void __init rtas_initialize(void)
if (!rtas.dev)
return;
- basep = of_get_property(rtas.dev, "linux,rtas-base", NULL);
- sizep = of_get_property(rtas.dev, "rtas-size", NULL);
- if (basep == NULL || sizep == NULL) {
+ no_base = of_property_read_u32(rtas.dev, "linux,rtas-base", &base);
+ no_size = of_property_read_u32(rtas.dev, "rtas-size", &size);
+ if (no_base || no_size) {
rtas.dev = NULL;
return;
}
- rtas.base = __be32_to_cpu(*basep);
- rtas.size = __be32_to_cpu(*sizep);
- entryp = of_get_property(rtas.dev, "linux,rtas-entry", NULL);
- if (entryp == NULL) /* Ugh */
- rtas.entry = rtas.base;
- else
- rtas.entry = __be32_to_cpu(*entryp);
+ rtas.base = base;
+ rtas.size = size;
+ no_entry = of_property_read_u32(rtas.dev, "linux,rtas-entry", &entry);
+ rtas.entry = no_entry ? rtas.base : entry;
/* If RTAS was found, allocate the RMO buffer for it and look for
* the stop-self token if any
--
2.7.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 3/3] powerpc/kernel: Fix unbalanced refcount on RTAS device node
2017-01-23 22:49 [PATCH v2 0/3] powerpc/kernel: Simplify rtas_initialize() Gavin Shan
2017-01-23 22:49 ` [PATCH v2 1/3] powerpc/kernel: Remove nested if statements in rtas_initialize() Gavin Shan
2017-01-23 22:49 ` [PATCH v2 2/3] powerpc/kernel: Use of_property_read_u32() " Gavin Shan
@ 2017-01-23 22:49 ` Gavin Shan
2 siblings, 0 replies; 5+ messages in thread
From: Gavin Shan @ 2017-01-23 22:49 UTC (permalink / raw)
To: linuxppc-dev; +Cc: mpe, Gavin Shan
The RTAS device-tree node's refcount has been increased by one in
the function call of_find_node_by_name(), but it's missed to be
decreased by one in the error path. It leads to unbalanced refcount
on RTAS device-tree node.
This fixes above issue by decreasing RTAS device-tree node's refcount
in error path.
Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
---
arch/powerpc/kernel/rtas.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/powerpc/kernel/rtas.c b/arch/powerpc/kernel/rtas.c
index ba5a4cc..b8a4987 100644
--- a/arch/powerpc/kernel/rtas.c
+++ b/arch/powerpc/kernel/rtas.c
@@ -1158,6 +1158,7 @@ void __init rtas_initialize(void)
no_base = of_property_read_u32(rtas.dev, "linux,rtas-base", &base);
no_size = of_property_read_u32(rtas.dev, "rtas-size", &size);
if (no_base || no_size) {
+ of_node_put(rtas.dev);
rtas.dev = NULL;
return;
}
--
2.7.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [v2, 1/3] powerpc/kernel: Remove nested if statements in rtas_initialize()
2017-01-23 22:49 ` [PATCH v2 1/3] powerpc/kernel: Remove nested if statements in rtas_initialize() Gavin Shan
@ 2017-01-27 0:40 ` Michael Ellerman
0 siblings, 0 replies; 5+ messages in thread
From: Michael Ellerman @ 2017-01-27 0:40 UTC (permalink / raw)
To: Gavin Shan, linuxppc-dev; +Cc: Gavin Shan
On Mon, 2017-01-23 at 22:49:52 UTC, Gavin Shan wrote:
> This removes the unnecessary nested if statements in function
> rtas_initialize(), to simplify the code. No functional changes
> introduced.
>
> Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
Series applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/dbecd5093043faa9da83c720ed0e08
cheers
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-01-27 0:40 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-23 22:49 [PATCH v2 0/3] powerpc/kernel: Simplify rtas_initialize() Gavin Shan
2017-01-23 22:49 ` [PATCH v2 1/3] powerpc/kernel: Remove nested if statements in rtas_initialize() Gavin Shan
2017-01-27 0:40 ` [v2, " Michael Ellerman
2017-01-23 22:49 ` [PATCH v2 2/3] powerpc/kernel: Use of_property_read_u32() " Gavin Shan
2017-01-23 22:49 ` [PATCH v2 3/3] powerpc/kernel: Fix unbalanced refcount on RTAS device node Gavin Shan
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).