All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: linux-media@vger.kernel.org,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: [media-ctl][PATCHv4 2/3] libmediactl: split media_get_devname_sysfs from media_enum_entities
Date: Fri,  2 Sep 2011 16:09:27 +0300	[thread overview]
Message-ID: <05824e3de1c4470932403064c64a7746b39e025c.1314968925.git.andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <6075971b959c2e808cd4ceec6540dc09b101346f.1314968925.git.andriy.shevchenko@linux.intel.com>
In-Reply-To: <6075971b959c2e808cd4ceec6540dc09b101346f.1314968925.git.andriy.shevchenko@linux.intel.com>

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 src/media.c |   61 +++++++++++++++++++++++++++++++++-------------------------
 1 files changed, 35 insertions(+), 26 deletions(-)

diff --git a/src/media.c b/src/media.c
index 050289e..5d3ff7c 100644
--- a/src/media.c
+++ b/src/media.c
@@ -245,15 +245,46 @@ static int media_enum_links(struct media_device *media)
 	return ret;
 }
 
-static int media_enum_entities(struct media_device *media)
+static int media_get_devname_sysfs(struct media_entity *entity)
 {
-	struct media_entity *entity;
 	struct stat devstat;
-	unsigned int size;
 	char devname[32];
 	char sysname[32];
 	char target[1024];
 	char *p;
+	int ret;
+
+	sprintf(sysname, "/sys/dev/char/%u:%u", entity->info.v4l.major,
+		entity->info.v4l.minor);
+	ret = readlink(sysname, target, sizeof(target));
+	if (ret < 0)
+		return -errno;
+
+	target[ret] = '\0';
+	p = strrchr(target, '/');
+	if (p == NULL)
+		return -EINVAL;
+
+	sprintf(devname, "/dev/%s", p + 1);
+	ret = stat(devname, &devstat);
+	if (ret < 0)
+		return -errno;
+
+	/* Sanity check: udev might have reordered the device nodes.
+	 * Make sure the major/minor match. We should really use
+	 * libudev.
+	 */
+	if (major(devstat.st_rdev) == entity->info.v4l.major &&
+	    minor(devstat.st_rdev) == entity->info.v4l.minor)
+		strcpy(entity->devname, devname);
+
+	return 0;
+}
+
+static int media_enum_entities(struct media_device *media)
+{
+	struct media_entity *entity;
+	unsigned int size;
 	__u32 id;
 	int ret = 0;
 
@@ -293,29 +324,7 @@ static int media_enum_entities(struct media_device *media)
 		    media_entity_type(entity) != MEDIA_ENT_T_V4L2_SUBDEV)
 			continue;
 
-		sprintf(sysname, "/sys/dev/char/%u:%u", entity->info.v4l.major,
-			entity->info.v4l.minor);
-		ret = readlink(sysname, target, sizeof(target));
-		if (ret < 0)
-			continue;
-
-		target[ret] = '\0';
-		p = strrchr(target, '/');
-		if (p == NULL)
-			continue;
-
-		sprintf(devname, "/dev/%s", p + 1);
-		ret = stat(devname, &devstat);
-		if (ret < 0)
-			continue;
-
-		/* Sanity check: udev might have reordered the device nodes.
-		 * Make sure the major/minor match. We should really use
-		 * libudev.
-		 */
-		if (major(devstat.st_rdev) == entity->info.v4l.major &&
-		    minor(devstat.st_rdev) == entity->info.v4l.minor)
-			strcpy(entity->devname, devname);
+		media_get_devname_sysfs(entity);
 	}
 
 	return ret;
-- 
1.7.5.4


  reply	other threads:[~2011-09-02 13:10 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-15 12:20 [media-ctl][PATCH] libmediactl: engage udev to get devname Andy Shevchenko
2011-08-15 14:52 ` Laurent Pinchart
2011-08-16  7:20   ` Andy Shevchenko
2011-08-16 10:28   ` [media-ctl][PATCHv2 1/4] libmediactl: restruct error path Andy Shevchenko
2011-08-16 10:28     ` [media-ctl][PATCHv2 2/4] libmediactl: split media_get_devname from media_enum_entities Andy Shevchenko
2011-08-16 10:28     ` [media-ctl][PATCHv2 3/4] libmediactl: use udev conditionally to get a devname Andy Shevchenko
2011-08-30 19:01       ` Laurent Pinchart
2011-09-02  8:39         ` [media-ctl][PATCHv3 1/3] libmediactl: restruct error path Andy Shevchenko
2011-09-02  8:39           ` [media-ctl][PATCHv3 2/3] libmediactl: split media_get_devname_sysfs from media_enum_entities Andy Shevchenko
2011-09-02  8:39           ` [media-ctl][PATCHv3 3/3] libmediactl: get the device name via udev Andy Shevchenko
2011-08-30 19:14       ` [media-ctl][PATCHv2 3/4] libmediactl: use udev conditionally to get a devname Laurent Pinchart
2011-09-02  8:42         ` Andy Shevchenko
2011-09-02 11:17           ` Laurent Pinchart
2011-09-02 11:21             ` Andy Shevchenko
2011-09-02 11:26               ` Laurent Pinchart
2011-09-02 13:09                 ` [media-ctl][PATCHv4 1/3] libmediactl: restruct error path Andy Shevchenko
2011-09-02 13:09                   ` Andy Shevchenko [this message]
2011-09-02 13:09                   ` [media-ctl][PATCHv4 3/3] libmediactl: get the device name via udev Andy Shevchenko
2011-09-05 10:31                     ` Laurent Pinchart
2011-09-05 14:48                       ` Andy Shevchenko
2011-09-05 14:57                         ` Laurent Pinchart
2011-09-05 15:24                           ` [media-ctl][PATCHv5 1/5] libmediactl: restruct error path Andy Shevchenko
2011-09-05 15:24                             ` [media-ctl][PATCHv5 2/5] libmediactl: split media_get_devname_sysfs from media_enum_entities Andy Shevchenko
2011-09-05 15:24                             ` [media-ctl][PATCHv5 3/5] libmediactl: get the device name via udev Andy Shevchenko
2011-09-05 15:24                             ` [media-ctl][PATCHv5 4/5] libmediactl: simplify code by introducing close_and_free inliner Andy Shevchenko
2011-09-05 15:24                             ` [media-ctl][PATCHv5 5/5] libmediactl: get rid of memset via using calloc Andy Shevchenko
2011-09-06 10:25                             ` [media-ctl][PATCHv5 1/5] libmediactl: restruct error path Laurent Pinchart
2011-09-06 10:46                               ` Andy Shevchenko
2011-09-06 10:50                                 ` Andy Shevchenko
2011-09-06 11:30                                   ` Laurent Pinchart
2011-09-06  8:14                           ` [media-ctl][PATCHv4 3/3] libmediactl: get the device name via udev Andy Shevchenko
2011-08-16 10:28     ` [media-ctl][PATCHv2 4/4] libmediactl: pass verbose to media_get_devname Andy Shevchenko
2011-08-30 20:20 ` [media-ctl][PATCH] libmediactl: engage udev to get devname L. Hanisch

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=05824e3de1c4470932403064c64a7746b39e025c.1314968925.git.andriy.shevchenko@linux.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.