diff mbox

[REVIEW,01/14] V4L: Int if: Dummy slave

Message ID A24693684029E5489D1D202277BE894416429F97@dlee02.ent.ti.com (mailing list archive)
State RFC
Headers show

Commit Message

Aguirre Rodriguez, Sergio Alberto Jan. 13, 2009, 2:03 a.m. UTC
This patch implements a dummy slave that has no functionality. Helps
managing slaves in the OMAP 3 camera driver; no need to check for NULL
pointers.

Signed-off-by: Sakari Ailus <sakari.ailus@nokia.com>
Signed-off-by: Sergio Aguirre <saaguirre@ti.com>
---
 drivers/media/video/v4l2-int-device.c |   19 +++++++++++++++++++
 include/media/v4l2-int-device.h       |    2 ++
 2 files changed, 21 insertions(+), 0 deletions(-)

Comments

Mauro Carvalho Chehab Jan. 13, 2009, 8:33 p.m. UTC | #1
On Mon, 12 Jan 2009 20:03:08 -0600
"Aguirre Rodriguez, Sergio Alberto" <saaguirre@ti.com> wrote:

>
> +static struct v4l2_int_slave dummy_slave = {
> +	/* Dummy pointer to avoid underflow in find_ioctl. */
> +	.ioctls = (void *)0x80000000,

Why are you using here a magic number?

> +	.num_ioctls = 0,
> +};

Cheers,
Mauro
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Sakari Ailus Jan. 22, 2009, 9:37 a.m. UTC | #2
Mauro Carvalho Chehab wrote:
> On Mon, 12 Jan 2009 20:03:08 -0600
> "Aguirre Rodriguez, Sergio Alberto" <saaguirre@ti.com> wrote:
> 
>> +static struct v4l2_int_slave dummy_slave = {
>> +	/* Dummy pointer to avoid underflow in find_ioctl. */
>> +	.ioctls = (void *)0x80000000,
> 
> Why are you using here a magic number?

Not really a reason. It could be or actually perhaps anything equal to
or bigger than sizeof(struct v4l2_int_ioctl_desc) so that last doesn't
underflow:

         const struct v4l2_int_ioctl_desc *first = slave->ioctls;
         const struct v4l2_int_ioctl_desc *last =
                 first + slave->num_ioctls - 1;

num_ioctls is zero. See find_ioctl in drivers/media/video/v4l2-int-device.c.

I guess that should be changed to sizeof(struct v4l2_int_ioctl_desc).
diff mbox

Patch

diff --git a/drivers/media/video/v4l2-int-device.c b/drivers/media/video/v4l2-int-device.c
index a935bae..cba1c9c 100644
--- a/drivers/media/video/v4l2-int-device.c
+++ b/drivers/media/video/v4l2-int-device.c
@@ -32,6 +32,25 @@ 
 static DEFINE_MUTEX(mutex);
 static LIST_HEAD(int_list);
 
+static struct v4l2_int_slave dummy_slave = {
+	/* Dummy pointer to avoid underflow in find_ioctl. */
+	.ioctls = (void *)0x80000000,
+	.num_ioctls = 0,
+};
+
+static struct v4l2_int_device dummy = {
+	.type = v4l2_int_type_slave,
+	.u = {
+		.slave = &dummy_slave,
+	},
+};
+
+struct v4l2_int_device *v4l2_int_device_dummy()
+{
+	return &dummy;
+}
+EXPORT_SYMBOL_GPL(v4l2_int_device_dummy);
+
 void v4l2_int_device_try_attach_all(void)
 {
 	struct v4l2_int_device *m, *s;
diff --git a/include/media/v4l2-int-device.h b/include/media/v4l2-int-device.h
index 9c2df41..85a1834 100644
--- a/include/media/v4l2-int-device.h
+++ b/include/media/v4l2-int-device.h
@@ -84,6 +84,8 @@  struct v4l2_int_device {
 	void *priv;
 };
 
+struct v4l2_int_device *v4l2_int_device_dummy(void);
+
 void v4l2_int_device_try_attach_all(void);
 
 int v4l2_int_device_register(struct v4l2_int_device *d);