Re: bug in sys/dev/[extres]/nvmem/nvmem.c

titus <[email protected]>
Newsgroups gmane.os.freebsd.devel.arm
Message-ID <[email protected]>
this is the patch that actually works and contains 
source, header, man page and aw_thermal diffs
p3.txt (text/plain, 3 KB)
--- /usr/src/sys/arm/allwinner/aw_thermal.c	2025-06-06 03:04:21.000000000 +0300
+++ ./usr/src/sys/arm/allwinner/aw_thermal.c	2025-11-23 11:07:48.760793000 +0200
@@ -379,16 +379,17 @@
 aw_thermal_init(struct aw_thermal_softc *sc)
 {
 	phandle_t node;
-	uint32_t calib[2];
+	uint32_t calib[2], clen;
 	int error;
 
 	node = ofw_bus_get_node(sc->dev);
-	if (nvmem_get_cell_len(node, "calibration") > sizeof(calib)) {
+	if (nvmem_get_cell_len(node, "calibration", &clen) ||
+		 clen > sizeof(calib)) {
 		device_printf(sc->dev, "calibration nvmem cell is too large\n");
 		return (ENXIO);
 	}
 	error = nvmem_read_cell_by_name(node, "calibration",
-	    (void *)&calib, nvmem_get_cell_len(node, "calibration"));
+	    (void *)&calib, clen);
 	/* Read calibration settings from EFUSE */
 	if (error != 0) {
 		device_printf(sc->dev, "Cannot read THS efuse\n");
--- /usr/src/sys/dev/extres/nvmem/nvmem.h	2025-06-06 03:04:24.000000000 +0300
+++ ./usr/src/sys/dev/extres/nvmem/nvmem.h	2025-11-23 10:38:13.190824000 +0200
@@ -26,7 +26,7 @@
 #ifndef _DEV_EXTRES_NVMEM_H_
 #define _DEV_EXTRES_NVMEM_H_
 
-int nvmem_get_cell_len(phandle_t node, const char *name);
+int nvmem_get_cell_len(phandle_t node, const char *name, uint32_t *len);
 int nvmem_read_cell_by_name(phandle_t node, const char *name, void *cell, size_t buflen);
 int nvmem_read_cell_by_idx(phandle_t node, int idx, void *cell, size_t buflen);
 int nvmem_write_cell_by_name(phandle_t node, const char *name, void *cell, size_t buflen);
--- /usr/src/sys/dev/extres/nvmem/nvmem.c	2025-06-06 03:04:24.000000000 +0300
+++ ./usr/src/sys/dev/extres/nvmem/nvmem.c	2025-11-22 10:51:16.402488000 +0200
@@ -68,7 +68,7 @@
 }
 
 int
-nvmem_get_cell_len(phandle_t node, const char *name)
+nvmem_get_cell_len(phandle_t node, const char *name, uint32_t *len)
 {
 	phandle_t cell_node;
 	uint32_t reg[2];
@@ -89,7 +89,8 @@
 		return (ENOENT);
 	}
 
-	return (reg[1]);
+	*len = reg[1];
+	return (0);
 }
 
 int
--- /usr/src/share/man/man9/nvmem.9	2025-06-06 03:04:21.000000000 +0300
+++ ./usr/src/share/man/man9/nvmem.9	2025-11-23 09:55:14.589304000 +0200
@@ -35,7 +35,7 @@
 .Cd "device nvmem"
 .In sys/extres/nvmem/nvmem.h
 .Ft int
-.Fn nvmem_get_cell_len "phandle_t node" "const char *name"
+.Fn nvmem_get_cell_len "phandle_t node" "const char *name" "uint32_t *len"
 .Ft int
 .Fn nvmem_read_cell_by_name "phandle_t node" "const char *name" "void *cell" "size_t buflen"
 .Ft int
@@ -54,9 +54,9 @@
 providers.
 .Sh FUNCTIONS
 .Bl -tag -width indent
-.It Fn nvmem_get_cell_len  "phandle_t node" "const char *name"
+.It Fn nvmem_get_cell_len  "phandle_t node" "const char *name" "uint32_t *len"
 Get the size of the cell base on the reg property on the node.
-Return the size or ENOENT if the cell name wasn't found
+Return 0 and store the size at *len on success or ENOENT if the cell name wasn't found
 .It Fn nvmem_read_cell_by_name "phandle_t node" "const char *name" "void *cell" "size_t buflen"
 Get the cell content based on the name.
 Return 0 on sucess or ENOENT if the cell doesn't exists, ENXIO if no provider device was found,
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.