All of lore.kernel.org
 help / color / mirror / Atom feed
From: Masahiro Yamada <masahiroy@kernel.org>
To: linux-kbuild@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Masahiro Yamada <masahiroy@kernel.org>
Subject: [PATCH 4/6] genksyms: refactor the return points in the for-loop in __add_symbol()
Date: Fri,  3 Jan 2025 16:30:41 +0900	[thread overview]
Message-ID: <20250103073046.2609911-4-masahiroy@kernel.org> (raw)
In-Reply-To: <20250103073046.2609911-1-masahiroy@kernel.org>

free_list() must be called before returning from this for-loop.

Swap 'break' and the combination of free_list() and 'return'.

This reduces the code and minimizes the risk of introducing memory
leaks in future changes.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/genksyms/genksyms.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/scripts/genksyms/genksyms.c b/scripts/genksyms/genksyms.c
index 5a90acd693f4..41d6cfce0088 100644
--- a/scripts/genksyms/genksyms.c
+++ b/scripts/genksyms/genksyms.c
@@ -231,7 +231,7 @@ static struct symbol *__add_symbol(const char *name, enum symbol_type type,
 			continue;
 
 		if (is_reference) {
-			/* fall through */ ;
+			break;
 		} else if (sym->type == type && equal_list(sym->defn, defn)) {
 			if (!sym->is_declared && sym->is_override) {
 				print_location();
@@ -239,25 +239,21 @@ static struct symbol *__add_symbol(const char *name, enum symbol_type type,
 				fprintf(stderr, " modversion is unchanged\n");
 			}
 			sym->is_declared = 1;
-			free_list(defn, NULL);
-			return sym;
 		} else if (sym->is_declared) {
 			error_with_pos("redefinition of %s", name);
-			free_list(defn, NULL);
-			return sym;
 		} else if (sym->is_override && flag_preserve) {
 			print_location();
 			fprintf(stderr, "ignoring ");
 			print_type_name(type, name);
 			fprintf(stderr, " modversion change\n");
 			sym->is_declared = 1;
-			free_list(defn, NULL);
-			return sym;
 		} else {
 			status = is_unknown_symbol(sym) ?
 					STATUS_DEFINED : STATUS_MODIFIED;
+			break;
 		}
-		break;
+		free_list(defn, NULL);
+		return sym;
 	}
 
 	if (sym) {
-- 
2.43.0


  parent reply	other threads:[~2025-01-03  7:30 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-03  7:30 [PATCH 1/6] genksyms: fix memory leak when the same symbol is added from source Masahiro Yamada
2025-01-03  7:30 ` [PATCH 2/6] genksyms: fix memory leak when the same symbol is read from *.symref file Masahiro Yamada
2025-01-03 12:50   ` Markus Elfring
2025-01-03  7:30 ` [PATCH 3/6] genksyms: reduce the indentation in the for-loop in __add_symbol() Masahiro Yamada
2025-01-03  7:30 ` Masahiro Yamada [this message]
2025-01-03  7:30 ` [PATCH 5/6] genksyms: use generic macros for hash table implementation Masahiro Yamada
2025-01-03  7:30 ` [PATCH 6/6] genksyms: use uint32_t instead of unsigned long for calculating CRC Masahiro Yamada
2025-01-03  8:34   ` David Laight
2025-01-10 17:34     ` Masahiro Yamada
2025-01-03 11:56 ` [PATCH 1/6] genksyms: fix memory leak when the same symbol is added from source Markus Elfring

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250103073046.2609911-4-masahiroy@kernel.org \
    --to=masahiroy@kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.