From patchwork Wed Sep 7 15:13:07 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guennadi Liakhovetski X-Patchwork-Id: 1127942 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p87GvZIt028597 for ; Wed, 7 Sep 2011 16:57:35 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752465Ab1IGQ5b (ORCPT ); Wed, 7 Sep 2011 12:57:31 -0400 Received: from moutng.kundenserver.de ([212.227.17.9]:60062 "EHLO moutng.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750896Ab1IGQ5b (ORCPT ); Wed, 7 Sep 2011 12:57:31 -0400 Received: from axis700.grange (dslb-178-006-246-092.pools.arcor-ip.net [178.6.246.92]) by mrelayeu.kundenserver.de (node=mreu3) with ESMTP (Nemesis) id 0LlLtL-1RYSRA1yyN-00addw; Wed, 07 Sep 2011 17:13:07 +0200 Received: by axis700.grange (Postfix, from userid 1000) id 3066618B03C; Wed, 7 Sep 2011 17:13:07 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by axis700.grange (Postfix) with ESMTP id 2D77318B03B for ; Wed, 7 Sep 2011 17:13:07 +0200 (CEST) Date: Wed, 7 Sep 2011 17:13:07 +0200 (CEST) From: Guennadi Liakhovetski X-X-Sender: lyakh@axis700.grange To: Linux Media Mailing List Subject: [PATCH 1/2] V4L: soc-camera: split a function into two In-Reply-To: Message-ID: References: MIME-Version: 1.0 X-Provags-ID: V02:K0:wCHzSFOHMDrDzvh7RabYb3uaW8derzYrN682R+d3U+E f9TErMdZpC1Xf0vXOgWaG5B5M3caypNDYNHZKoJ5KLSIFcYZgU 0ZsE+5RBRsvOB+gt6Mf04jxvMOBuNjTaonaO2etLN3sYB+FPUq rV5j61NsqlzsnJnmfLpA147SNrb1ASs5/3kcGaT8VunNjAmyXq kOtZlIVmzAGSN46G+SONMOzBcv7NX3JIybl7pmnMN9AuSfxmeB tqHclVQ1E7UAe+gDV9Q7eC/uhyNkiv7cxX04tBVG+0j3QGgPHd ta3IltgiTnbTw1uWMrhAF4xWk9n7/7acM0/yQiDK5kUTffkDoP ZGw2X8AlvyMUH5a1H7+7eGmDJTjOA264CDXEDeubziS52sFwNQ Z0uqTu9gJdugQ== 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 (demeter2.kernel.org [140.211.167.43]); Wed, 07 Sep 2011 16:57:35 +0000 (UTC) The soc_camera_power_set() function processes two cases: power on anf off. These two cases don't share and common code, and the function is always called with a constant power on / off argument. Splitting this function into two removes a condition check, reduces indentation levels and makes the code look cleaner. Signed-off-by: Guennadi Liakhovetski --- drivers/media/video/soc_camera.c | 65 ++++++++++++++++++++------------------ 1 files changed, 34 insertions(+), 31 deletions(-) diff --git a/drivers/media/video/soc_camera.c b/drivers/media/video/soc_camera.c index 5943235..de374da 100644 --- a/drivers/media/video/soc_camera.c +++ b/drivers/media/video/soc_camera.c @@ -50,49 +50,52 @@ static LIST_HEAD(hosts); static LIST_HEAD(devices); static DEFINE_MUTEX(list_lock); /* Protects the list of hosts */ -static int soc_camera_power_set(struct soc_camera_device *icd, - struct soc_camera_link *icl, - int power_on) +static int soc_camera_power_on(struct soc_camera_device *icd, + struct soc_camera_link *icl) { int ret; - if (power_on) { - ret = regulator_bulk_enable(icl->num_regulators, - icl->regulators); - if (ret < 0) { - dev_err(icd->pdev, "Cannot enable regulators\n"); - return ret; - } + ret = regulator_bulk_enable(icl->num_regulators, + icl->regulators); + if (ret < 0) { + dev_err(icd->pdev, "Cannot enable regulators\n"); + return ret; + } - if (icl->power) - ret = icl->power(icd->pdev, power_on); + if (icl->power) { + ret = icl->power(icd->pdev, 1); if (ret < 0) { dev_err(icd->pdev, "Platform failed to power-on the camera.\n"); regulator_bulk_disable(icl->num_regulators, icl->regulators); - return ret; } - } else { - ret = 0; - if (icl->power) - ret = icl->power(icd->pdev, 0); + } + + return ret; +} + +static int soc_camera_power_off(struct soc_camera_device *icd, + struct soc_camera_link *icl) +{ + int ret; + + if (icl->power) { + ret = icl->power(icd->pdev, 0); if (ret < 0) { dev_err(icd->pdev, "Platform failed to power-off the camera.\n"); return ret; } - - ret = regulator_bulk_disable(icl->num_regulators, - icl->regulators); - if (ret < 0) { - dev_err(icd->pdev, "Cannot disable regulators\n"); - return ret; - } } - return 0; + ret = regulator_bulk_disable(icl->num_regulators, + icl->regulators); + if (ret < 0) + dev_err(icd->pdev, "Cannot disable regulators\n"); + + return ret; } const struct soc_camera_format_xlate *soc_camera_xlate_by_fourcc( @@ -502,7 +505,7 @@ static int soc_camera_open(struct file *file) }, }; - ret = soc_camera_power_set(icd, icl, 1); + ret = soc_camera_power_on(icd, icl); if (ret < 0) goto epower; @@ -555,7 +558,7 @@ esfmt: eresume: ici->ops->remove(icd); eiciadd: - soc_camera_power_set(icd, icl, 0); + soc_camera_power_off(icd, icl); epower: icd->use_count--; module_put(ici->ops->owner); @@ -579,7 +582,7 @@ static int soc_camera_close(struct file *file) if (ici->ops->init_videobuf2) vb2_queue_release(&icd->vb2_vidq); - soc_camera_power_set(icd, icl, 0); + soc_camera_power_off(icd, icl); } if (icd->streamer == file) @@ -1086,7 +1089,7 @@ static int soc_camera_probe(struct soc_camera_device *icd) if (ret < 0) goto ereg; - ret = soc_camera_power_set(icd, icl, 1); + ret = soc_camera_power_on(icd, icl); if (ret < 0) goto epower; @@ -1163,7 +1166,7 @@ static int soc_camera_probe(struct soc_camera_device *icd) ici->ops->remove(icd); - soc_camera_power_set(icd, icl, 0); + soc_camera_power_off(icd, icl); mutex_unlock(&icd->video_lock); @@ -1185,7 +1188,7 @@ eadddev: evdc: ici->ops->remove(icd); eadd: - soc_camera_power_set(icd, icl, 0); + soc_camera_power_off(icd, icl); epower: regulator_bulk_free(icl->num_regulators, icl->regulators); ereg: