From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_MUTT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 13695C04AAF for ; Thu, 16 May 2019 11:48:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CE28620848 for ; Thu, 16 May 2019 11:48:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="pld/BfU2" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727447AbfEPLs5 (ORCPT ); Thu, 16 May 2019 07:48:57 -0400 Received: from perceval.ideasonboard.com ([213.167.242.64]:34700 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727817AbfEPLsy (ORCPT ); Thu, 16 May 2019 07:48:54 -0400 Received: from pendragon.ideasonboard.com (dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi [IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id CA0672FD; Thu, 16 May 2019 13:48:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1558007331; bh=s7hLWlBo7amBJq1P8APfOipBJL4XakYbg9xTS8jsnPI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=pld/BfU2z4RaH7vQ2uujGMa425AsxcMjBA66R6iZWHzq0VYUCUs04llHlsofBVGpt Kyo4hIYryfa5FqlM9wwNroRybVTQgmCopc2OYUyuPSot6CjlE+XP2b/6TU7AYtY4r6 vTQq0LG0awjc7dFBQafb4pV2ago7Ev5avFnUndk0= Date: Thu, 16 May 2019 14:48:34 +0300 From: Laurent Pinchart To: Niklas =?utf-8?Q?S=C3=B6derlund?= Cc: Ulrich Hecht , linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Ulrich Hecht Subject: Re: [PATCH v2 8/8] rcar-vin: Merge Gen2 and Gen3 file operations Message-ID: <20190516114834.GG14820@pendragon.ideasonboard.com> References: <20190516011417.10590-1-niklas.soderlund+renesas@ragnatech.se> <20190516011417.10590-9-niklas.soderlund+renesas@ragnatech.se> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20190516011417.10590-9-niklas.soderlund+renesas@ragnatech.se> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Hi Niklas, Thank you for the patch. On Thu, May 16, 2019 at 03:14:17AM +0200, Niklas Söderlund wrote: > After the rework of the Gen2 file operations it's now trivial to merge > the Gen2 and Gen3 versions. > > Signed-off-by: Niklas Söderlund > Reviewed-by: Ulrich Hecht > --- > drivers/media/platform/rcar-vin/rcar-v4l2.c | 96 ++++----------------- > 1 file changed, 16 insertions(+), 80 deletions(-) > > diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c b/drivers/media/platform/rcar-vin/rcar-v4l2.c > index 169639416121f204..8e4afa4278fe9d30 100644 > --- a/drivers/media/platform/rcar-vin/rcar-v4l2.c > +++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c > @@ -781,14 +781,19 @@ static int rvin_open(struct file *file) > if (ret) > goto err_pm; > > - if (v4l2_fh_is_singular_file(file)) { > - ret = rvin_power_parallel(vin, true); > + if (vin->info->use_mc) { > + ret = v4l2_pipeline_pm_use(&vin->vdev.entity, 1); > if (ret < 0) > goto err_open; > + } else { > + if (v4l2_fh_is_singular_file(file)) { > + ret = rvin_power_parallel(vin, true); > + if (ret < 0) > + goto err_open; > > - v4l2_ctrl_handler_setup(&vin->ctrl_handler); > + v4l2_ctrl_handler_setup(&vin->ctrl_handler); > + } > } I wonder if you shouldn't abstract the first open init and last close cleanup operations in separate functions, with MC and non-MC variants, as you will need to handle the v4l2_ctrl_handler_setup() failure here, making error handling more complex. > - > mutex_unlock(&vin->lock); > > return 0; > @@ -816,12 +821,12 @@ static int rvin_release(struct file *file) > /* the release helper will cleanup any on-going streaming */ > ret = _vb2_fop_release(file, NULL); > > - /* > - * If this was the last open file. > - * Then de-initialize hw module. > - */ > - if (fh_singular) > - rvin_power_parallel(vin, false); > + if (vin->info->use_mc) { > + v4l2_pipeline_pm_use(&vin->vdev.entity, 0); > + } else { > + if (fh_singular) > + rvin_power_parallel(vin, false); > + } > > pm_runtime_put(vin->dev); > > @@ -840,74 +845,6 @@ static const struct v4l2_file_operations rvin_fops = { > .read = vb2_fop_read, > }; > > -/* ----------------------------------------------------------------------------- > - * Media controller file operations > - */ > - > -static int rvin_mc_open(struct file *file) > -{ > - struct rvin_dev *vin = video_drvdata(file); > - int ret; > - > - ret = mutex_lock_interruptible(&vin->lock); > - if (ret) > - return ret; > - > - ret = pm_runtime_get_sync(vin->dev); > - if (ret < 0) > - goto err_unlock; > - > - ret = v4l2_pipeline_pm_use(&vin->vdev.entity, 1); > - if (ret < 0) > - goto err_pm; > - > - file->private_data = vin; > - > - ret = v4l2_fh_open(file); > - if (ret) > - goto err_v4l2pm; > - > - mutex_unlock(&vin->lock); > - > - return 0; > -err_v4l2pm: > - v4l2_pipeline_pm_use(&vin->vdev.entity, 0); > -err_pm: > - pm_runtime_put(vin->dev); > -err_unlock: > - mutex_unlock(&vin->lock); > - > - return ret; > -} > - > -static int rvin_mc_release(struct file *file) > -{ > - struct rvin_dev *vin = video_drvdata(file); > - int ret; > - > - mutex_lock(&vin->lock); > - > - /* the release helper will cleanup any on-going streaming. */ > - ret = _vb2_fop_release(file, NULL); > - > - v4l2_pipeline_pm_use(&vin->vdev.entity, 0); > - pm_runtime_put(vin->dev); > - > - mutex_unlock(&vin->lock); > - > - return ret; > -} > - > -static const struct v4l2_file_operations rvin_mc_fops = { > - .owner = THIS_MODULE, > - .unlocked_ioctl = video_ioctl2, > - .open = rvin_mc_open, > - .release = rvin_mc_release, > - .poll = vb2_fop_poll, > - .mmap = vb2_fop_mmap, > - .read = vb2_fop_read, > -}; > - > void rvin_v4l2_unregister(struct rvin_dev *vin) > { > if (!video_is_registered(&vin->vdev)) > @@ -948,6 +885,7 @@ int rvin_v4l2_register(struct rvin_dev *vin) > snprintf(vdev->name, sizeof(vdev->name), "VIN%u output", vin->id); > vdev->release = video_device_release_empty; > vdev->lock = &vin->lock; > + vdev->fops = &rvin_fops; > vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING | > V4L2_CAP_READWRITE; > > @@ -959,10 +897,8 @@ int rvin_v4l2_register(struct rvin_dev *vin) > vin->format.colorspace = RVIN_DEFAULT_COLORSPACE; > > if (vin->info->use_mc) { > - vdev->fops = &rvin_mc_fops; > vdev->ioctl_ops = &rvin_mc_ioctl_ops; > } else { > - vdev->fops = &rvin_fops; > vdev->ioctl_ops = &rvin_ioctl_ops; > rvin_reset_format(vin); > } -- Regards, Laurent Pinchart