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

titus <[email protected]>
Newsgroups gmane.os.freebsd.devel.arm
Message-ID <[email protected]>
the return of the function nvmem_get_cell_len does not really tell if it was succesful or not

it is only used in sys/arm/allwinner/aw_thermal.c
proposed patch
p1.txt (text/plain, 1010 B)
--- /sys/dev/extres/nvmem/nvmem.c	2025-06-06 03:04:24.000000000 +0300
+++ 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
--- /sys/arm/allwinner/aw_thermal.c	2025-06-06 03:04:21.000000000 +0300
+++ sys/arm/allwinner/aw_thermal.c	2025-11-22 10:53:56.015662000 +0200
@@ -379,11 +379,12 @@
 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);
 	}
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.