V4L/DVB (6465): Use correct error codes when chip is not recognized

If the chip isn't recognized, then the correct errors should be returned.
The v4l2_i2c_attach() utility function will return 0 for all errors
except -ENOMEM to provide proper compatibility support for the old I2C
probing function.

Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
diff --git a/drivers/media/video/cs53l32a.c b/drivers/media/video/cs53l32a.c
index e43febb..65bb6af 100644
--- a/drivers/media/video/cs53l32a.c
+++ b/drivers/media/video/cs53l32a.c
@@ -140,7 +140,7 @@
 
 	/* Check if the adapter supports the needed features */
 	if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
-		return 0;
+		return -EIO;
 
 	snprintf(client->name, sizeof(client->name) - 1, "cs53l32a");
 
diff --git a/drivers/media/video/cx25840/cx25840-core.c b/drivers/media/video/cx25840/cx25840-core.c
index 1556e2f..6d2ca82 100644
--- a/drivers/media/video/cx25840/cx25840-core.c
+++ b/drivers/media/video/cx25840/cx25840-core.c
@@ -1078,6 +1078,10 @@
 	u32 id;
 	u16 device_id;
 
+	/* Check if the adapter supports the needed features */
+	if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
+		return -EIO;
+
 	v4l_dbg(1, cx25840_debug, client, "detecting cx25840 client on address 0x%x\n", client->addr << 1);
 
 	device_id = cx25840_read(client, 0x101) << 8;
@@ -1093,7 +1097,7 @@
 	}
 	else {
 		v4l_dbg(1, cx25840_debug, client, "cx25840 not found\n");
-		return 0;
+		return -ENODEV;
 	}
 
 	state = kzalloc(sizeof(struct cx25840_state), GFP_KERNEL);
diff --git a/drivers/media/video/msp3400-driver.c b/drivers/media/video/msp3400-driver.c
index f2946ac..f4c1460 100644
--- a/drivers/media/video/msp3400-driver.c
+++ b/drivers/media/video/msp3400-driver.c
@@ -812,7 +812,7 @@
 
 	if (msp_reset(client) == -1) {
 		v4l_dbg(1, msp_debug, client, "msp3400 not found\n");
-		return 0;
+		return -ENODEV;
 	}
 
 	state = kzalloc(sizeof(*state), GFP_KERNEL);
@@ -844,7 +844,7 @@
 	if (state->rev1 == -1 || (state->rev1 == 0 && state->rev2 == 0)) {
 		v4l_dbg(1, msp_debug, client, "not an msp3400 (cannot read chip version)\n");
 		kfree(state);
-		return 0;
+		return -ENODEV;
 	}
 
 	msp_set_audio(client);
diff --git a/drivers/media/video/saa7115.c b/drivers/media/video/saa7115.c
index ad60335..41e5e51 100644
--- a/drivers/media/video/saa7115.c
+++ b/drivers/media/video/saa7115.c
@@ -1459,7 +1459,7 @@
 
 	/* Check if the adapter supports the needed features */
 	if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
-		return 0;
+		return -EIO;
 
 	snprintf(client->name, sizeof(client->name) - 1, "saa7115");
 
@@ -1478,7 +1478,7 @@
 	if (memcmp(name, "1f711", 5)) {
 		v4l_dbg(1, debug, client, "chip found @ 0x%x (ID %s) does not match a known saa711x chip.\n",
 			client->addr << 1, name);
-		return 0;
+		return -ENODEV;
 	}
 
 	snprintf(client->name, sizeof(client->name) - 1, "saa711%d",chip_id);
diff --git a/drivers/media/video/saa7127.c b/drivers/media/video/saa7127.c
index 958ecc7..0262acd 100644
--- a/drivers/media/video/saa7127.c
+++ b/drivers/media/video/saa7127.c
@@ -671,7 +671,7 @@
 
 	/* Check if the adapter supports the needed features */
 	if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
-		return 0;
+		return -EIO;
 
 	snprintf(client->name, sizeof(client->name) - 1, "saa7127");
 
@@ -685,12 +685,12 @@
 	if ((saa7127_read(client, 0) & 0xe4) != 0 ||
 			(saa7127_read(client, 0x29) & 0x3f) != 0x1d) {
 		v4l_dbg(1, debug, client, "saa7127 not found\n");
-		return 0;
+		return -ENODEV;
 	}
 	state = kzalloc(sizeof(struct saa7127_state), GFP_KERNEL);
 
 	if (state == NULL) {
-		return (-ENOMEM);
+		return -ENOMEM;
 	}
 
 	i2c_set_clientdata(client, state);
diff --git a/drivers/media/video/tlv320aic23b.c b/drivers/media/video/tlv320aic23b.c
index 0282f38..e906528 100644
--- a/drivers/media/video/tlv320aic23b.c
+++ b/drivers/media/video/tlv320aic23b.c
@@ -133,7 +133,7 @@
 
 	/* Check if the adapter supports the needed features */
 	if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
-		return 0;
+		return -EIO;
 
 	v4l_info(client, "chip found @ 0x%x (%s)\n", client->addr << 1, client->adapter->name);
 
diff --git a/drivers/media/video/upd64031a.c b/drivers/media/video/upd64031a.c
index b060ce3..0318432 100644
--- a/drivers/media/video/upd64031a.c
+++ b/drivers/media/video/upd64031a.c
@@ -200,7 +200,7 @@
 	int i;
 
 	if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
-		return 0;
+		return -EIO;
 
 	v4l_info(client, "chip found @ 0x%x (%s)\n", client->addr << 1, client->adapter->name);
 
diff --git a/drivers/media/video/upd64083.c b/drivers/media/video/upd64083.c
index 08d2d64..7e32c5b 100644
--- a/drivers/media/video/upd64083.c
+++ b/drivers/media/video/upd64083.c
@@ -178,7 +178,7 @@
 	int i;
 
 	if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
-		return 0;
+		return -EIO;
 
 	v4l_info(client, "chip found @ 0x%x (%s)\n", client->addr << 1, client->adapter->name);
 
diff --git a/drivers/media/video/v4l2-common.c b/drivers/media/video/v4l2-common.c
index 32607a6..61ebdb0 100644
--- a/drivers/media/video/v4l2-common.c
+++ b/drivers/media/video/v4l2-common.c
@@ -1037,7 +1037,7 @@
 	else {
 		kfree(client);
 	}
-	return err;
+	return err != -ENOMEM ? 0 : err;
 }
 
 /* ----------------------------------------------------------------- */
diff --git a/drivers/media/video/vp27smpx.c b/drivers/media/video/vp27smpx.c
index 24a9423..97e2476 100644
--- a/drivers/media/video/vp27smpx.c
+++ b/drivers/media/video/vp27smpx.c
@@ -131,7 +131,7 @@
 
 	/* Check if the adapter supports the needed features */
 	if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
-		return 0;
+		return -EIO;
 
 	snprintf(client->name, sizeof(client->name) - 1, "vp27smpx");
 
diff --git a/drivers/media/video/wm8739.c b/drivers/media/video/wm8739.c
index 459228a..3d9e709 100644
--- a/drivers/media/video/wm8739.c
+++ b/drivers/media/video/wm8739.c
@@ -264,6 +264,10 @@
 {
 	struct wm8739_state *state;
 
+	/* Check if the adapter supports the needed features */
+	if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
+		return -EIO;
+
 	v4l_info(client, "chip found @ 0x%x (%s)\n", client->addr << 1, client->adapter->name);
 
 	state = kmalloc(sizeof(struct wm8739_state), GFP_KERNEL);