[i2c] [patch 2.6.23-rc9] remove i2c_algorithm.algo_control(); cleanup

David Brownell david-b at pacbell.net
Thu Oct 4 04:21:02 CEST 2007


This removes:

 - An effectively unused hook:  i2c_algorithm.algo_control.

 - The i2c_control() call, used only by i2c-dev to call that
   unused hook or set two barely supported adapter params.

   (That param setting moves into i2c-dev.c ... still iffy
   due to lack of locking, but no other changes.)

As shown by diffstat, this is a net code shrink.  It also reduces the
complexity of the I2C adapter and /dev interfaces.

Signed-off-by: David Brownell <dbrownell at users.sourceforge.net>
---
The main potential issue with this is fixing a bug in how i2c-dev
implements unsupported ioctl requests:  it finally reports the error
to userspace.  If needed, the bug could be perpetuated for a while. 

 drivers/i2c/i2c-core.c |   22 ----------------------
 drivers/i2c/i2c-dev.c  |   14 ++++++++++++--
 include/linux/i2c.h    |    7 -------
 3 files changed, 12 insertions(+), 31 deletions(-)

--- a/include/linux/i2c.h	2007-10-03 17:50:40.000000000 -0700
+++ b/include/linux/i2c.h	2007-10-03 19:09:52.000000000 -0700
@@ -292,9 +292,6 @@ struct i2c_algorithm {
 	                   unsigned short flags, char read_write,
 	                   u8 command, int size, union i2c_smbus_data * data);
 
-	/* --- ioctl like call to set div. parameters. */
-	int (*algo_control)(struct i2c_adapter *, unsigned int, unsigned long);
-
 	/* To determine what the adapter supports */
 	u32 (*functionality) (struct i2c_adapter *);
 };
@@ -418,10 +415,6 @@ extern int i2c_probe(struct i2c_adapter 
 		struct i2c_client_address_data *address_data,
 		int (*found_proc) (struct i2c_adapter *, int, int));
 
-/* An ioctl like call to set div. parameters of the adapter.
- */
-extern int i2c_control(struct i2c_client *,unsigned int, unsigned long);
-
 extern struct i2c_adapter* i2c_get_adapter(int id);
 extern void i2c_put_adapter(struct i2c_adapter *adap);
 
--- a/drivers/i2c/i2c-dev.c	2007-10-03 14:12:34.000000000 -0700
+++ b/drivers/i2c/i2c-dev.c	2007-10-03 19:09:35.000000000 -0700
@@ -393,9 +393,19 @@ static int i2cdev_ioctl(struct inode *in
 				return -EFAULT;
 		}
 		return res;
-
+	case I2C_RETRIES:
+		client->adapter->retries = arg;
+		break;
+	case I2C_TIMEOUT:
+		client->adapter->timeout = arg;
+		break;
 	default:
-		return i2c_control(client,cmd,arg);
+		/* NOTE:  returning a fault code here could cause trouble
+		 * in buggy userspace code.  Some old kernel bugs returned
+		 * zero in this case, and userspace code might accidentally
+		 * have depended on that bug.
+		 */
+		return -ENOTTY;
 	}
 	return 0;
 }
--- a/drivers/i2c/i2c-core.c	2007-10-03 14:12:34.000000000 -0700
+++ b/drivers/i2c/i2c-core.c	2007-10-03 17:50:43.000000000 -0700
@@ -936,28 +936,6 @@ int i2c_master_recv(struct i2c_client *c
 }
 EXPORT_SYMBOL(i2c_master_recv);
 
-int i2c_control(struct i2c_client *client,
-	unsigned int cmd, unsigned long arg)
-{
-	int ret = 0;
-	struct i2c_adapter *adap = client->adapter;
-
-	dev_dbg(&client->adapter->dev, "i2c ioctl, cmd: 0x%x, arg: %#lx\n", cmd, arg);
-	switch (cmd) {
-		case I2C_RETRIES:
-			adap->retries = arg;
-			break;
-		case I2C_TIMEOUT:
-			adap->timeout = arg;
-			break;
-		default:
-			if (adap->algo->algo_control!=NULL)
-				ret = adap->algo->algo_control(adap,cmd,arg);
-	}
-	return ret;
-}
-EXPORT_SYMBOL(i2c_control);
-
 /* ----------------------------------------------------
  * the i2c address scanning function
  * Will not work for 10-bit addresses!



More information about the i2c mailing list