[1/2] media: v4l2-cci: Allow "empty read"

Message ID 20240807-imx290-avail-v1-1-666c130c7601@skidata.com (mailing list archive)
State Changes Requested
Delegated to: Sakari Ailus
Headers
Series media: i2c: imx290: check for availability in probe() |

Commit Message

Benjamin Bara Aug. 7, 2024, 8:10 a.m. UTC
  Make the read pointer optional for cases where only the return value is
of interest. This could be the case for availability checks during
probe().

Signed-off-by: Benjamin Bara <benjamin.bara@skidata.com>
---
 drivers/media/v4l2-core/v4l2-cci.c | 5 ++++-
 include/media/v4l2-cci.h           | 2 +-
 2 files changed, 5 insertions(+), 2 deletions(-)
  

Patch

diff --git a/drivers/media/v4l2-core/v4l2-cci.c b/drivers/media/v4l2-core/v4l2-cci.c
index 1ff94affbaf3..c402e0377a57 100644
--- a/drivers/media/v4l2-core/v4l2-cci.c
+++ b/drivers/media/v4l2-core/v4l2-cci.c
@@ -30,7 +30,8 @@  int cci_read(struct regmap *map, u32 reg, u64 *val, int *err)
 	 * to a valid value whenever this function returns 0 but smatch
 	 * can't figure that out currently.
 	 */
-	*val = 0;
+	if (val)
+		*val = 0;
 
 	if (err && *err)
 		return *err;
@@ -45,6 +46,8 @@  int cci_read(struct regmap *map, u32 reg, u64 *val, int *err)
 			reg, ret);
 		goto out;
 	}
+	if (!val)
+		goto out;
 
 	switch (len) {
 	case 1:
diff --git a/include/media/v4l2-cci.h b/include/media/v4l2-cci.h
index 4e96e90ee636..ef5e0d875e68 100644
--- a/include/media/v4l2-cci.h
+++ b/include/media/v4l2-cci.h
@@ -60,7 +60,7 @@  struct cci_reg_sequence {
  *
  * @map: Register map to read from
  * @reg: Register address to read, use CCI_REG#() macros to encode reg width
- * @val: Pointer to store read value
+ * @val: Optional pointer to store read value
  * @err: Optional pointer to store errors, if a previous error is set
  *       then the read will be skipped
  *