dev_dbg(&client->adapter->dev, "i2c-%d ioctl, cmd: 0x%x, arg: %lx.\n", iminor(inode),cmd, arg); 
dev_dbg(&client->adapter->dev, "ioctl, cmd=0x%02x, arg=0x%02lx\n", cmd, arg); 
static int i2cdev_ioctl(struct inode *inode, struct file *file,		unsigned int cmd, unsigned long arg){	struct i2c_client *client = (struct i2c_client *)file->private_data;	struct i2c_rdwr_ioctl_data rdwr_arg;	struct i2c_smbus_ioctl_data data_arg;	union i2c_smbus_data temp;	struct i2c_msg *rdwr_pa;	u8 __user **data_ptrs;	int i,datasize,res;	unsigned long funcs;	dev_dbg(&client->adapter->dev, "i2c-%d ioctl, cmd: 0x%x, arg: %lx.\n",		iminor(inode),cmd, arg);	switch ( cmd ) {	case I2C_SLAVE:	case I2C_SLAVE_FORCE:		if ((arg > 0x3ff) || 		    (((client->flags & I2C_M_TEN) == 0) && arg > 0x7f))			return -EINVAL;		if ((cmd == I2C_SLAVE) && i2c_check_addr(client->adapter,arg))			return -EBUSY;		client->addr = arg;		return 0;	case I2C_TENBIT:		if (arg)			client->flags |= I2C_M_TEN;		else			client->flags &= ~I2C_M_TEN;		return 0;	case I2C_PEC:		if (arg)			client->flags |= I2C_CLIENT_PEC;		else			client->flags &= ~I2C_CLIENT_PEC;		return 0;	case I2C_FUNCS:		funcs = i2c_get_functionality(client->adapter);		return (copy_to_user((unsigned long __user *)arg, &funcs,		                     sizeof(unsigned long)))?-EFAULT:0;	case I2C_RDWR:		if (copy_from_user(&rdwr_arg, 				   (struct i2c_rdwr_ioctl_data __user *)arg, 				   sizeof(rdwr_arg)))			return -EFAULT;		/* Put an arbitrary limit on the number of messages that can		 * be sent at once */		if (rdwr_arg.nmsgs > I2C_RDRW_IOCTL_MAX_MSGS)			return -EINVAL;				rdwr_pa = (struct i2c_msg *)			kmalloc(rdwr_arg.nmsgs * sizeof(struct i2c_msg), 			GFP_KERNEL);		if (rdwr_pa == NULL) return -ENOMEM;		if (copy_from_user(rdwr_pa, rdwr_arg.msgs,				   rdwr_arg.nmsgs * sizeof(struct i2c_msg))) {			kfree(rdwr_pa);			return -EFAULT;		}		data_ptrs = kmalloc(rdwr_arg.nmsgs * sizeof(u8 __user *), GFP_KERNEL);		if (data_ptrs == NULL) {			kfree(rdwr_pa);			return -ENOMEM;		}		res = 0;		for( i=0; i<rdwr_arg.nmsgs; i++ ) {			/* Limit the size of the message to a sane amount */			if (rdwr_pa[i].len > 8192) {				res = -EINVAL;				break;			}			data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;			rdwr_pa[i].buf = kmalloc(rdwr_pa[i].len, GFP_KERNEL);			if(rdwr_pa[i].buf == NULL) {				res = -ENOMEM;				break;			}			if(copy_from_user(rdwr_pa[i].buf,				data_ptrs[i],				rdwr_pa[i].len)) {					++i; /* Needs to be kfreed too */					res = -EFAULT;				break;			}		}		if (res < 0) {			int j;			for (j = 0; j < i; ++j)				kfree(rdwr_pa[j].buf);			kfree(data_ptrs);			kfree(rdwr_pa);			return res;		}		res = i2c_transfer(client->adapter,			rdwr_pa,			rdwr_arg.nmsgs);		while(i-- > 0) {			if( res>=0 && (rdwr_pa[i].flags & I2C_M_RD)) {				if(copy_to_user(					data_ptrs[i],					rdwr_pa[i].buf,					rdwr_pa[i].len)) {					res = -EFAULT;				}			}			kfree(rdwr_pa[i].buf);		}		kfree(data_ptrs);		kfree(rdwr_pa);		return res;	case I2C_SMBUS:		if (copy_from_user(&data_arg,		                   (struct i2c_smbus_ioctl_data __user *) arg,		                   sizeof(struct i2c_smbus_ioctl_data)))			return -EFAULT;		if ((data_arg.size != I2C_SMBUS_BYTE) && 		    (data_arg.size != I2C_SMBUS_QUICK) &&		    (data_arg.size != I2C_SMBUS_BYTE_DATA) && 		    (data_arg.size != I2C_SMBUS_WORD_DATA) &&		    (data_arg.size != I2C_SMBUS_PROC_CALL) &&		    (data_arg.size != I2C_SMBUS_BLOCK_DATA) &&		    (data_arg.size != I2C_SMBUS_I2C_BLOCK_DATA) &&		    (data_arg.size != I2C_SMBUS_BLOCK_PROC_CALL)) {			dev_dbg(&client->adapter->dev,				"size out of range (%x) in ioctl I2C_SMBUS.\n",				data_arg.size);			return -EINVAL;		}		/* Note that I2C_SMBUS_READ and I2C_SMBUS_WRITE are 0 and 1, 		   so the check is valid if size==I2C_SMBUS_QUICK too. */		if ((data_arg.read_write != I2C_SMBUS_READ) && 		    (data_arg.read_write != I2C_SMBUS_WRITE)) {			dev_dbg(&client->adapter->dev, 				"read_write out of range (%x) in ioctl I2C_SMBUS.\n",				data_arg.read_write);			return -EINVAL;		}		/* Note that command values are always valid! */		if ((data_arg.size == I2C_SMBUS_QUICK) ||		    ((data_arg.size == I2C_SMBUS_BYTE) && 		    (data_arg.read_write == I2C_SMBUS_WRITE)))			/* These are special: we do not use data */			return i2c_smbus_xfer(client->adapter, client->addr,					      client->flags,					      data_arg.read_write,					      data_arg.command,					      data_arg.size, NULL);		if (data_arg.data == NULL) {			dev_dbg(&client->adapter->dev,				"data is NULL pointer in ioctl I2C_SMBUS.\n");			return -EINVAL;		}		if ((data_arg.size == I2C_SMBUS_BYTE_DATA) ||		    (data_arg.size == I2C_SMBUS_BYTE))			datasize = sizeof(data_arg.data->byte);		else if ((data_arg.size == I2C_SMBUS_WORD_DATA) || 		         (data_arg.size == I2C_SMBUS_PROC_CALL))			datasize = sizeof(data_arg.data->word);		else /* size == smbus block, i2c block, or block proc. call */			datasize = sizeof(data_arg.data->block);		if ((data_arg.size == I2C_SMBUS_PROC_CALL) || 		    (data_arg.size == I2C_SMBUS_BLOCK_PROC_CALL) || 		    (data_arg.read_write == I2C_SMBUS_WRITE)) {			if (copy_from_user(&temp, data_arg.data, datasize))				return -EFAULT;		}		res = i2c_smbus_xfer(client->adapter,client->addr,client->flags,		      data_arg.read_write,		      data_arg.command,data_arg.size,&temp);		if (! res && ((data_arg.size == I2C_SMBUS_PROC_CALL) || 		              (data_arg.size == I2C_SMBUS_BLOCK_PROC_CALL) || 			      (data_arg.read_write == I2C_SMBUS_READ))) {			if (copy_to_user(data_arg.data, &temp, datasize))				return -EFAULT;		}		return res;	default:		return i2c_control(client,cmd,arg);	}	return 0;}
4520	/local/tlutelli/issta_data/temp/c/2005_temp/2005/4520/e8aafcb2bba1fe122907161701a167e38174c7a5/i2c-dev.c/clean/drivers/i2c/i2c-dev.c