netconsole: refactor CPU number formatting into separate function
authorBreno Leitao <leitao@debian.org>
Fri, 28 Feb 2025 12:50:19 +0000 (04:50 -0800)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 4 Mar 2025 14:28:27 +0000 (15:28 +0100)
Extract CPU number formatting logic from prepare_extradata() into a new
append_cpu_nr() function.

This refactoring improves code organization by isolating CPU number
formatting into its own function while reducing the complexity of
prepare_extradata().

The change prepares the codebase for the upcoming taskname feature by
establishing a consistent pattern for handling sysdata features.

The CPU number formatting logic itself remains unchanged; only its
location has moved to improve maintainability.

Signed-off-by: Breno Leitao <leitao@debian.org>
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
drivers/net/netconsole.c

index 698dbbea2713f1ea90db741e924b45dd85609b47..96153fd01f46e750bcc40e609a62e7d4a72e2e5f 100644 (file)
@@ -1117,13 +1117,21 @@ static void populate_configfs_item(struct netconsole_target *nt,
        init_target_config_group(nt, target_name);
 }
 
+static int append_cpu_nr(struct netconsole_target *nt, int offset)
+{
+       /* Append cpu=%d at extradata_complete after userdata str */
+       return scnprintf(&nt->extradata_complete[offset],
+                        MAX_EXTRADATA_ENTRY_LEN, " cpu=%u\n",
+                        raw_smp_processor_id());
+}
+
 /*
  * prepare_extradata - append sysdata at extradata_complete in runtime
  * @nt: target to send message to
  */
 static int prepare_extradata(struct netconsole_target *nt)
 {
-       int sysdata_len, extradata_len;
+       int extradata_len;
 
        /* userdata was appended when configfs write helper was called
         * by update_userdata().
@@ -1133,12 +1141,8 @@ static int prepare_extradata(struct netconsole_target *nt)
        if (!(nt->sysdata_fields & SYSDATA_CPU_NR))
                goto out;
 
-       /* Append cpu=%d at extradata_complete after userdata str */
-       sysdata_len = scnprintf(&nt->extradata_complete[nt->userdata_length],
-                               MAX_EXTRADATA_ENTRY_LEN, " cpu=%u\n",
-                               raw_smp_processor_id());
-
-       extradata_len += sysdata_len;
+       if (nt->sysdata_fields & SYSDATA_CPU_NR)
+               extradata_len += append_cpu_nr(nt, extradata_len);
 
        WARN_ON_ONCE(extradata_len >
                     MAX_EXTRADATA_ENTRY_LEN * MAX_EXTRADATA_ITEMS);