Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/ic A part number field of DDR3 and DDR4 is not NUL t...



details:   https://anonhg.NetBSD.org/src/rev/f6aac444b5e2
branches:  trunk
changeset: 356831:f6aac444b5e2
user:      msaitoh <msaitoh%NetBSD.org@localhost>
date:      Mon Oct 16 08:33:48 2017 +0000

description:
A part number field of DDR3 and DDR4 is not NUL terminated. All unused chars
are filled by 0x20. Print it correctly.

Before:
spdmem0 at iic0 addr 0x50: 8KTF51264AZ-1G6E1 E1M^@,DPAFEQZ021
spdmem1 at iic0 addr 0x51: ACR256X64D3U1333C9BA^AM^X
spdmem2 at iic0 addr 0x52: KP223C-ELD        BA^BM-~

After:
spdmem0 at iic0 addr 0x50: 8KTF51264AZ-1G6E1
spdmem1 at iic0 addr 0x51: ACR256X64D3U1333C9
spdmem2 at iic0 addr 0x52: KP223C-ELD

diffstat:

 sys/dev/ic/spdmem.c |  31 +++++++++++++++++++++++++++----
 1 files changed, 27 insertions(+), 4 deletions(-)

diffs (63 lines):

diff -r 5e727ce01b8f -r f6aac444b5e2 sys/dev/ic/spdmem.c
--- a/sys/dev/ic/spdmem.c       Mon Oct 16 05:52:43 2017 +0000
+++ b/sys/dev/ic/spdmem.c       Mon Oct 16 08:33:48 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: spdmem.c,v 1.24 2017/01/18 06:02:50 msaitoh Exp $ */
+/* $NetBSD: spdmem.c,v 1.25 2017/10/16 08:33:48 msaitoh Exp $ */
 
 /*
  * Copyright (c) 2007 Nicolas Joly
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: spdmem.c,v 1.24 2017/01/18 06:02:50 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spdmem.c,v 1.25 2017/10/16 08:33:48 msaitoh Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -751,9 +751,20 @@
 decode_ddr3(const struct sysctlnode *node, device_t self, struct spdmem *s)
 {
        int dimm_size, cycle_time, bits;
+       unsigned char buf[sizeof(s->sm_ddr3.ddr3_part) + 1];
+       int i, pnsize;
 
+       pnsize = sizeof(s->sm_ddr3.ddr3_part);
+       memcpy(buf, s->sm_ddr3.ddr3_part, pnsize);
+       buf[pnsize] = 0; /* Terminate for full string */
+       for (i = pnsize - 1; i >= 0; i--) {
+               if (buf[i] == 0x20) /* remove trailing spaces */
+                       buf[i] = 0;
+               else
+                       break;
+       }
        aprint_naive("\n");
-       aprint_normal(": %18s\n", s->sm_ddr3.ddr3_part);
+       aprint_normal(": %s\n", buf);
        aprint_normal_dev(self, "%s", spdmem_basic_types[s->sm_type]);
 
        if (s->sm_ddr3.ddr3_mod_type ==
@@ -862,9 +873,21 @@
 {
        int dimm_size, cycle_time;
        int tAA_clocks, tRCD_clocks,tRP_clocks, tRAS_clocks;
+       unsigned char buf[sizeof(s->sm_ddr4.ddr4_part_number) + 1];
+       int i, pnsize;
+
+       pnsize = sizeof(s->sm_ddr4.ddr4_part_number);
+       memcpy(buf, s->sm_ddr4.ddr4_part_number, pnsize);
+       buf[pnsize] = 0; /* Terminate for full string */
+       for (i = pnsize - 1; i >= 0; i--) {
+               if (buf[i] == 0x20) /* remove trailing spaces */
+                       buf[i] = 0;
+               else
+                       break;
+       }
 
        aprint_naive("\n");
-       aprint_normal(": %20s\n", s->sm_ddr4.ddr4_part_number);
+       aprint_normal(": %s\n", buf);
        aprint_normal_dev(self, "%s", spdmem_basic_types[s->sm_type]);
        if (s->sm_ddr4.ddr4_mod_type < __arraycount(spdmem_ddr4_module_types))
                aprint_normal(" (%s)", 



Home | Main Index | Thread Index | Old Index