From patchwork Sun May 20 15:40:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 10413481 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 92D6F6032C for ; Sun, 20 May 2018 15:40:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 71775286F1 for ; Sun, 20 May 2018 15:40:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4F56728722; Sun, 20 May 2018 15:40:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BBC2B286F1 for ; Sun, 20 May 2018 15:40:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751631AbeETPku (ORCPT ); Sun, 20 May 2018 11:40:50 -0400 Received: from mail-pl0-f68.google.com ([209.85.160.68]:33529 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751547AbeETPkt (ORCPT ); Sun, 20 May 2018 11:40:49 -0400 Received: by mail-pl0-f68.google.com with SMTP id n10-v6so7316263plp.0 for ; Sun, 20 May 2018 08:40:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=Z9JhEGvgCTSXvAAwsvx54X1MfIIEu6kcB460x069I68=; b=gk8NlHlkXM7rzqqpv0mdTB9Di9OuOzyC7oKu3KASpUXlMT54ENOLiIlc6J6XfhTRy4 r45CXxS0IuAU8vP2OIpjM86AwE5VeQpBoc80T5PTLBRr/ci+ZtcfhQ+pW/HCR1zq6Fk9 5cT/LR8fz8M9sm760H+vSwRsnRhMzjKFqhWbAU5/Gg58iZJHZDoNsLpmNk9ybt25ue8S ZUQpdilZ1UJboJcJIaCBTu/cOhCoBTBxCdLHVQ8xF12XHNhfN75ychymv61HoND8gUnV +3NHQO1apTkGEvt84TIUUDt7Z2gRKkh8Qa2a/wXCGdbDTEkFhBxHAOh1i+U50amo5TI7 OLBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Z9JhEGvgCTSXvAAwsvx54X1MfIIEu6kcB460x069I68=; b=EBmViPO/SaDELFox0f4fQ3sqmHXY+LppmQ5pleck50YgFhTNZR67BmfGHEdDxE6aEu HA8jz43h60BMTj5wGybsu4FfTqaMGm/eEE9Eg+DeHqq/xq/IkiEwDUnNlTKOUMGZSH8z NpK8OGHFepkioJ0DqmxppP4s+fB3Y0doDV6hdmvqX02s1e4IOPNrnSHNY6X5VFWtcqpK TnwTgXrNjNZ35g1MgQDeyxyIiAu3mmzpbmXybvsxyih2CYnPoo69Sv29S1q/HD1knOsA JB5PLemoIlnRZ3uolThURWVY23LIsvLDXcV+5iu0ikkMhbOk/YFiACA2M1Jnf4jEg6Et uuTA== X-Gm-Message-State: ALKqPweraLlpHnIFz9S6NtlR6Gt/lJ9+UhdkcYxU5mstzWxyOv3MKwkP V8bzhhTVE5jiCmFZ/4nTEpnRTA== X-Google-Smtp-Source: AB8JxZpaFeSC9UcKKG/I1GC1x9yCnxAf4ekvGoK7ru7eaGBNPHwnLXYBTN70X4zG4m52WDLvoFDpVA== X-Received: by 2002:a17:902:d808:: with SMTP id a8-v6mr17300848plz.177.1526830848919; Sun, 20 May 2018 08:40:48 -0700 (PDT) Received: from localhost.localdomain ([240f:4:c2bc:1:909f:9859:c14a:d81e]) by smtp.gmail.com with ESMTPSA id p6-v6sm22058236pfg.157.2018.05.20.08.40.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 20 May 2018 08:40:48 -0700 (PDT) From: Akinobu Mita To: linux-media@vger.kernel.org Cc: Akinobu Mita , Sakari Ailus , Mauro Carvalho Chehab Subject: [PATCH] media: pxa_camera: avoid duplicate s_power calls Date: Mon, 21 May 2018 00:40:38 +0900 Message-Id: <1526830838-2812-1-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 2.7.4 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The open() operation for the pxa_camera driver always calls s_power() operation to put its subdevice sensor in normal operation mode, and the release() operation always call s_power() operation to put the subdevice in power saving mode. This requires the subdevice sensor driver to keep track of its power state in order to avoid putting the subdevice in power saving mode while the device is still opened by some users. Many subdevice drivers handle it by the boilerplate code that increments and decrements an internal counter in s_power() like below: /* * If the power count is modified from 0 to != 0 or from != 0 to 0, * update the power state. */ if (sensor->power_count == !on) { ret = ov5640_set_power(sensor, !!on); if (ret) goto out; } /* Update the power count. */ sensor->power_count += on ? 1 : -1; However, some subdevice drivers don't handle it and may cause a problem with the pxa_camera driver if the video device is opened by more than two users at the same time. Instead of propagating the boilerplate code for each subdevice driver that implement s_power, this introduces an trick that many V4L2 drivers are using with v4l2_fh_is_singular_file(). Cc: Sakari Ailus Cc: Mauro Carvalho Chehab Signed-off-by: Akinobu Mita --- drivers/media/platform/pxa_camera.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/media/platform/pxa_camera.c b/drivers/media/platform/pxa_camera.c index c71a007..c792cb1 100644 --- a/drivers/media/platform/pxa_camera.c +++ b/drivers/media/platform/pxa_camera.c @@ -2040,6 +2040,9 @@ static int pxac_fops_camera_open(struct file *filp) if (ret < 0) goto out; + if (!v4l2_fh_is_singular_file(filp)) + goto out; + ret = sensor_call(pcdev, core, s_power, 1); if (ret) v4l2_fh_release(filp); @@ -2052,13 +2055,17 @@ static int pxac_fops_camera_release(struct file *filp) { struct pxa_camera_dev *pcdev = video_drvdata(filp); int ret; - - ret = vb2_fop_release(filp); - if (ret < 0) - return ret; + bool fh_singular; mutex_lock(&pcdev->mlock); - ret = sensor_call(pcdev, core, s_power, 0); + + fh_singular = v4l2_fh_is_singular_file(filp); + + ret = _vb2_fop_release(filp, NULL); + + if (fh_singular) + ret = sensor_call(pcdev, core, s_power, 0); + mutex_unlock(&pcdev->mlock); return ret;