Commit 52ebc763 authored by Trent Piepho's avatar Trent Piepho Committed by Mauro Carvalho Chehab
Browse files

V4L/DVB (5146): Make VIDIOC_INT_[SG]_REGISTER ioctls no longer internal only



The direct register access ioctls were defined as kernel internal only,
but they are very useful for debugging hardware from userspace and are
used as such.  Officially export them.

VIDIOC_INT_[SG]_REGISTER is renamed to VIDIOC_DBG_[SG]_REGISTER 
Definition of ioctl and struct v4l2_register is moved from v4l2-common.h 
to videodev2.h.

Types used in struct v4l2_register are changed to the userspace 
exportable versions (u32 -> __u32, etc). 

Use of VIDIOC_DBG_S_REGISTER requires CAP_SYS_ADMIN permission, so move 
the check into the video_ioctl2() dispatcher so it doesn't need to be 
duplicated in each driver's call-back function. CAP_SYS_ADMIN check is 
added to pvrusb2 (which doesn't use video_ioctl2).

Signed-off-by: default avatarTrent Piepho <xyzzy@speakeasy.org>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@infradead.org>
parent dbbff48f
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -628,7 +628,7 @@ static int cx25840_command(struct i2c_client *client, unsigned int cmd,
#ifdef CONFIG_VIDEO_ADV_DEBUG
	/* ioctls to allow direct access to the
	 * cx25840 registers for testing */
	case VIDIOC_INT_G_REGISTER:
	case VIDIOC_DBG_G_REGISTER:
	{
		struct v4l2_register *reg = arg;

@@ -638,7 +638,7 @@ static int cx25840_command(struct i2c_client *client, unsigned int cmd,
		break;
	}

	case VIDIOC_INT_S_REGISTER:
	case VIDIOC_DBG_S_REGISTER:
	{
		struct v4l2_register *reg = arg;

+0 −2
Original line number Diff line number Diff line
@@ -1405,8 +1405,6 @@ static int vidioc_s_register (struct file *file, void *fh,

	if (reg->i2c_id != 0)
		return -EINVAL;
	if (!capable(CAP_SYS_ADMIN))
		return -EPERM;
	cx_write(reg->reg&0xffffff, reg->val);
	return 0;
}
+3 −3
Original line number Diff line number Diff line
@@ -3277,7 +3277,7 @@ static int pvr2_hdw_get_eeprom_addr(struct pvr2_hdw *hdw)


int pvr2_hdw_register_access(struct pvr2_hdw *hdw,
			     u32 chip_id,unsigned long reg_id,
			     u32 chip_id, u32 reg_id,
			     int setFl,u32 *val_ptr)
{
#ifdef CONFIG_VIDEO_ADV_DEBUG
@@ -3295,8 +3295,8 @@ int pvr2_hdw_register_access(struct pvr2_hdw *hdw,
			cp = list_entry(item,struct pvr2_i2c_client,list);
			if (cp->client->driver->id != chip_id) continue;
			stat = pvr2_i2c_client_cmd(
				cp,(setFl ? VIDIOC_INT_S_REGISTER :
				    VIDIOC_INT_G_REGISTER),&req);
				cp,(setFl ? VIDIOC_DBG_S_REGISTER :
				    VIDIOC_DBG_G_REGISTER),&req);
			if (!setFl) *val_ptr = req.val;
			okFl = !0;
			break;
+1 −1
Original line number Diff line number Diff line
@@ -222,7 +222,7 @@ void pvr2_hdw_v4l_store_minor_number(struct pvr2_hdw *,
   setFl   - true to set the register, false to read it
   val_ptr - storage location for source / result. */
int pvr2_hdw_register_access(struct pvr2_hdw *,
			     u32 chip_id,unsigned long reg_id,
			     u32 chip_id,u32 reg_id,
			     int setFl,u32 *val_ptr);

/* The following entry points are all lower level things you normally don't
+9 −5
Original line number Diff line number Diff line
@@ -738,16 +738,20 @@ static int pvr2_v4l2_do_ioctl(struct inode *inode, struct file *file,
		break;
	}
#ifdef CONFIG_VIDEO_ADV_DEBUG
	case VIDIOC_INT_G_REGISTER:
	case VIDIOC_INT_S_REGISTER:
	case VIDIOC_DBG_S_REGISTER:
		if (!capable(CAP_SYS_ADMIN)) {
			ret = -EPERM;
			break;
		} /* fall through */
	case VIDIOC_DBG_G_REGISTER:
	{
		u32 val;
		struct v4l2_register *req = (struct v4l2_register *)arg;
		if (cmd == VIDIOC_INT_S_REGISTER) val = req->val;
		if (cmd == VIDIOC_DBG_S_REGISTER) val = req->val;
		ret = pvr2_hdw_register_access(
			hdw,req->i2c_id,req->reg,
			cmd == VIDIOC_INT_S_REGISTER,&val);
		if (cmd == VIDIOC_INT_G_REGISTER) req->val = val;
			cmd == VIDIOC_DBG_S_REGISTER,&val);
		if (cmd == VIDIOC_DBG_G_REGISTER) req->val = val;
		break;
	}
#endif
Loading