Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3343450pxv; Sun, 4 Jul 2021 16:05:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGOHeNL+PPvbPkPx+dKuHochJOZDS1Dvqbs3Iay+yuPCpbQKqCLiRgIgHDazTdwUsFROJ5 X-Received: by 2002:a92:2010:: with SMTP id j16mr8193746ile.98.1625439928145; Sun, 04 Jul 2021 16:05:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625439928; cv=none; d=google.com; s=arc-20160816; b=die/xPBP9dEVQnqGDsc7UyvWOudVO6W0WSVZd1SkJ9G/IdrscnH+3TwQcuqrYRrc0X QF2sOKn2daHAT9ZmiQbnfzNHBkmERM23EM2zt6p4zrUGYGUDyFmHVg8D1f+XhPBGXbQl o1/AM7pQ0NDDL11C7o1h+/xtwXEc1ccBNT8d9kpLqTtvqTOlbG4E5zxW5BvE5eP2Md9d QgDGiBo0jYkasf4tWVgUug9RNUs7iJQO4i5lt+9yKqPV34NnoHB7QAnr/jVOJIydxGNk hPgYyYnX6lwYrXuFvzgRGETd2sMs2ZunwiqR+7ClErGsovnaxBdoFBBB5CJ8nn1Bo/Mj Z2Jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=++CiKyyx/irlnUbFeKQ+ZspmnN8nOx+atkyJMnKf0T8=; b=npcP45jFf/72Dl3Sr9A88aD5oVUSaGGEkwH6SCKt3EYlUwurD+ip5eFDUO0ni1c2oc SFx55asiVmutKJviIR4cbIeXWHXs8pgPcGShRLrkBVmo9T3bEGcKPlnlIFgXh4lO6aMz B4CacmZQj0uFOJHG7m6JotygqoHtO7A6ABfa5mJ9TjVWM+RNOwSFPzNKVrghxhNp2MTb 7susgZ528pQ9gvKfO+7heXmh0AaH75RKQmThv7f3m4r9hjVlokp2NaIXNNG2+Jvg3kqs 3WYr91hhOJjWD+tNYtCjjQBiXXHL6CGENDXh1kWfVLfNEp1SxA72ZFYYZFCygQoyOEBE yJzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aREna3O+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id a4si11423952ild.162.2021.07.04.16.05.16; Sun, 04 Jul 2021 16:05:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aREna3O+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S229956AbhGDXHM (ORCPT + 99 others); Sun, 4 Jul 2021 19:07:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:45084 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229947AbhGDXHI (ORCPT ); Sun, 4 Jul 2021 19:07:08 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7C407613E5; Sun, 4 Jul 2021 23:04:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625439872; bh=WoXSq2ICM3efq+BWozC2CMUcabEJzzaMVOvVVaY7IjM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aREna3O+4UGJW9FKim2GJlkyvP9+rDlSC8kQrTFjn3X8iZfany1Az8CR9qAl4vVMc RZPRWogWyVX8BxQqrsXVc3g3oKGGQYd4x0PZo2Dy5OVTYjnh0jX8Gl1y6FH/f7kVA8 EbZnmXsdzA37BUDJUDnzQ0PCxPA5lSz4uRBDmj2qufifQQFBUIu9zvn1iK1SLwbk/2 9aDXPtqNAUg08nSO8WrS4Nd5kc3SK7Ny7DGOUZVJqla3o9rDiQCRyjZlF104asrDTH tmgI6v+9VO/6VKyI9wKkWW1CdCZsE8s/JfxgirIKPWcpPVnLgTMqHHGDxtOCjiSH8L Hi3IFt8f3KeZw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Mauro Carvalho Chehab , Jonathan Cameron , Sasha Levin , linux-media@vger.kernel.org Subject: [PATCH AUTOSEL 5.13 08/85] media: am437x: fix pm_runtime_get_sync() usage count Date: Sun, 4 Jul 2021 19:03:03 -0400 Message-Id: <20210704230420.1488358-8-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210704230420.1488358-1-sashal@kernel.org> References: <20210704230420.1488358-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mauro Carvalho Chehab [ Upstream commit c41e02493334985cca1a22efd5ca962ce3abb061 ] The pm_runtime_get_sync() internally increments the dev->power.usage_count without decrementing it, even on errors. Replace it by the new pm_runtime_resume_and_get(), introduced by: commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") in order to properly decrement the usage counter, avoiding a potential PM usage counter leak. While here, ensure that the driver will check if PM runtime resumed at vpfe_initialize_device(). Reviewed-by: Jonathan Cameron Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/platform/am437x/am437x-vpfe.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/am437x/am437x-vpfe.c b/drivers/media/platform/am437x/am437x-vpfe.c index 6cdc77dda0e4..1c9cb9e05fdf 100644 --- a/drivers/media/platform/am437x/am437x-vpfe.c +++ b/drivers/media/platform/am437x/am437x-vpfe.c @@ -1021,7 +1021,9 @@ static int vpfe_initialize_device(struct vpfe_device *vpfe) if (ret) return ret; - pm_runtime_get_sync(vpfe->pdev); + ret = pm_runtime_resume_and_get(vpfe->pdev); + if (ret < 0) + return ret; vpfe_config_enable(&vpfe->ccdc, 1); @@ -2443,7 +2445,11 @@ static int vpfe_probe(struct platform_device *pdev) pm_runtime_enable(&pdev->dev); /* for now just enable it here instead of waiting for the open */ - pm_runtime_get_sync(&pdev->dev); + ret = pm_runtime_resume_and_get(&pdev->dev); + if (ret < 0) { + vpfe_err(vpfe, "Unable to resume device.\n"); + goto probe_out_v4l2_unregister; + } vpfe_ccdc_config_defaults(ccdc); @@ -2530,6 +2536,11 @@ static int vpfe_suspend(struct device *dev) /* only do full suspend if streaming has started */ if (vb2_start_streaming_called(&vpfe->buffer_queue)) { + /* + * ignore RPM resume errors here, as it is already too late. + * A check like that should happen earlier, either at + * open() or just before start streaming. + */ pm_runtime_get_sync(dev); vpfe_config_enable(ccdc, 1); -- 2.30.2