From patchwork Sun May 27 15:30:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 10429441 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 6FEFC60249 for ; Sun, 27 May 2018 15:30:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5600128AF3 for ; Sun, 27 May 2018 15:30:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4846528B26; Sun, 27 May 2018 15:30:25 +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 A8EBD28AF3 for ; Sun, 27 May 2018 15:30:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1032721AbeE0PaW (ORCPT ); Sun, 27 May 2018 11:30:22 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:35508 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1032634AbeE0PaV (ORCPT ); Sun, 27 May 2018 11:30:21 -0400 Received: by mail-pf0-f193.google.com with SMTP id x9-v6so4692762pfm.2 for ; Sun, 27 May 2018 08:30:21 -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=J/PSK6EO042GL/NC9Omn6uSWFNpsZYpphN4/VPgdDcY=; b=DgG189q+C9ezzvCPdsSfrBWCqUmropnph27pR8P66oI4cSCcPLs5U5+RcvggDfV0oF hOpGqBTpWuXyTNQZy0sxRtkBpQ2srw882M/AQWwldBDJUZrkvmwW+3hq1q9XeJ5hLNc2 EgSHPmAYprN+XtLx2VfJz/9Tp8Ut3FRCmuFFVjKMV6Z1KE6ZEcoIdy0I64MtAXrZjtMN Yp4BM+WG6G8tVhvvAKd5aF6o8dMACKP+PzrWs24jXa6bTiTVRx6IGVbEsMNNU2n6o/n3 fMSPfI0/AxFyk2D3krTx2OyEBVLENZ7XQ9F+eKkbzl8YmBucIOExv3rRE+l9BLa+M+1N BkWg== 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=J/PSK6EO042GL/NC9Omn6uSWFNpsZYpphN4/VPgdDcY=; b=V70kcztT8n3gJC3qkTC6on3ja5nGRHQ18gnqC96fDgziZbXL+YiPR7mh5a48OB3WLl OEprrFj++B+rKoevSGwqvuPaeuIASOf5Zym8W1PtFxQkoZpfhSUtffR5P+2fcDzBSHNu kGttwH8KxcPdZoP09NgXXQxiLEBBO5YkVouqlHpZUJuZgz2soIvid7R9FQEpzObV1iut eUL9Kr5Qa5xOP0ddIhP4ijQchuU6AmOxAWVWlYLtICEZHFunQEdMJeL9eyuMX2JSkz+a YQ+QzGIeoBzB5kHhHTfPCuS0rIiahz4+N0Y/utOcFWWcr073uu8m4+hMEPObPQCap26z NyXg== X-Gm-Message-State: ALKqPwcMv5/goyJp1CccliSwBvJ5lrqUjA3eNhZYZvnninf6fFMO8kPB jtCoBGnGZsdqH0QV/uA8Hig99w== X-Google-Smtp-Source: AB8JxZpFW9RudI2lSOR/yDcE2YhLOEcfkoqiXOjIg+88727yAVs37Qf8K9ojni6S1crzrRLYjfCMQg== X-Received: by 2002:aa7:81cc:: with SMTP id c12-v6mr10206922pfn.169.1527435021351; Sun, 27 May 2018 08:30:21 -0700 (PDT) Received: from localhost.localdomain ([240f:4:c2bc:1:ac9f:2c83:40c9:40ea]) by smtp.gmail.com with ESMTPSA id a23-v6sm6219454pgd.85.2018.05.27.08.30.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 27 May 2018 08:30:20 -0700 (PDT) From: Akinobu Mita To: linux-media@vger.kernel.org Cc: Akinobu Mita , Sakari Ailus , Mauro Carvalho Chehab Subject: [PATCH v2] media: pxa_camera: avoid duplicate s_power calls Date: Mon, 28 May 2018 00:30:11 +0900 Message-Id: <1527435011-9318-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 Acked-by: Sakari Ailus --- * v2 - Print warning message when s_power() is failed. (not printing warning when _vb2_fop_release() is failed as it always returns zero for now) drivers/media/platform/pxa_camera.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/drivers/media/platform/pxa_camera.c b/drivers/media/platform/pxa_camera.c index c71a007..a35f461 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,23 @@ 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); + if (ret) { + dev_warn(pcdev_to_dev(pcdev), + "Failed to put subdevice in power saving mode: %d\n", + ret); + } + } + mutex_unlock(&pcdev->mlock); return ret;