public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Brandon Philips <brandon@ifup.org>
To: Hans Verkuil <hverkuil@xs4all.nl>, mchehab@infradead.org
Cc: v4l-dvb-maintainer@linuxtv.org, video4linux-list@redhat.com
Subject: Re: [v4l-dvb-maintainer] [PATCH] [PATCH] v4l: Introduce "index" attribute for?persistent video4linux device nodes
Date: Mon, 23 Jun 2008 16:39:52 -0700	[thread overview]
Message-ID: <20080623233952.GA4569@plankton> (raw)
In-Reply-To: <200806231800.44274.hverkuil@xs4all.nl>

On 18:00 Mon 23 Jun 2008, Hans Verkuil wrote:
> On Monday 23 June 2008 17:07:34 Brandon Philips wrote:
> There is also no need to use class_for_each_device(): you can also 
> iterate over the video_device[] array.
> 
> So get_index would look something like this:

Your code compiles, looks correct and is simpler.  It tested OK on my
single node device but I don't have any multiple node devices like a
ivtv.  Testers welcome ;)

Mauro had already committed my patch to his branch so I just made the
change on top of that.

Mauro you can pull this patch from here: http://ifup.org/hg/v4l-dvb

Cheers,

	Brandon

changeset:   8111:e39be24dd6a0
tag:         tip
user:        Brandon Philips <brandon@ifup.org>
date:        Mon Jun 23 16:33:06 2008 -0700
files:       linux/drivers/media/video/videodev.c
description:
videodev: simplify get_index()

Use Hans Verkuil's suggested method of implementing get_index which doesn't
depend on class_for_each_device and instead uses the video_device array.  This
simplifies the code and reduces its memory footprint.

Signed-off-by: Brandon Philips <bphilips@suse.de>

diff --git a/linux/drivers/media/video/videodev.c b/linux/drivers/media/video/videodev.c
--- a/linux/drivers/media/video/videodev.c
+++ b/linux/drivers/media/video/videodev.c
@@ -1989,26 +1989,8 @@ out:
 }
 EXPORT_SYMBOL(video_ioctl2);
 
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25)
-struct index_info {
-	struct device *dev;
-	unsigned int used[VIDEO_NUM_DEVICES];
-};
-
-static int __fill_index_info(struct device *cd, void *data)
-{
-	struct index_info *info = data;
-	struct video_device *vfd = container_of(cd, struct video_device,
-						class_dev);
-
-	if (info->dev == vfd->dev)
-		info->used[vfd->index] = 1;
-
-	return 0;
-}
-
 /**
- * assign_index - assign stream number based on parent device
+ * get_index - assign stream number based on parent device
  * @vdev: video_device to assign index number to, vdev->dev should be assigned
  * @num: -1 if auto assign, requested number otherwise
  *
@@ -2018,46 +2000,35 @@ static int __fill_index_info(struct devi
  */
 static int get_index(struct video_device *vdev, int num)
 {
-	struct index_info *info;
+	u32 used = 0;
 	int i;
-	int ret = 0;
 
-	if (num >= VIDEO_NUM_DEVICES)
+	if (num >= 32) {
+		printk(KERN_ERR "videodev: %s num is too large\n", __func__);
 		return -EINVAL;
-
-	info = kzalloc(sizeof(*info), GFP_KERNEL);
-	if (!info)
-		return -ENOMEM;
-
-	info->dev = vdev->dev;
-
-	ret = class_for_each_device(&video_class, info,
-					__fill_index_info);
-
-	if (ret < 0)
-		goto out;
-
-	if (num >= 0) {
-		if (!info->used[num])
-			ret = num;
-		else
-			ret = -ENFILE;
-
-		goto out;
 	}
 
 	for (i = 0; i < VIDEO_NUM_DEVICES; i++) {
-		if (info->used[i])
-			continue;
-		ret = i;
-		goto out;
+		if (video_device[i] != NULL &&
+		    video_device[i] != vdev &&
+		    video_device[i]->dev == vdev->dev) {
+			used |= 1 << video_device[i]->index;
+		}
 	}
 
-out:
-	kfree(info);
-	return ret;
+	if (num >= 0) {
+		if (used & (1 << num))
+			return -ENFILE;
+		return num;
+	}
+
+	for (i = 0; i < 32; i++) {
+		if (used & (1 << i))
+			continue;
+		return i;
+	}
+	return -ENFILE;
 }
-#endif
 
 static const struct file_operations video_fops;
 
@@ -2151,11 +2122,7 @@ int video_register_device_index(struct v
 	video_device[i]=vfd;
 	vfd->minor=i;
 
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25)
 	ret = get_index(vfd, index);
-#else
-	ret = 0;
-#endif
 	if (ret < 0) {
 		printk(KERN_ERR "%s: get_index failed\n",
 		       __func__);

--
video4linux-list mailing list
Unsubscribe mailto:video4linux-list-request@redhat.com?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list

  reply	other threads:[~2008-06-23 23:40 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-20 22:58 [PATCH] [PATCH] v4l: Introduce "index" attribute for persistent video4linux device nodes brandon
2008-06-22 11:34 ` Hans Verkuil
2008-06-23  7:05   ` [v4l-dvb-maintainer] " Trent Piepho
2008-06-23 15:12     ` Brandon Philips
2008-06-23 15:07   ` Brandon Philips
2008-06-23 16:00     ` [v4l-dvb-maintainer] " Hans Verkuil
2008-06-23 23:39       ` Brandon Philips [this message]
2008-06-24  7:34         ` [v4l-dvb-maintainer] [PATCH] [PATCH] v4l: Introduce "index" attribute for?persistent " Trent Piepho
2008-06-24 22:59           ` Brandon Philips
2008-07-17 16:16             ` Hans Verkuil
2008-07-17 16:40               ` Mauro Carvalho Chehab
2008-07-17 16:44                 ` Hans Verkuil
2008-07-17 16:48                   ` Hans Verkuil
2008-07-17 16:57                     ` Mauro Carvalho Chehab
2008-07-17 17:10                       ` Hans Verkuil
2008-07-17 17:35                         ` Mauro Carvalho Chehab
2008-07-17 17:40                           ` Hans Verkuil
2008-07-17 17:43                             ` Mauro Carvalho Chehab
2008-06-23 16:46     ` [v4l-dvb-maintainer] [PATCH] [PATCH] v4l: Introduce "index" attribute for persistent " Trent Piepho

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080623233952.GA4569@plankton \
    --to=brandon@ifup.org \
    --cc=hverkuil@xs4all.nl \
    --cc=mchehab@infradead.org \
    --cc=v4l-dvb-maintainer@linuxtv.org \
    --cc=video4linux-list@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox