From: SF Markus Elfring <hidden> Date: 2017-01-19 16:53:56
From: Markus Elfring <redacted>
Date: Thu, 19 Jan 2017 17:41:23 +0100
Some update suggestions were taken into account
from static source code analysis.
Markus Elfring (8):
Return directly after a failed parameter validation in dev_nvram_write()
Return directly after a failed kmalloc() in dev_nvram_write()
Move an assignment for the variable "ret" in dev_nvram_write()
Return directly after a failed parameter validation in dev_nvram_read()
Return directly after a failed kmalloc() in dev_nvram_read()
Delete three error messages for a failed memory allocation
Improve size determinations in three functions
Move an assignment for the variable "err" in nvram_scan_partitions()
arch/powerpc/kernel/nvram_64.c | 63 +++++++++++++++---------------------------
1 file changed, 22 insertions(+), 41 deletions(-)
--
2.11.0
From: SF Markus Elfring <hidden> Date: 2017-01-19 16:54:24
From: Markus Elfring <redacted>
Date: Thu, 19 Jan 2017 15:22:56 +0100
* Return directly after an inappropriate input parameter was detected.
* Delete an initialisation for the variable "tmp" at the beginning
and an assignment for the variable "ret" which became unnecessary
with this refactoring.
Signed-off-by: Markus Elfring <redacted>
---
arch/powerpc/kernel/nvram_64.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
From: SF Markus Elfring <hidden> Date: 2017-01-19 16:55:59
From: Markus Elfring <redacted>
Date: Thu, 19 Jan 2017 15:44:03 +0100
Return directly after a call of the function "kmalloc" failed here.
Signed-off-by: Markus Elfring <redacted>
---
arch/powerpc/kernel/nvram_64.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
From: SF Markus Elfring <hidden> Date: 2017-01-19 16:58:03
From: Markus Elfring <redacted>
Date: Thu, 19 Jan 2017 16:12:48 +0100
* Return directly after an inappropriate input parameter was detected.
* Delete an initialisation for the variable "tmp" at the beginning
which became unnecessary with this refactoring.
Signed-off-by: Markus Elfring <redacted>
---
arch/powerpc/kernel/nvram_64.c | 20 +++++++-------------
1 file changed, 7 insertions(+), 13 deletions(-)
From: SF Markus Elfring <hidden> Date: 2017-01-19 17:01:33
From: Markus Elfring <redacted>
Date: Thu, 19 Jan 2017 16:56:46 +0100
The script "checkpatch.pl" pointed information out like the following.
WARNING: Possible unnecessary 'out of memory' message
Thus fix affected source code places.
Signed-off-by: Markus Elfring <redacted>
---
arch/powerpc/kernel/nvram_64.c | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)
From: SF Markus Elfring <hidden> Date: 2017-01-19 17:03:56
From: Markus Elfring <redacted>
Date: Thu, 19 Jan 2017 15:55:36 +0100
A local variable was set to an error code before a concrete error situation
was detected. Thus move the corresponding assignment into an if branch
to indicate a software failure there.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <redacted>
---
arch/powerpc/kernel/nvram_64.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
From: SF Markus Elfring <hidden> Date: 2017-01-19 17:04:29
From: Markus Elfring <redacted>
Date: Thu, 19 Jan 2017 17:15:30 +0100
Replace the specification of data structures by references for local
variables as the parameter for the operator "sizeof" to make
the corresponding size determination a bit safer.
Signed-off-by: Markus Elfring <redacted>
---
arch/powerpc/kernel/nvram_64.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
From: SF Markus Elfring <hidden> Date: 2017-01-19 17:36:18
From: Markus Elfring <redacted>
Date: Thu, 19 Jan 2017 17:27:37 +0100
A local variable was set to an error code before a concrete error situation
was detected. Thus move the corresponding assignment into an if branch
to indicate a software failure there.
Signed-off-by: Markus Elfring <redacted>
---
arch/powerpc/kernel/nvram_64.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
From: SF Markus Elfring <hidden> Date: 2017-01-19 20:44:18
From: Markus Elfring <redacted>
Date: Thu, 19 Jan 2017 16:50:31 +0100
Return directly after a call of the function "kmalloc" failed here.
Signed-off-by: Markus Elfring <redacted>
---
arch/powerpc/kernel/nvram_64.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
From: Markus Elfring <redacted>
Date: Thu, 19 Jan 2017 15:55:36 +0100
A local variable was set to an error code before a concrete error situation
was detected. Thus move the corresponding assignment into an if branch
to indicate a software failure there.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <redacted>
---
arch/powerpc/kernel/nvram_64.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
I think you really could have squashed patches 1-3 into a single patch
that returns directly after any failure. After this 3rd patch this is
now the only spot that branches to the "out" label. At this point you
might as well remove that label and move the kfree(tmp) call up and
return directly after the failure and at the nvram_write() call site
doing away completely with the "ret" variable.
Something like the following patch:
From: SF Markus Elfring <hidden> Date: 2017-01-20 07:09:34
I think you really could have squashed patches 1-3 into a single patch
that returns directly after any failure.
Thanks for your constructive feedback.
I have got software development concerns around such patch squashing.
At this point you might as well remove that label and move the kfree(tmp) call up
and return directly after the failure and at the nvram_write() call site
doing away completely with the "ret" variable.
Your idea might look nice at first glance. But I would interpret the previous
implementation of the discussed function in the way that the memory which was
dynamically allocated here should always (not only in the failure case) be released
before returning here.
Would you really like to change the life time for this “temporary” data item?
Regards,
Markus
I think you really could have squashed patches 1-3 into a single patch
that returns directly after any failure.
Thanks for your constructive feedback.
I have got software development concerns around such patch squashing.
quoted
At this point you might as well remove that label and move the kfree(tmp) call up
and return directly after the failure and at the nvram_write() call site
doing away completely with the "ret" variable.
Your idea might look nice at first glance. But I would interpret the previous
implementation of the discussed function in the way that the memory which was
dynamically allocated here should always (not only in the failure case) be released
before returning here.
You are correct. I did muck that part up. However, I do still believe it
is cleaner to squash your three patches together. There is no functional
change here and it is clearer in a single patch that you are modifying
the function to return directly in the simple error cases.
-Tyrel
Would you really like to change the life time for this “temporary” data item?
Regards,
Markus