Remove already upstreamed patches, add another one from mailing-list. Signed-off-by: Michael Heimpold <mhei@heimpold.de>lilik-openwrt-22.03
@ -1,30 +0,0 @@ | |||
From bf96e1b2f48eab26c4a0c2a0903d9d7b9a311a1d Mon Sep 17 00:00:00 2001 | |||
From: Michael Heimpold <michael.heimpold@i2se.com> | |||
Date: Tue, 18 Dec 2018 14:47:16 +0100 | |||
Subject: [PATCH 1/9] Check calloc's return value before using the pointer | |||
If calloc fails, bail out immediately instead of trying to | |||
use the NULL pointer. | |||
Signed-off-by: Michael Heimpold <michael.heimpold@i2se.com> | |||
Cc: Michael Heimpold <mhei@heimpold.de> | |||
--- | |||
lsmmc.c | 2 ++ | |||
1 file changed, 2 insertions(+) | |||
diff --git a/lsmmc.c b/lsmmc.c | |||
index 9737b37..e514c83 100644 | |||
--- a/lsmmc.c | |||
+++ b/lsmmc.c | |||
@@ -374,6 +374,8 @@ char *to_binstr(char *hexstr) | |||
char *binstr; | |||
binstr = calloc(strlen(hexstr) * 4 + 1, sizeof(char)); | |||
+ if (!binstr) | |||
+ return NULL; | |||
while (hexstr && *hexstr != '\0') { | |||
if (!isxdigit(*hexstr)) | |||
-- | |||
2.17.1 | |||
@ -1,33 +0,0 @@ | |||
From 9214f2a4002bafef73c9593464ab3841ba7bac12 Mon Sep 17 00:00:00 2001 | |||
From: Michael Heimpold <michael.heimpold@i2se.com> | |||
Date: Tue, 18 Dec 2018 14:49:37 +0100 | |||
Subject: [PATCH 2/9] Cleanup memory in error case | |||
In case that we leave due to malformed string, | |||
free the allocated memory before returning. | |||
Signed-off-by: Michael Heimpold <michael.heimpold@i2se.com> | |||
Cc: Michael Heimpold <mhei@heimpold.de> | |||
--- | |||
lsmmc.c | 4 +++- | |||
1 file changed, 3 insertions(+), 1 deletion(-) | |||
diff --git a/lsmmc.c b/lsmmc.c | |||
index e514c83..a53bc57 100644 | |||
--- a/lsmmc.c | |||
+++ b/lsmmc.c | |||
@@ -378,8 +378,10 @@ char *to_binstr(char *hexstr) | |||
return NULL; | |||
while (hexstr && *hexstr != '\0') { | |||
- if (!isxdigit(*hexstr)) | |||
+ if (!isxdigit(*hexstr)) { | |||
+ free(binstr); | |||
return NULL; | |||
+ } | |||
if (isdigit(*hexstr)) | |||
strcat(binstr, bindigits[*hexstr - '0']); | |||
-- | |||
2.17.1 | |||
@ -1,33 +0,0 @@ | |||
From a59d98003c0b2364929ee23ed331d610029c6dcf Mon Sep 17 00:00:00 2001 | |||
From: Michael Heimpold <michael.heimpold@i2se.com> | |||
Date: Tue, 18 Dec 2018 14:52:12 +0100 | |||
Subject: [PATCH 3/9] Fix parsing of character in to_binstr() | |||
When a hex-digit > 'a' or 'A' is read, we have to add an offset of 10 | |||
to access the valid symbol in our mapping table. | |||
Signed-off-by: Michael Heimpold <michael.heimpold@i2se.com> | |||
Cc: Michael Heimpold <mhei@heimpold.de> | |||
--- | |||
lsmmc.c | 4 ++-- | |||
1 file changed, 2 insertions(+), 2 deletions(-) | |||
diff --git a/lsmmc.c b/lsmmc.c | |||
index a53bc57..e64117c 100644 | |||
--- a/lsmmc.c | |||
+++ b/lsmmc.c | |||
@@ -386,9 +386,9 @@ char *to_binstr(char *hexstr) | |||
if (isdigit(*hexstr)) | |||
strcat(binstr, bindigits[*hexstr - '0']); | |||
else if (islower(*hexstr)) | |||
- strcat(binstr, bindigits[*hexstr - 'a']); | |||
+ strcat(binstr, bindigits[*hexstr - 'a' + 10]); | |||
else | |||
- strcat(binstr, bindigits[*hexstr - 'A']); | |||
+ strcat(binstr, bindigits[*hexstr - 'A' + 10]); | |||
hexstr++; | |||
} | |||
-- | |||
2.17.1 | |||
@ -1,56 +0,0 @@ | |||
From f1fc04d7609ab074647aa00e96d4c66d5135b155 Mon Sep 17 00:00:00 2001 | |||
From: Michael Heimpold <michael.heimpold@i2se.com> | |||
Date: Tue, 18 Dec 2018 15:02:25 +0100 | |||
Subject: [PATCH 4/9] Optimize to_binstr() function | |||
Appending multiple times to same string is slow since strcat() needs | |||
to determine the end during each run. So manually maintain a pointer | |||
to the end to speed-up things. | |||
Signed-off-by: Michael Heimpold <michael.heimpold@i2se.com> | |||
Cc: Michael Heimpold <mhei@heimpold.de> | |||
--- | |||
lsmmc.c | 11 +++++++---- | |||
1 file changed, 7 insertions(+), 4 deletions(-) | |||
diff --git a/lsmmc.c b/lsmmc.c | |||
index e64117c..86713f7 100644 | |||
--- a/lsmmc.c | |||
+++ b/lsmmc.c | |||
@@ -371,12 +371,14 @@ char *to_binstr(char *hexstr) | |||
"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", | |||
"1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111", | |||
}; | |||
- char *binstr; | |||
+ char *binstr, *tail; | |||
binstr = calloc(strlen(hexstr) * 4 + 1, sizeof(char)); | |||
if (!binstr) | |||
return NULL; | |||
+ tail = binstr; | |||
+ | |||
while (hexstr && *hexstr != '\0') { | |||
if (!isxdigit(*hexstr)) { | |||
free(binstr); | |||
@@ -384,13 +386,14 @@ char *to_binstr(char *hexstr) | |||
} | |||
if (isdigit(*hexstr)) | |||
- strcat(binstr, bindigits[*hexstr - '0']); | |||
+ strcat(tail, bindigits[*hexstr - '0']); | |||
else if (islower(*hexstr)) | |||
- strcat(binstr, bindigits[*hexstr - 'a' + 10]); | |||
+ strcat(tail, bindigits[*hexstr - 'a' + 10]); | |||
else | |||
- strcat(binstr, bindigits[*hexstr - 'A' + 10]); | |||
+ strcat(tail, bindigits[*hexstr - 'A' + 10]); | |||
hexstr++; | |||
+ tail += 4; | |||
} | |||
return binstr; | |||
-- | |||
2.17.1 | |||
@ -1,30 +0,0 @@ | |||
From c0375ecea6f3731c0f65ff6abd2c194b90153b26 Mon Sep 17 00:00:00 2001 | |||
From: Michael Heimpold <michael.heimpold@i2se.com> | |||
Date: Tue, 18 Dec 2018 15:09:42 +0100 | |||
Subject: [PATCH 5/9] Add eMMC vendor Micron to table | |||
Signed-off-by: Michael Heimpold <michael.heimpold@i2se.com> | |||
Cc: Michael Heimpold <mhei@heimpold.de> | |||
--- | |||
lsmmc.c | 5 +++++ | |||
1 file changed, 5 insertions(+) | |||
diff --git a/lsmmc.c b/lsmmc.c | |||
index 86713f7..4f687ac 100644 | |||
--- a/lsmmc.c | |||
+++ b/lsmmc.c | |||
@@ -194,6 +194,11 @@ struct ids_database database[] = { | |||
.id = 0x11, | |||
.manufacturer = "Toshiba", | |||
}, | |||
+ { | |||
+ .type = "mmc", | |||
+ .id = 0x13, | |||
+ .manufacturer = "Micron", | |||
+ }, | |||
{ | |||
.type = "mmc", | |||
.id = 0x15, | |||
-- | |||
2.17.1 | |||
@ -0,0 +1,35 @@ | |||
From 3539243dcab7b84bb8a45e2c2da80e162284bffc Mon Sep 17 00:00:00 2001 | |||
From: Michael Heimpold <mhei@heimpold.de> | |||
Date: Sat, 8 Dec 2018 10:43:01 +0100 | |||
Subject: [PATCH] One further optimization of trimming routine | |||
The last change to the trimming routine made it more efficient, | |||
however, we can even get rid of the memmove() as we leave the | |||
function with strdup() anyway. | |||
Signed-off-by: Michael Heimpold <mhei@heimpold.de> | |||
Reviewed-by: Wolfram Sang <wsa+renesas@sang-engineering.com> | |||
--- | |||
lsmmc.c | 5 ++--- | |||
1 file changed, 2 insertions(+), 3 deletions(-) | |||
diff --git a/lsmmc.c b/lsmmc.c | |||
index 06cc0b8..05d59e8 100644 | |||
--- a/lsmmc.c | |||
+++ b/lsmmc.c | |||
@@ -393,10 +393,9 @@ char *read_file(char *name) | |||
start++; | |||
len--; | |||
} | |||
- memmove(line, start, len); | |||
- line[len] = '\0'; | |||
- return strdup(line); | |||
+ start[len] = '\0'; | |||
+ return strdup(start); | |||
} | |||
/* Hexadecimal string parsing functions */ | |||
-- | |||
2.17.1 | |||