Skip to contentSkip to conversation

drm/panel: dsi-cm: Normalize mipi_dsi_dcs_read/write() return values

PATCH New Ian Rogers 1 participant 1 message Nov 19

Subsystems (3)
lore
Share & tools
lore

Ian Rogers

author
#0 lore raw

PATCH 1/1 drm/panel: dsi-cm: Normalize mipi_dsi_dcs_read/write() return values

When commit d4cf15372868 ("drm/omap: panel-dsi-cm: use DSI helpers") converted dsicm_dcs_read_1() and dsicm_dcs_write_1() to mipi_dsi_dcs_read() and mipi_dsi_dcs_write(), all callers in panel-dsi-cm continued to check 'if (r)' expecting 0 on success and a negative errno on failure. While OMAP's dsi_vc_dcs_read() populates the buffer and returns 0 on a successful read, mipi_dsi_dcs_read() on standard MIPI DSI hosts and mipi_dsi_dcs_write() return the positive byte count transferred on success:

1. A 1-byte DCS read returning 1 causes dsicm_get_id(), num_dsi_errors_show(), and hw_revision_show() to treat success as a non-zero return value (exposing 1 byte of uninitialized sysfs buffer).
2. If a DSI host returns 0 without writing the output byte, dsicm_power_on() and hw_revision_show() read uninitialized stack bytes (id1, id2, id3).
3. A successful 2-byte DCS write returns 2, causing dsicm_power_on() to abort at 'if (r) goto err;'.

Normalize both dsicm_dcs_read_1() and dsicm_dcs_write_1() to propagate negative error codes and return 0 on non-negative return values (handling both OMAP DSI returning 0 and standard DSI hosts returning byte counts), zero-initialize *data in dsicm_dcs_read_1(), and zero-initialize id1, id2, and id3 in hw_revision_show().

Found via an x86_64 LLVM=1 (Clang 21.1.8) allyesconfig audit with -Wconditional-uninitialized enabled; fix and changelog drafted with an AI coding assistant. Verified with a C unit test and build-tested under LLVM=1 W=1 (-Werror) and -Wconditional-uninitialized; not tested on DSI command-mode panel hardware.

Fixes d4cf15372868 ("drm/omap: panel-dsi-cm: use DSI helpers")
---
 drivers/gpu/drm/panel/panel-dsi-cm.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
drivers/gpu/drm/panel/panel-dsi-cm.c +16 -3
index ae6e9ffc46cb..1b40fe4f08d8 100644
@@ -109,12 +109,25 @@ static void hw_guard_wait(struct panel_drv_data *ddata)
 
 static int dsicm_dcs_read_1(struct panel_drv_data *ddata, u8 dcs_cmd, u8 *data)
 {
-	return mipi_dsi_dcs_read(ddata->dsi, dcs_cmd, data, 1);
+	ssize_t ret;
+
+	*data = 0;
+	ret = mipi_dsi_dcs_read(ddata->dsi, dcs_cmd, data, 1);
+	if (ret < 0)
+		return ret;
+
+	return 0;
 }
 
 static int dsicm_dcs_write_1(struct panel_drv_data *ddata, u8 dcs_cmd, u8 param)
 {
-	return mipi_dsi_dcs_write(ddata->dsi, dcs_cmd, &param, 1);
+	ssize_t ret;
+
+	ret = mipi_dsi_dcs_write(ddata->dsi, dcs_cmd, &param, 1);
+	if (ret < 0)
+		return ret;
+
+	return 0;
 }
 
 static int dsicm_sleep_in(struct panel_drv_data *ddata)
@@ -238,7 +251,7 @@ static ssize_t hw_revision_show(struct device *dev,
 		struct device_attribute *attr, char *buf)
 {
 	struct panel_drv_data *ddata = dev_get_drvdata(dev);
-	u8 id1, id2, id3;
+	u8 id1 = 0, id2 = 0, id3 = 0;
 	int r = -ENODEV;
 
 	mutex_lock(&ddata->lock);
Signature · 1 line
2.56.1.708.g77570a6a1d-goog