From patchwork Sat Oct 12 12:31:55 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sylwester Nawrocki X-Patchwork-Id: 3031511 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 BBC9DBF924 for ; Sat, 12 Oct 2013 12:32:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CFA2F2039D for ; Sat, 12 Oct 2013 12:32:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DC9BE20379 for ; Sat, 12 Oct 2013 12:32:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752779Ab3JLMcd (ORCPT ); Sat, 12 Oct 2013 08:32:33 -0400 Received: from mail-wi0-f172.google.com ([209.85.212.172]:59838 "EHLO mail-wi0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752557Ab3JLMcW (ORCPT ); Sat, 12 Oct 2013 08:32:22 -0400 Received: by mail-wi0-f172.google.com with SMTP id hn3so1332174wib.11 for ; Sat, 12 Oct 2013 05:32:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=/OvNesEP3uYq75Is/HIzt/IRa3c8pW9c2v7B7qc7RSU=; b=WtBme9vFT2Cjo/7cpXC/PydsCFMDpf2KwCoNiQXxuNoIiSr0iK1BRDS5n8YTKoOWj/ MHt4MrtVUGHAt+Icqdw33EZ1yo4gT0bmx4T0C2hHYj/JhZkW2Xg7IFsBD8Zpjj3Toqnz nMPuTX+iS+LlSUdsaVBor073WvHY7ZCarrc0cOVLzDlHZCSMiXNh3eLL7SWexUnKT5xa qGJrfW400OArv9n8G+e2ijfrf6yWUmYGRD8sjP3Fl0A7V3SxBVL3cGIiqM/DVrRg1qbY Dy6Hx5ipaCR9NgXwxJdUALrBO/0YPImLc6AT1tkS16lnYqCdDAWf+5Muh0h7ZgqapIBH ufWg== X-Received: by 10.180.208.45 with SMTP id mb13mr7170293wic.27.1381581140973; Sat, 12 Oct 2013 05:32:20 -0700 (PDT) Received: from localhost.localdomain (093105185086.warszawa.vectranet.pl. [93.105.185.86]) by mx.google.com with ESMTPSA id q17sm14747025wiv.10.1969.12.31.16.00.00 (version=TLSv1 cipher=RC4-SHA bits=128/128); Sat, 12 Oct 2013 05:32:20 -0700 (PDT) From: Sylwester Nawrocki To: linux-media@vger.kernel.org Cc: hverkuil@xs4all.nl, pawel@osciak.com, javier.martin@vista-silicon.com, m.szyprowski@samsung.com, shaik.ameer@samsung.com, arun.kk@samsung.com, k.debski@samsung.com, p.zabel@pengutronix.de, kyungmin.park@samsung.com, linux-samsung-soc@vger.kernel.org, Sylwester Nawrocki Subject: [PATCH RFC v2 05/10] mx2-emmaprp: Use struct v4l2_fh Date: Sat, 12 Oct 2013 14:31:55 +0200 Message-Id: <1381581120-26883-6-git-send-email-s.nawrocki@samsung.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1381581120-26883-1-git-send-email-s.nawrocki@samsung.com> References: <1381581120-26883-1-git-send-email-s.nawrocki@samsung.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=-7.0 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, KHOP_BIG_TO_CC, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID,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 Signed-off-by: Sylwester Nawrocki Signed-off-by: Kyungmin Park --- drivers/media/platform/mx2_emmaprp.c | 54 ++++++++++++++++++++++----------- 1 files changed, 36 insertions(+), 18 deletions(-) -- 1.7.4.1 -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/media/platform/mx2_emmaprp.c b/drivers/media/platform/mx2_emmaprp.c index c690435..e91a4d5 100644 --- a/drivers/media/platform/mx2_emmaprp.c +++ b/drivers/media/platform/mx2_emmaprp.c @@ -221,9 +221,12 @@ struct emmaprp_ctx { /* Abort requested by m2m */ int aborting; struct emmaprp_q_data q_data[2]; + struct v4l2_fh fh; struct v4l2_m2m_ctx *m2m_ctx; }; +#define fh_to_ctx(__fh) container_of(__fh, struct emmaprp_ctx, fh) + static struct emmaprp_q_data *get_q_data(struct emmaprp_ctx *ctx, enum v4l2_buf_type type) { @@ -478,13 +481,15 @@ static int vidioc_g_fmt(struct emmaprp_ctx *ctx, struct v4l2_format *f) static int vidioc_g_fmt_vid_out(struct file *file, void *priv, struct v4l2_format *f) { - return vidioc_g_fmt(priv, f); + struct emmaprp_ctx *ctx = fh_to_ctx(priv); + return vidioc_g_fmt(ctx, f); } static int vidioc_g_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f) { - return vidioc_g_fmt(priv, f); + struct emmaprp_ctx *ctx = fh_to_ctx(priv); + return vidioc_g_fmt(ctx, f); } static int vidioc_try_fmt(struct v4l2_format *f) @@ -524,8 +529,8 @@ static int vidioc_try_fmt(struct v4l2_format *f) static int vidioc_try_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f) { + struct emmaprp_ctx *ctx = fh_to_ctx(priv); struct emmaprp_fmt *fmt; - struct emmaprp_ctx *ctx = priv; fmt = find_format(f); if (!fmt || !(fmt->types & MEM2MEM_CAPTURE)) { @@ -541,8 +546,8 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv, static int vidioc_try_fmt_vid_out(struct file *file, void *priv, struct v4l2_format *f) { + struct emmaprp_ctx *ctx = fh_to_ctx(priv); struct emmaprp_fmt *fmt; - struct emmaprp_ctx *ctx = priv; fmt = find_format(f); if (!fmt || !(fmt->types & MEM2MEM_OUTPUT)) { @@ -561,7 +566,7 @@ static int vidioc_s_fmt(struct emmaprp_ctx *ctx, struct v4l2_format *f) struct vb2_queue *vq; int ret; - vq = v4l2_m2m_get_vq(ctx->m2m_ctx, f->type); + vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type); if (!vq) return -EINVAL; @@ -596,25 +601,27 @@ static int vidioc_s_fmt(struct emmaprp_ctx *ctx, struct v4l2_format *f) static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f) { + struct emmaprp_ctx *ctx = fh_to_ctx(priv); int ret; ret = vidioc_try_fmt_vid_cap(file, priv, f); if (ret) return ret; - return vidioc_s_fmt(priv, f); + return vidioc_s_fmt(ctx, f); } static int vidioc_s_fmt_vid_out(struct file *file, void *priv, struct v4l2_format *f) { + struct emmaprp_ctx *ctx = fh_to_ctx(priv); int ret; ret = vidioc_try_fmt_vid_out(file, priv, f); if (ret) return ret; - return vidioc_s_fmt(priv, f); + return vidioc_s_fmt(ctx, f); } static int vidioc_reqbufs(struct file *file, void *priv, @@ -790,27 +797,28 @@ static int emmaprp_open(struct file *file) { struct emmaprp_dev *pcdev = video_drvdata(file); struct emmaprp_ctx *ctx; + int ret; ctx = kzalloc(sizeof *ctx, GFP_KERNEL); if (!ctx) return -ENOMEM; - file->private_data = ctx; - ctx->dev = pcdev; - if (mutex_lock_interruptible(&pcdev->dev_mutex)) { - kfree(ctx); - return -ERESTARTSYS; + ret = -ERESTARTSYS; + goto err_free; } + v4l2_fh_init(&ctx->fh, pcdev->vfd); + file->private_data = &ctx->fh; + v4l2_fh_add(&ctx->fh); + + ctx->dev = pcdev; + ctx->m2m_ctx = v4l2_m2m_ctx_init(pcdev->m2m_dev, ctx, &queue_init); if (IS_ERR(ctx->m2m_ctx)) { - int ret = PTR_ERR(ctx->m2m_ctx); - - mutex_unlock(&pcdev->dev_mutex); - kfree(ctx); - return ret; + ret = PTR_ERR(ctx->m2m_ctx); + goto err_fh; } clk_prepare_enable(pcdev->clk_emma_ipg); @@ -822,12 +830,20 @@ static int emmaprp_open(struct file *file) dprintk(pcdev, "Created instance %p, m2m_ctx: %p\n", ctx, ctx->m2m_ctx); return 0; + +err_fh: + v4l2_fh_del(&ctx->fh); + v4l2_fh_exit(&ctx->fh); +err_free: + kfree(ctx); + mutex_unlock(&pcdev->dev_mutex); + return ret; } static int emmaprp_release(struct file *file) { + struct emmaprp_ctx *ctx = fh_to_ctx(file->private_data); struct emmaprp_dev *pcdev = video_drvdata(file); - struct emmaprp_ctx *ctx = file->private_data; dprintk(pcdev, "Releasing instance %p\n", ctx); @@ -835,6 +851,8 @@ static int emmaprp_release(struct file *file) clk_disable_unprepare(pcdev->clk_emma_ahb); clk_disable_unprepare(pcdev->clk_emma_ipg); v4l2_m2m_ctx_release(ctx->m2m_ctx); + v4l2_fh_del(&ctx->fh); + v4l2_fh_exit(&ctx->fh); mutex_unlock(&pcdev->dev_mutex); kfree(ctx);