[PATCH] I2C: Centralize 24RF08 corruption prevention

The 24RF08 corruption would better be prevented at i2c-core level than
at chip driver level, for several reasons:
* The second quick write should happen as soon as possible after the
  first one, so as to limit the risk that another command is issued on
  the bus inbetween, causing the corruption.
* As a matter of fact, the protection code at driver level was reworked
  at least three times already, which proves how hard it is to get it
  right there, while it's straightforward at i2c-core level.
* It's easy to add a new driver that would need the protection, and
  forget to add it. This did happen already.
* As additional probing addresses can be passed to most i2c chip drivers
  as module parameters, virtually every i2c chip driver would need the
  protection if we want to be really safe.
* Why duplicate code when we can easily avoid it?

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index bee0148..dda472e 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -679,9 +679,16 @@
 		return 0;
 
 	/* Make sure there is something at this address, unless forced */
-	if (kind < 0
-	 && i2c_smbus_xfer(adapter, addr, 0, 0, 0, I2C_SMBUS_QUICK, NULL) < 0)
-		return 0;
+	if (kind < 0) {
+		if (i2c_smbus_xfer(adapter, addr, 0, 0, 0,
+				   I2C_SMBUS_QUICK, NULL) < 0)
+			return 0;
+
+		/* prevent 24RF08 corruption */
+		if ((addr & ~0x0f) == 0x50)
+			i2c_smbus_xfer(adapter, addr, 0, 0, 0,
+				       I2C_SMBUS_QUICK, NULL);
+	}
 
 	/* Finally call the custom detection function */
 	err = found_proc(adapter, addr, kind);