Quellcode durchsuchen

msm: camera: sensor: Check the result of i2c transfer

The i2c transfer interface returns the num of message is
processed if there is no issue, this change checks if the
result of i2c transfer is same with the num of message,
the return value is assigned as 0 if they are same.

CRs-Fixed: 3495774
Change-Id: I408038120ac2371f1ed031daa364c2e2563e3606
Signed-off-by: Depeng Shao <[email protected]>
Depeng Shao vor 2 Jahren
Ursprung
Commit
a219b9f118
1 geänderte Dateien mit 30 neuen und 13 gelöschten Zeilen
  1. 30 13
      drivers/cam_sensor_module/cam_sensor_io/cam_sensor_qup_i2c.c

+ 30 - 13
drivers/cam_sensor_module/cam_sensor_io/cam_sensor_qup_i2c.c

@@ -22,6 +22,7 @@ static int32_t cam_qup_i2c_rxdata(
 {
 	int32_t rc = 0;
 	uint16_t saddr = dev_client->addr >> 1;
+	int i2c_msg_size = 2;
 	struct i2c_msg msgs[] = {
 		{
 			.addr  = saddr,
@@ -36,15 +37,21 @@ static int32_t cam_qup_i2c_rxdata(
 			.buf   = rxdata,
 		},
 	};
-	rc = i2c_transfer(dev_client->adapter, msgs, 2);
+	rc = i2c_transfer(dev_client->adapter, msgs, i2c_msg_size);
 	if (rc < 0) {
 		CAM_ERR(CAM_SENSOR, "failed 0x%x", saddr);
 		return rc;
 	}
-	/* Returns negative errno */
-	/* else the number of messages executed. */
-	/* So positive values are not errors. */
-	return 0;
+
+	if (rc == i2c_msg_size)
+		rc = 0;
+	else {
+		CAM_ERR(CAM_SENSOR, "i2c transfer failed, i2c_msg_size:%d rc:%d",
+			i2c_msg_size, rc);
+		rc = -EIO;
+	}
+
+	return rc;
 }
 
 static inline void  cam_qup_i2c_txdata_fill(
@@ -63,6 +70,7 @@ static int32_t cam_qup_i2c_txdata(
 {
 	int32_t rc = 0;
 	uint16_t saddr = dev_client->client->addr >> 1;
+	int i2c_msg_size = 1;
 	struct i2c_msg msg[] = {
 		{
 			.addr = saddr,
@@ -71,15 +79,16 @@ static int32_t cam_qup_i2c_txdata(
 			.buf = txdata,
 		 },
 	};
-	rc = i2c_transfer(dev_client->client->adapter, msg, 1);
-	if (rc < 0) {
-		CAM_ERR(CAM_SENSOR, "failed 0x%x", saddr);
-		return rc;
+	rc = i2c_transfer(dev_client->client->adapter, msg, i2c_msg_size);
+	if (rc == i2c_msg_size)
+		rc = 0;
+	else {
+		CAM_ERR(CAM_SENSOR, "i2c transfer failed, i2c_msg_size:%d rc:%d",
+			i2c_msg_size, rc);
+		rc = -EIO;
 	}
-	/* Returns negative errno, */
-	/* else the number of messages executed. */
-	/* So positive values are not errors. */
-	return 0;
+
+	return rc;
 }
 
 int32_t cam_qup_i2c_read(struct i2c_client *client,
@@ -428,6 +437,14 @@ int32_t cam_qup_i2c_write_table(struct camera_io_master *client,
 		usleep_range(write_setting->delay * 1000, (write_setting->delay
 			* 1000) + 1000);
 
+	if (rc == i2c_msg_size)
+		rc = 0;
+	else {
+		CAM_ERR(CAM_SENSOR, "i2c transfer failed, i2c_msg_size:%d rc:%d",
+			i2c_msg_size, rc);
+		rc = -EIO;
+	}
+
 deallocate_buffer:
 	kfree(buf);
 	kfree(msgs);