Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5650415img; Wed, 27 Mar 2019 12:26:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqzdo9dCJXlJL6gpYoJk2ir06yjdF/7x1QEuaCF6/0U2loN8kxAmDdhYZ3tEw7jEkff41uB9 X-Received: by 2002:a63:6805:: with SMTP id d5mr2574361pgc.416.1553714816996; Wed, 27 Mar 2019 12:26:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553714816; cv=none; d=google.com; s=arc-20160816; b=lyVv98WdSR4260MrPIwLel45fjL/ofd1FmHW+Alcq3xaCIdk8O1QqmYHoKQxMcQ5rg dczgvRD+Lzihkuq0FSuyhDn4aDa80TvAzTjUn/MsLBQ4z7E8TE3/1RkCMj+0lsL4yMOd jL6Z+O8WaW06dmWUadReu5BFmzqh378Z/l4lcxGimc1yRd30Dgs48gBnzPYein5RgZlv Xo6hY1XgVE6yqSVow3gnm6of9NkMR1CdKjQE6kXLbGKSBCn1ykAynx0mV3DMF97Xu5SO DqllXc5nMJ95MQAHtUGTFh+51wZ+X0r7cFiGHeZdFP+YI6nzaP3ynfmh/kHbytMw2HQf 6MQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=WodF3VjYGy27rLIiRwXTShRlD3Uh8A8UT80jWJOvYSs=; b=0WA+yQCbtLf++fh+ll7UfvD5erbV17+TAUSXUJJcWXh9rsds2X/tsEfwVrurwlLMzI +wmbULqa9fQ4Uf9aBm+Ef7m5ooEc5eYodh+CjgUUzKhTw+Vm1emkZ+rGqpgvs8qr2XIB yMfeolQewTgB9/ezpbbTv2lV2NasfbSxjB1H3kDDsCoJeRpuasdZ4LPKhNgnNWzEZka7 13KFK28z/nTX4LwmsckWU2ijHULQNX2MpiYFgsd7zdgRAHtp4avcemT6tyg+wvf5+RgW Fw/o3Kxs5Rdggs8KyJhdbwW9Y85ZAT9yjHo7/AWSJ0uHazFIlPWq+BrV7r3OHbLbE39b L3Qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gKglGU5D; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w2si18545960pgp.266.2019.03.27.12.26.41; Wed, 27 Mar 2019 12:26:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gKglGU5D; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387865AbfC0TYx (ORCPT + 99 others); Wed, 27 Mar 2019 15:24:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:46738 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732477AbfC0SFd (ORCPT ); Wed, 27 Mar 2019 14:05:33 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BEF7021734; Wed, 27 Mar 2019 18:05:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553709932; bh=zuvBSIuz23CI0czPNPfY7zqWKOEeMKbbX79+///fBqc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gKglGU5DaJTYfjbJSPzZk0yT1SDHXriHOU5r0a0/opn9zSRB54umvHc5hCq4Zu0RP QTDvjoagbMJHnWexZBqbHqaBSaOn56XhiKx+c97egdYb8L+wu//yhF4wIk0Mqbz6iA 3zXcQSRtItJTzxp5JoImHLtmZSBtSaC5ItZkqC4Q= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Akinobu Mita , Wenyou Yang , Sakari Ailus , Mauro Carvalho Chehab , Sasha Levin , linux-media@vger.kernel.org Subject: [PATCH AUTOSEL 5.0 119/262] media: ov7740: fix runtime pm initialization Date: Wed, 27 Mar 2019 13:59:34 -0400 Message-Id: <20190327180158.10245-119-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190327180158.10245-1-sashal@kernel.org> References: <20190327180158.10245-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Akinobu Mita [ Upstream commit 12aceee1f412c3ddc7750155fec06c906f14ab51 ] The runtime PM of this device is enabled after v4l2_ctrl_handler_setup(), and this makes this device's runtime PM usage count a negative value. The ov7740_set_ctrl() tries to do something only if the device's runtime PM usage counter is nonzero. ov7740_set_ctrl() { if (!pm_runtime_get_if_in_use(&client->dev)) return 0; ; pm_runtime_put(&client->dev); return ret; } However, the ov7740_set_ctrl() is called by v4l2_ctrl_handler_setup() while the runtime PM of this device is not yet enabled. In this case, the pm_runtime_get_if_in_use() returns -EINVAL (!= 0). Therefore we can't bail out of this function and the usage count is decreased by pm_runtime_put() without increment. This fixes this problem by enabling the runtime PM of this device before v4l2_ctrl_handler_setup() so that the ov7740_set_ctrl() is always called when the runtime PM is enabled. Cc: Wenyou Yang Signed-off-by: Akinobu Mita Tested-by: Eugen Hristev Signed-off-by: Sakari Ailus Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/i2c/ov7740.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/media/i2c/ov7740.c b/drivers/media/i2c/ov7740.c index 177688afd9a6..8835b831cdc0 100644 --- a/drivers/media/i2c/ov7740.c +++ b/drivers/media/i2c/ov7740.c @@ -1101,6 +1101,9 @@ static int ov7740_probe(struct i2c_client *client, if (ret) return ret; + pm_runtime_set_active(&client->dev); + pm_runtime_enable(&client->dev); + ret = ov7740_detect(ov7740); if (ret) goto error_detect; @@ -1123,8 +1126,6 @@ static int ov7740_probe(struct i2c_client *client, if (ret) goto error_async_register; - pm_runtime_set_active(&client->dev); - pm_runtime_enable(&client->dev); pm_runtime_idle(&client->dev); return 0; @@ -1134,6 +1135,8 @@ static int ov7740_probe(struct i2c_client *client, error_init_controls: ov7740_free_controls(ov7740); error_detect: + pm_runtime_disable(&client->dev); + pm_runtime_set_suspended(&client->dev); ov7740_set_power(ov7740, 0); media_entity_cleanup(&ov7740->subdev.entity); -- 2.19.1