Pass a print callback to dmi_print_memory_size, as we already do for
dmi_system_uuid. This makes it possible to use this function for
either an attribute or a sub-attribute.

Signed-off-by: Jean Delvare <[email protected]>
---
 dmidecode.c |   23 +++++++++++++----------
 dmidecode.h |    3 ++-
 dmioem.c    |    4 ++--
 3 files changed, 17 insertions(+), 13 deletions(-)

--- a/dmidecode.c
+++ b/dmidecode.c
@@ -274,7 +274,8 @@ static void dmi_dump(const struct dmi_he
 }
 
 /* shift is 0 if the value is in bytes, 1 if it is in kibibytes */
-void dmi_print_memory_size(const char *attr, u64 code, int shift)
+void dmi_print_memory_size(void (*print_cb)(const char *name, const char 
*format, ...),
+                          const char *attr, u64 code, int shift)
 {
        unsigned long capacity;
        u16 split[7];
@@ -314,7 +315,7 @@ void dmi_print_memory_size(const char *a
        else
                capacity = split[i];
 
-       pr_attr(attr, "%lu %s", capacity, unit[i + shift]);
+       print_cb(attr, "%lu %s", capacity, unit[i + shift]);
 }
 
 /* shift is 0 if the value is in bytes, 1 if it is in kB, 2 if it is in MB */
@@ -368,7 +369,7 @@ static void dmi_bios_rom_size(u8 code1,
 
        if (code1 != 0xFF)
        {
-               dmi_print_memory_size("ROM Size", (u64)(code1 + 1) << 6, 1);
+               dmi_print_memory_size(pr_attr, "ROM Size", (u64)(code1 + 1) << 
6, 1);
        }
        else
                pr_attr("ROM Size", "%u %s", code2 & 0x3FFF, unit[code2 >> 14]);
@@ -1817,7 +1818,7 @@ static void dmi_cache_size_2(const char
        }
 
        /* Use a more convenient unit for large cache size */
-       dmi_print_memory_size(attr, size, 1);
+       dmi_print_memory_size(pr_attr, attr, size, 1);
 }
 
 static void dmi_cache_size(const char *attr, u16 code)
@@ -2796,7 +2797,7 @@ static void dmi_memory_device_size(u16 c
                u64 s = (u64)code & 0x7FFFULL;
                if (!(code & 0x8000))
                        s <<= 10;
-               dmi_print_memory_size("Size", s, 1);
+               dmi_print_memory_size(pr_attr, "Size", s, 1);
        }
 }
 
@@ -3041,7 +3042,7 @@ static void dmi_memory_size(const char *
        else if (code == 0ULL)
                pr_attr(attr, "None");
        else
-               dmi_print_memory_size(attr, code, 0);
+               dmi_print_memory_size(pr_attr, attr, code, 0);
 }
 
 static void dmi_memory_revision(const char *attr_type, u16 code, u8 mem_type)
@@ -3168,7 +3169,7 @@ static void dmi_mapped_address_size(u32
        if (code == 0)
                pr_attr("Range Size", "Invalid");
        else
-               dmi_print_memory_size("Range Size", (u64)code, 1);
+               dmi_print_memory_size(pr_attr, "Range Size", (u64)code, 1);
 }
 
 static void dmi_mapped_address_extended_size(u64 start, u64 end)
@@ -3176,7 +3177,7 @@ static void dmi_mapped_address_extended_
        if (start == end)
                pr_attr("Range Size", "Invalid");
        else
-               dmi_print_memory_size("Range Size", end - start + 1, 0);
+               dmi_print_memory_size(pr_attr, "Range Size", end - start + 1, 
0);
 }
 
 /*
@@ -4878,12 +4879,14 @@ static void dmi_decode(const struct dmi_
                                if (h->length < 0x17)
                                        pr_attr("Maximum Capacity", "Unknown");
                                else
-                                       dmi_print_memory_size("Maximum 
Capacity",
+                                       dmi_print_memory_size(pr_attr,
+                                                             "Maximum 
Capacity",
                                                              QWORD(data + 
0x0F), 0);
                        }
                        else
                        {
-                               dmi_print_memory_size("Maximum Capacity",
+                               dmi_print_memory_size(pr_attr,
+                                                     "Maximum Capacity",
                                                      DWORD(data + 0x07), 1);
                        }
                        if (!(opt.flags & FLAG_QUIET))
--- a/dmidecode.h
+++ b/dmidecode.h
@@ -49,7 +49,8 @@ extern enum cpuid_type cpuid_type;
 
 int is_printable(const u8 *data, int len);
 const char *dmi_string(const struct dmi_header *dm, u8 s);
-void dmi_print_memory_size(const char *attr, u64 code, int shift);
+void dmi_print_memory_size(void (*print_cb)(const char *name, const char 
*format, ...),
+                          const char *attr, u64 code, int shift);
 void dmi_print_storage_size(const char *attr, u64 code, unsigned int shift);
 void dmi_print_cpuid(void (*print_cb)(const char *name, const char *format, 
...),
                     const char *label, enum cpuid_type sig, const u8 *p);
--- a/dmioem.c
+++ b/dmioem.c
@@ -1956,7 +1956,7 @@ static int dmi_decode_hp(const struct dm
                        pr_attr("Version String", "%s", dmi_string(h, 
data[0x0A]));
 
                        if (DWORD(data + 0x0B))
-                               dmi_print_memory_size("Image Size", QWORD(data 
+ 0xB), 0);
+                               dmi_print_memory_size(pr_attr, "Image Size", 
QWORD(data + 0xB), 0);
                        else
                                pr_attr("Image Size", "Not Available");
 
@@ -2103,7 +2103,7 @@ static int dmi_decode_hp(const struct dm
                                                          ((feat >> 1) & 0x01) 
? "Byte Accessible" :
                                                          ((feat >> 2) & 0x01) 
? "Block I/O" :
                                                          "Reserved");
-                       dmi_print_memory_size("Size", QWORD(data + 0x09), 2);
+                       dmi_print_memory_size(pr_attr, "Size", QWORD(data + 
0x09), 2);
                        pr_attr("Passphrase Enabled", "%s", data[0x11] ? "Yes" 
: "No");
                        feat = WORD(data + 0x12);
                        if (feat)

-- 
Jean Delvare
SUSE L3 Support

Reply via email to