소스 검색

i2c-dev: Clarify the unit of ioctl I2C_TIMEOUT

The unit in which user-space can set the bus timeout value is jiffies
for historical reasons (back when HZ was always 100.) This is however
not good because user-space doesn't know how long a jiffy lasts. The
timeout value should instead be set in a fixed time unit. Given the
original value of HZ, this unit should be 10 ms, for compatibility.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Acked-by: Wolfram Sang <w.sang@pengutronix.de>
Jean Delvare 16 년 전
부모
커밋
cd97f39b7c
3개의 변경된 파일7개의 추가작업 그리고 3개의 파일을 삭제
  1. 5 1
      drivers/i2c/i2c-dev.c
  2. 1 1
      include/linux/i2c-dev.h
  3. 1 1
      include/linux/i2c.h

+ 5 - 1
drivers/i2c/i2c-dev.c

@@ -35,6 +35,7 @@
 #include <linux/i2c.h>
 #include <linux/i2c.h>
 #include <linux/i2c-dev.h>
 #include <linux/i2c-dev.h>
 #include <linux/smp_lock.h>
 #include <linux/smp_lock.h>
+#include <linux/jiffies.h>
 #include <asm/uaccess.h>
 #include <asm/uaccess.h>
 
 
 static struct i2c_driver i2cdev_driver;
 static struct i2c_driver i2cdev_driver;
@@ -422,7 +423,10 @@ static long i2cdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 		client->adapter->retries = arg;
 		client->adapter->retries = arg;
 		break;
 		break;
 	case I2C_TIMEOUT:
 	case I2C_TIMEOUT:
-		client->adapter->timeout = arg;
+		/* For historical reasons, user-space sets the timeout
+		 * value in units of 10 ms.
+		 */
+		client->adapter->timeout = msecs_to_jiffies(arg * 10);
 		break;
 		break;
 	default:
 	default:
 		/* NOTE:  returning a fault code here could cause trouble
 		/* NOTE:  returning a fault code here could cause trouble

+ 1 - 1
include/linux/i2c-dev.h

@@ -33,7 +33,7 @@
  */
  */
 #define I2C_RETRIES	0x0701	/* number of times a device address should
 #define I2C_RETRIES	0x0701	/* number of times a device address should
 				   be polled when not acknowledging */
 				   be polled when not acknowledging */
-#define I2C_TIMEOUT	0x0702	/* set timeout in jiffies - call with int */
+#define I2C_TIMEOUT	0x0702	/* set timeout in units of 10 ms */
 
 
 /* NOTE: Slave address is 7 or 10 bits, but 10-bit addresses
 /* NOTE: Slave address is 7 or 10 bits, but 10-bit addresses
  * are NOT supported! (due to code brokenness)
  * are NOT supported! (due to code brokenness)

+ 1 - 1
include/linux/i2c.h

@@ -361,7 +361,7 @@ struct i2c_adapter {
 	struct mutex bus_lock;
 	struct mutex bus_lock;
 	struct mutex clist_lock;
 	struct mutex clist_lock;
 
 
-	int timeout;
+	int timeout;			/* in jiffies */
 	int retries;
 	int retries;
 	struct device dev;		/* the adapter device */
 	struct device dev;		/* the adapter device */