Skip to contentSkip to conversation

mmc-utils: Fix for Firmware Version string printing

PATCH In review [email protected] 3 participants 3 messages Jul 13, 2021 – Aug 24, 2021 MMC, SD and SDIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mmc-utils: Fix for Firmware Version string printing

From: Kimito Sakata <[email protected]>

Added a local buffer to create a NULL terminated string to print the Firmware Version instead of attempting to print directly from ext_csd buffer. The last byte of the Firmware Version field may not be NULL and the next field may also not be which may cause it to print garbage.

Tested on x86 platform.

---
 mmc_cmds.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
mmc_cmds.c +4 -2
index afa85b7..205e6e5 100644
@@ -1392,6 +1392,7 @@ int do_read_extcsd(int nargs, char **argv)
 	__u32 regl;
 	int fd, ret;
 	char *device;
+	char lbuf[10];
 	const char *str;
 
 	if (nargs != 2) {
@@ -1833,8 +1834,9 @@ int do_read_extcsd(int nargs, char **argv)
 	}
 
 	if (ext_csd_rev >= 7) {
-		printf("eMMC Firmware Version: %s\n",
-			(char*)&ext_csd[EXT_CSD_FIRMWARE_VERSION]);
+                memset(lbuf, 0, sizeof(lbuf));
+		strncpy(lbuf, (char*)&ext_csd[EXT_CSD_FIRMWARE_VERSION], 8);
+		printf("eMMC Firmware Version: %s\n", lbuf);
 		printf("eMMC Life Time Estimation A [EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_A]: 0x%02x\n",
 			ext_csd[EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_A]);
 		printf("eMMC Life Time Estimation B [EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_B]: 0x%02x\n",
Signature · 1 line
2.31.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines

From: Kimito Sakata <[email protected]>

Added a local buffer to create a NULL terminated string to print the Firmware Version instead of attempting to print directly from ext_csd buffer. The last byte of the Firmware Version field may not be NULL and the next field may also not be which may cause it to print garbage.

Tested on x86 platform.

Fixes 89cd01ed865a (mmc_utils: add ffu support)
Quoted 32 lines
---
 mmc_cmds.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
mmc_cmds.c +4 -2
index afa85b7..205e6e5 100644
@@ -1392,6 +1392,7 @@ int do_read_extcsd(int nargs, char **argv)
        __u32 regl;
        int fd, ret;
        char *device;
+       char lbuf[10];
        const char *str;
 
        if (nargs != 2) {
@@ -1833,8 +1834,9 @@ int do_read_extcsd(int nargs, char **argv)
        }
 
        if (ext_csd_rev >= 7) {
-               printf("eMMC Firmware Version: %s\n",
-                       (char*)&ext_csd[EXT_CSD_FIRMWARE_VERSION]);
+                memset(lbuf, 0, sizeof(lbuf));
+               strncpy(lbuf, (char*)&ext_csd[EXT_CSD_FIRMWARE_VERSION], 8);
+               printf("eMMC Firmware Version: %s\n", lbuf);
                printf("eMMC Life Time Estimation A
 [EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_A]: 0x%02x\n",
                        ext_csd[EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_A]);

printf("eMMC Life Time Estimation B
[EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_B]: 0x%02x\n", --
2.31.1

#2 lore raw
Quoted 10 lines · Avri Altman
Quoted 10 lines

From: Kimito Sakata <[email protected]>

Added a local buffer to create a NULL terminated string to print the Firmware Version instead of attempting to print directly from ext_csd buffer. The last byte of the Firmware Version field may not be NULL and the next field may also not be which may cause it to print garbage.

Quoted 5 lines
Quoted 1 line

Tested on x86 platform.

Fixes 89cd01ed865a (mmc_utils: add ffu support)

Applied for master at git.kernel.org/pub/scm/utils/mmc/mmc-utils.git, thanks!

Kind regards
Uffe

Quoted 34 lines
Quoted 33 lines
---
 mmc_cmds.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
mmc_cmds.c +4 -2
index afa85b7..205e6e5 100644
@@ -1392,6 +1392,7 @@ int do_read_extcsd(int nargs, char **argv)
        __u32 regl;
        int fd, ret;
        char *device;
+       char lbuf[10];
        const char *str;
 
        if (nargs != 2) {
@@ -1833,8 +1834,9 @@ int do_read_extcsd(int nargs, char **argv)
        }
 
        if (ext_csd_rev >= 7) {
-               printf("eMMC Firmware Version: %s\n",
-                       (char*)&ext_csd[EXT_CSD_FIRMWARE_VERSION]);
+                memset(lbuf, 0, sizeof(lbuf));
+               strncpy(lbuf, (char*)&ext_csd[EXT_CSD_FIRMWARE_VERSION], 8);
+               printf("eMMC Firmware Version: %s\n", lbuf);
                printf("eMMC Life Time Estimation A
 [EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_A]: 0x%02x\n",
                        ext_csd[EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_A]);

printf("eMMC Life Time Estimation B
[EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_B]: 0x%02x\n", --
2.31.1