Exemple #1
0
int vfc_get_video_ioctl(struct inode *inode, struct file *file, 
			struct vfc_dev *dev, unsigned long arg) 
{
	int ret=0;
	unsigned int status=NO_LOCK;
	unsigned char buf[1];

	if(vfc_i2c_recvbuf(dev,VFC_SAA9051_ADDR,buf,1)) {
		printk(KERN_ERR "vfc%d: Unable to get status\n",dev->instance);
		return -EIO;
	}

	if(buf[0] & VFC_SAA9051_HLOCK) {
		status = NO_LOCK;
	} else if(buf[0] & VFC_SAA9051_FD) {
		if(buf[0] & VFC_SAA9051_CD)
			status=NTSC_COLOR;
		else
			status=NTSC_NOCOLOR;
	} else {
		if(buf[0] & VFC_SAA9051_CD)
			status=PAL_COLOR;
		else
			status=PAL_NOCOLOR;
	}
	VFC_IOCTL_DEBUG_PRINTK(("vfc%d: IOCTL(VFCGVID) returning status 0x%x; buf[0]=%x\n",dev->instance,
			  status,buf[0]));
	if (copy_to_user((void *)arg,&status,sizeof(unsigned int))) {
		VFC_IOCTL_DEBUG_PRINTK(("vfc%d: User passed bogus pointer to "
				 "vfc_get_video_ioctl\n",dev->instance));
		return ret;
	}
	return ret;
}
Exemple #2
0
static int vfc_debug(struct vfc_dev *dev, int cmd, unsigned long arg) 
{
	struct vfc_debug_inout inout;
	unsigned char *buffer;

	if (!capable(CAP_SYS_ADMIN))
		return -EPERM;

	switch(cmd) {
	case VFC_I2C_SEND:
		if(copy_from_user(&inout, (void *)arg, sizeof(inout)))
			return -EFAULT;

		buffer = kmalloc(inout.len*sizeof(char), GFP_KERNEL);
		if (buffer == NULL)
			return -ENOMEM;

		if(copy_from_user(buffer, inout.buffer, 
				  inout.len*sizeof(char))) {
			kfree(buffer);
			return -EFAULT;
		}
		

		vfc_lock_device(dev);
		inout.ret=
			vfc_i2c_sendbuf(dev,inout.addr & 0xff,
					inout.buffer,inout.len);

		if (copy_to_user((void *)arg,&inout,sizeof(inout))) {
			kfree(buffer);
			return -EFAULT;
		}
		vfc_unlock_device(dev);

		break;
	case VFC_I2C_RECV:
		if (copy_from_user(&inout, (void *)arg, sizeof(inout)))
			return -EFAULT;

		buffer = kmalloc(inout.len, GFP_KERNEL);
		if (buffer == NULL)
			return -ENOMEM;

		memset(buffer,0,inout.len*sizeof(char));
		vfc_lock_device(dev);
		inout.ret=
			vfc_i2c_recvbuf(dev,inout.addr & 0xff
					,buffer,inout.len);
		vfc_unlock_device(dev);
		
		if (copy_to_user(inout.buffer, buffer, inout.len)) {
			kfree(buffer);
			return -EFAULT;
		}
		if (copy_to_user((void *)arg,&inout,sizeof(inout))) {
			kfree(buffer);
			return -EFAULT;
		}
		kfree(buffer);
		break;
	default:
		return -EINVAL;
	};

	return 0;
}