From patchwork Fri Sep 2 13:09:27 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 1121782 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p82DACSJ022811 for ; Fri, 2 Sep 2011 13:10:12 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752019Ab1IBNKJ (ORCPT ); Fri, 2 Sep 2011 09:10:09 -0400 Received: from mga09.intel.com ([134.134.136.24]:11512 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751806Ab1IBNKJ (ORCPT ); Fri, 2 Sep 2011 09:10:09 -0400 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP; 02 Sep 2011 06:10:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.67,351,1309762800"; d="scan'208";a="44491218" Received: from unknown (HELO smile) ([10.255.18.202]) by orsmga002.jf.intel.com with ESMTP; 02 Sep 2011 06:10:07 -0700 Received: from andy by smile with local (Exim 4.76) (envelope-from ) id 1QzTVJ-00025l-Uy; Fri, 02 Sep 2011 16:09:53 +0300 From: Andy Shevchenko To: linux-media@vger.kernel.org, Laurent Pinchart Cc: Andy Shevchenko 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 Message-Id: <05824e3de1c4470932403064c64a7746b39e025c.1314968925.git.andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <6075971b959c2e808cd4ceec6540dc09b101346f.1314968925.git.andriy.shevchenko@linux.intel.com> References: <201109021326.14340.laurent.pinchart@ideasonboard.com> <6075971b959c2e808cd4ceec6540dc09b101346f.1314968925.git.andriy.shevchenko@linux.intel.com> In-Reply-To: <6075971b959c2e808cd4ceec6540dc09b101346f.1314968925.git.andriy.shevchenko@linux.intel.com> References: <6075971b959c2e808cd4ceec6540dc09b101346f.1314968925.git.andriy.shevchenko@linux.intel.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Fri, 02 Sep 2011 13:10:16 +0000 (UTC) Signed-off-by: Andy Shevchenko --- 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;