Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 19 Nov 2018 06:48:48 +0000 (UTC)
From:      Stanislav Galabov <sgalabov@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r340613 - head/sys/mips/mediatek
Message-ID:  <201811190648.wAJ6mmxN031960@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: sgalabov
Date: Mon Nov 19 06:48:48 2018
New Revision: 340613
URL: https://svnweb.freebsd.org/changeset/base/340613

Log:
  Fix access to cpu_model[] in mtk_soc_set_cpu_model()
  
  There may be cases where cpu_model[] may not be 32bit aligned, so it is
  better to not try to access it as such in order to avoid unaligned access.
  
  Sponsored by:	Smartcom - Bulgaria AD

Modified:
  head/sys/mips/mediatek/mtk_soc.c

Modified: head/sys/mips/mediatek/mtk_soc.c
==============================================================================
--- head/sys/mips/mediatek/mtk_soc.c	Mon Nov 19 06:39:00 2018	(r340612)
+++ head/sys/mips/mediatek/mtk_soc.c	Mon Nov 19 06:48:48 2018	(r340613)
@@ -401,7 +401,9 @@ extern char cpu_model[];
 void
 mtk_soc_set_cpu_model(void)
 {
-	uint32_t *p_model = (uint32_t *)cpu_model;
+	int idx, offset = sizeof(mtk_soc_chipid0_3);
+	char *chipid0_3 = (char *)(&mtk_soc_chipid0_3);
+	char *chipid4_7 = (char *)(&mtk_soc_chipid4_7);
 
 	/*
 	 * CHIPID is always 2x32 bit registers, containing the ASCII
@@ -411,11 +413,13 @@ mtk_soc_set_cpu_model(void)
 	 * it is left at its default value of "unknown " if it could not be
 	 * obtained for some reason.
 	 */
-	p_model[0] = mtk_soc_chipid0_3;
-	p_model[1] = mtk_soc_chipid4_7;
+	for (idx = 0; idx < offset; idx++) {
+		cpu_model[idx] = chipid0_3[idx];
+		cpu_model[idx + offset] = chipid4_7[idx];
+	}
 
 	/* Null-terminate the string */
-	cpu_model[8] = 0;
+	cpu_model[2 * offset] = 0;
 }
 
 uint32_t



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201811190648.wAJ6mmxN031960>