summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorge Moussalem2025-02-06 18:05:54 +0000
committerChristian Marangi2025-02-19 08:40:21 +0000
commit02481fb1d9045853da17c339e510649b2a97079c (patch)
tree97e9ed859e4dcc6eb5daac0320d8c791b15985e2
parent08f5a13db1374f24ee4cb7613ef81c6b65eb00a3 (diff)
downloadopenwrt-02481fb1d9045853da17c339e510649b2a97079c.tar.gz
nvmem: layouts: ascii-env handle CRLF while parsing
Add validation and support for parsing of name/value pairs with CRLF line endings. Signed-off-by: George Moussalem <george.moussalem@outlook.com> Link: https://github.com/openwrt/openwrt/pull/17935 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
-rw-r--r--target/linux/generic/pending-6.6/809-03-nvmem-layouts-ascii-env-handle-CRLF-while-parsing.patch58
1 files changed, 58 insertions, 0 deletions
diff --git a/target/linux/generic/pending-6.6/809-03-nvmem-layouts-ascii-env-handle-CRLF-while-parsing.patch b/target/linux/generic/pending-6.6/809-03-nvmem-layouts-ascii-env-handle-CRLF-while-parsing.patch
new file mode 100644
index 0000000000..ab5fc58d0e
--- /dev/null
+++ b/target/linux/generic/pending-6.6/809-03-nvmem-layouts-ascii-env-handle-CRLF-while-parsing.patch
@@ -0,0 +1,58 @@
+From: George Moussalem <george.moussalem@outlook.com>
+Date: Thu, 06 Feb 2025 21:55:28 +0400
+Subject: [PATCH] nvmem: layouts: ascii-env handle CRLF while parsing
+
+The current driver supports LF line endings only.
+
+For CRLF-based line endings in the ASCII env, the length of the value of
+the variable passed to nvmem_layout_parse_mac_base is 18 bytes instead
+of an expected length of 17 causing the parsing to fail.
+So, let's add the ability to handle CRLF line endings by adding a
+condition to check if the value ends with a '\r' character and replace it
+with '\0' to properly parse the mac address.
+
+Tested on Linksys MX2000, MX5500, and SPNMX56.
+
+Signed-off-by: George Moussalem <george.moussalem@outlook.com>
+---
+--- a/drivers/nvmem/layouts/ascii-env.c
++++ b/drivers/nvmem/layouts/ascii-env.c
+@@ -25,18 +25,20 @@ struct ascii_env_match_data {
+ static int ascii_env_parse_cells(struct device *dev, struct nvmem_device *nvmem, uint8_t *buf,
+ size_t data_len, const char delim)
+ {
+- char *var, *value, *eq, *lf;
++ char *var, *value, *eq, *lf, *cr;
+ char *data = buf;
++ uint incr = 0;
+
+ /*
+ * Warning the inner loop take care of replacing '\n'
+ * with '\0', hence we can use strlen on value.
+ */
+ for (var = data; var < data + data_len && *var;
+- var = value + strlen(value) + 1) {
++ var = value + strlen(value) + incr) {
+ struct nvmem_cell_info info = {};
+ struct device_node *child;
+ const char *label;
++ incr = 0;
+
+ eq = strchr(var, delim);
+ if (!eq)
+@@ -49,6 +51,15 @@ static int ascii_env_parse_cells(struct
+ if (!lf)
+ break;
+ *lf = '\0';
++ incr++;
++
++ /* For CRLF based env, replace '\r' with '\0' too to use strlen
++ * for value, and increment var by one in loop for next variable */
++ cr = strchr(value, '\r');
++ if (cr) {
++ *cr = '\0';
++ incr++;
++ }
+
+ info.name = devm_kstrdup(dev, var, GFP_KERNEL);
+ if (!info.name)