Skip to contentSkip to conversation

media: v4l2-cci: Always assign *val

PATCH In review Sakari Ailus 2 participants 2 messages May 29, 2024 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: v4l2-cci: Always assign *val

Always assign *val to 0 in cci_read(). This has the benefit of not requiring initialisation of the variables data is read to using cci_read(). Once smatch is fixed, it could catch the use of uninitialised reads.

---
 drivers/media/v4l2-core/v4l2-cci.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/media/v4l2-core/v4l2-cci.c +9 -0
index ee3475bed37f..1ff94affbaf3 100644
@@ -23,6 +23,15 @@ int cci_read(struct regmap *map, u32 reg, u64 *val, int *err)
 	u8 buf[8];
 	int ret;
 
+	/*
+	 * TODO: Fix smatch. Assign *val to 0 here in order to avoid
+	 * failing a smatch check on caller when the caller proceeds to
+	 * read *val without initialising it on caller's side. *val is set
+	 * to a valid value whenever this function returns 0 but smatch
+	 * can't figure that out currently.
+	 */
+	*val = 0;
+
 	if (err && *err)
 		return *err;
 
Signature · 1 line
2.39.2
Reviewed-by on v1 1/1
#1 lore raw

Hi,

Quoted 7 lines · Sakari Ailus

Always assign *val to 0 in cci_read(). This has the benefit of not requiring initialisation of the variables data is read to using cci_read(). Once smatch is fixed, it could catch the use of uninitialised reads.

Thanks, patch looks good to me:

Regards,

Hans

Quoted 24 lines
---
 drivers/media/v4l2-core/v4l2-cci.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/media/v4l2-core/v4l2-cci.c +9 -0
index ee3475bed37f..1ff94affbaf3 100644
@@ -23,6 +23,15 @@ int cci_read(struct regmap *map, u32 reg, u64 *val, int *err)
 	u8 buf[8];
 	int ret;
 
+	/*
+	 * TODO: Fix smatch. Assign *val to 0 here in order to avoid
+	 * failing a smatch check on caller when the caller proceeds to
+	 * read *val without initialising it on caller's side. *val is set
+	 * to a valid value whenever this function returns 0 but smatch
+	 * can't figure that out currently.
+	 */
+	*val = 0;
+
 	if (err && *err)
 		return *err;