[PATCH 2/2] module: Avoid unnecessary return value initialization in move_module()

Petr Pavlu posted 2 patches 6 months, 2 weeks ago
There is a newer version of this series
[PATCH 2/2] module: Avoid unnecessary return value initialization in move_module()
Posted by Petr Pavlu 6 months, 2 weeks ago
All error conditions in move_module() set the return value by updating the
ret variable. Therefore, it is not necessary to the initialize the variable
when declaring it.

Remove the unnecessary initialization.

Signed-off-by: Petr Pavlu <petr.pavlu@suse.com>
---
 kernel/module/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/module/main.c b/kernel/module/main.c
index 322b38c0a782..06511607075c 100644
--- a/kernel/module/main.c
+++ b/kernel/module/main.c
@@ -2615,7 +2615,7 @@ static int move_module(struct module *mod, struct load_info *info)
 {
 	int i;
 	enum mod_mem_type t;
-	int ret = -ENOMEM;
+	int ret;
 	bool codetag_section_found = false;
 
 	for_each_mod_mem_type(type) {
-- 
2.49.0
Re: [PATCH 2/2] module: Avoid unnecessary return value initialization in move_module()
Posted by Daniel Gomez 6 months, 1 week ago
On 07/06/2025 18.16, Petr Pavlu wrote:
> All error conditions in move_module() set the return value by updating the
> ret variable. Therefore, it is not necessary to the initialize the variable
> when declaring it.
> 
> Remove the unnecessary initialization.
> 
> Signed-off-by: Petr Pavlu <petr.pavlu@suse.com>

Reviewed-by: Daniel Gomez <da.gomez@samsung.com>

> ---
>  kernel/module/main.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/module/main.c b/kernel/module/main.c
> index 322b38c0a782..06511607075c 100644
> --- a/kernel/module/main.c
> +++ b/kernel/module/main.c
> @@ -2615,7 +2615,7 @@ static int move_module(struct module *mod, struct load_info *info)
>  {
>  	int i;
>  	enum mod_mem_type t;
> -	int ret = -ENOMEM;
> +	int ret;

Nit:

We can "merge" all integers in one line.
Re: [PATCH 2/2] module: Avoid unnecessary return value initialization in move_module()
Posted by Sami Tolvanen 6 months, 1 week ago
On Sat, Jun 07, 2025 at 06:16:28PM +0200, Petr Pavlu wrote:
> All error conditions in move_module() set the return value by updating the
> ret variable. Therefore, it is not necessary to the initialize the variable
> when declaring it.
> 
> Remove the unnecessary initialization.
> 
> Signed-off-by: Petr Pavlu <petr.pavlu@suse.com>
> ---
>  kernel/module/main.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/module/main.c b/kernel/module/main.c
> index 322b38c0a782..06511607075c 100644
> --- a/kernel/module/main.c
> +++ b/kernel/module/main.c
> @@ -2615,7 +2615,7 @@ static int move_module(struct module *mod, struct load_info *info)
>  {
>  	int i;
>  	enum mod_mem_type t;
> -	int ret = -ENOMEM;
> +	int ret;
>  	bool codetag_section_found = false;
>  
>  	for_each_mod_mem_type(type) {

Reviewed-by: Sami Tolvanen <samitolvanen@google.com>

Sami