From patchwork Mon Sep 5 15:24:06 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 1125012 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 p85FPJUD027717 for ; Mon, 5 Sep 2011 15:25:19 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754568Ab1IEPZR (ORCPT ); Mon, 5 Sep 2011 11:25:17 -0400 Received: from mga11.intel.com ([192.55.52.93]:13266 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752725Ab1IEPZQ (ORCPT ); Mon, 5 Sep 2011 11:25:16 -0400 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 05 Sep 2011 08:25:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.68,334,1312182000"; d="scan'208";a="49101134" Received: from unknown (HELO smile) ([10.255.14.174]) by fmsmga002.fm.intel.com with ESMTP; 05 Sep 2011 08:25:15 -0700 Received: from andy by smile with local (Exim 4.76) (envelope-from ) id 1R0b2i-0002ZA-LQ; Mon, 05 Sep 2011 18:25:00 +0300 From: Andy Shevchenko To: Laurent Pinchart , linux-media@vger.kernel.org Cc: Andy Shevchenko Subject: [media-ctl][PATCHv5 4/5] libmediactl: simplify code by introducing close_and_free inliner Date: Mon, 5 Sep 2011 18:24:06 +0300 Message-Id: X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <6075971b959c2e808cd4ceec6540dc09b101346f.1315236211.git.andriy.shevchenko@linux.intel.com> References: <201109051657.21646.laurent.pinchart@ideasonboard.com> <6075971b959c2e808cd4ceec6540dc09b101346f.1315236211.git.andriy.shevchenko@linux.intel.com> In-Reply-To: <6075971b959c2e808cd4ceec6540dc09b101346f.1315236211.git.andriy.shevchenko@linux.intel.com> References: <6075971b959c2e808cd4ceec6540dc09b101346f.1315236211.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]); Mon, 05 Sep 2011 15:25:19 +0000 (UTC) Signed-off-by: Andy Shevchenko --- src/media.c | 15 +++++++++------ 1 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/media.c b/src/media.c index 657b6c4..6c03369 100644 --- a/src/media.c +++ b/src/media.c @@ -403,6 +403,12 @@ static int media_enum_entities(struct media_private *priv) return ret; } +static inline void close_and_free(struct media_private *priv) +{ + free(priv); + media_close(priv->media); +} + struct media_device *media_open(const char *name, int verbose) { struct media_device *media; @@ -440,8 +446,7 @@ struct media_device *media_open(const char *name, int verbose) ret = media_udev_open(priv); if (ret < 0) { printf("%s: Can't get udev context\n", __func__); - free(priv); - media_close(media); + close_and_free(priv); return NULL; } @@ -457,8 +462,7 @@ struct media_device *media_open(const char *name, int verbose) if (ret < 0) { printf("%s: Unable to enumerate entities for device %s (%s)\n", __func__, name, strerror(-ret)); - free(priv); - media_close(media); + close_and_free(priv); return NULL; } @@ -471,8 +475,7 @@ struct media_device *media_open(const char *name, int verbose) if (ret < 0) { printf("%s: Unable to enumerate pads and linksfor device %s\n", __func__, name); - free(priv); - media_close(media); + close_and_free(priv); return NULL; }