From patchwork Mon Jun 23 23:54:17 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 4405711 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id F1CCEBEEAA for ; Mon, 23 Jun 2014 23:54:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 278592034B for ; Mon, 23 Jun 2014 23:54:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 45D38201DD for ; Mon, 23 Jun 2014 23:54:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753209AbaFWXyK (ORCPT ); Mon, 23 Jun 2014 19:54:10 -0400 Received: from perceval.ideasonboard.com ([95.142.166.194]:47311 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753051AbaFWXyH (ORCPT ); Mon, 23 Jun 2014 19:54:07 -0400 Received: from avalon.ideasonboard.com (unknown [91.178.161.143]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 741F9366F2; Tue, 24 Jun 2014 01:53:16 +0200 (CEST) From: Laurent Pinchart To: linux-media@vger.kernel.org Cc: linux-sh@vger.kernel.org Subject: [PATCH v2 11/23] v4l: vsp1: Propagate vsp1_device_get errors to the callers Date: Tue, 24 Jun 2014 01:54:17 +0200 Message-Id: <1403567669-18539-12-git-send-email-laurent.pinchart+renesas@ideasonboard.com> X-Mailer: git-send-email 1.8.5.5 In-Reply-To: <1403567669-18539-1-git-send-email-laurent.pinchart+renesas@ideasonboard.com> References: <1403567669-18539-1-git-send-email-laurent.pinchart+renesas@ideasonboard.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Modify the vsp1_device_get() function to return an error code instead of a pointer to the VSP1 device, and use the return value in the callers. Signed-off-by: Laurent Pinchart --- drivers/media/platform/vsp1/vsp1.h | 2 +- drivers/media/platform/vsp1/vsp1_drv.c | 16 ++++++---------- drivers/media/platform/vsp1/vsp1_video.c | 4 ++-- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/drivers/media/platform/vsp1/vsp1.h b/drivers/media/platform/vsp1/vsp1.h index 3cfa393..1246719 100644 --- a/drivers/media/platform/vsp1/vsp1.h +++ b/drivers/media/platform/vsp1/vsp1.h @@ -66,7 +66,7 @@ struct vsp1_device { struct media_device media_dev; }; -struct vsp1_device *vsp1_device_get(struct vsp1_device *vsp1); +int vsp1_device_get(struct vsp1_device *vsp1); void vsp1_device_put(struct vsp1_device *vsp1); static inline u32 vsp1_read(struct vsp1_device *vsp1, u32 reg) diff --git a/drivers/media/platform/vsp1/vsp1_drv.c b/drivers/media/platform/vsp1/vsp1_drv.c index 0c5e74c..3e6601b 100644 --- a/drivers/media/platform/vsp1/vsp1_drv.c +++ b/drivers/media/platform/vsp1/vsp1_drv.c @@ -345,36 +345,32 @@ static int vsp1_device_init(struct vsp1_device *vsp1) * Increment the VSP1 reference count and initialize the device if the first * reference is taken. * - * Return a pointer to the VSP1 device or NULL if an error occurred. + * Return 0 on success or a negative error code otherwise. */ -struct vsp1_device *vsp1_device_get(struct vsp1_device *vsp1) +int vsp1_device_get(struct vsp1_device *vsp1) { - struct vsp1_device *__vsp1 = vsp1; - int ret; + int ret = 0; mutex_lock(&vsp1->lock); if (vsp1->ref_count > 0) goto done; ret = clk_prepare_enable(vsp1->clock); - if (ret < 0) { - __vsp1 = NULL; + if (ret < 0) goto done; - } ret = vsp1_device_init(vsp1); if (ret < 0) { clk_disable_unprepare(vsp1->clock); - __vsp1 = NULL; goto done; } done: - if (__vsp1) + if (!ret) vsp1->ref_count++; mutex_unlock(&vsp1->lock); - return __vsp1; + return ret; } /* diff --git a/drivers/media/platform/vsp1/vsp1_video.c b/drivers/media/platform/vsp1/vsp1_video.c index a60332e..885ec01 100644 --- a/drivers/media/platform/vsp1/vsp1_video.c +++ b/drivers/media/platform/vsp1/vsp1_video.c @@ -955,8 +955,8 @@ static int vsp1_video_open(struct file *file) file->private_data = vfh; - if (!vsp1_device_get(video->vsp1)) { - ret = -EBUSY; + ret = vsp1_device_get(video->vsp1); + if (ret < 0) { v4l2_fh_del(vfh); kfree(vfh); }