Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1994182ybk; Thu, 21 May 2020 22:21:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+uwygXPGwM1A1MCS45ks4EoMv1XQv5jl26EORAJlRz6gJHegEfMzsPe2Q7pYEgFQmWo28 X-Received: by 2002:aa7:c4da:: with SMTP id p26mr1663020edr.184.1590124878897; Thu, 21 May 2020 22:21:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590124878; cv=none; d=google.com; s=arc-20160816; b=HCk3OVkCZ3m118CH+29PyFhk+Y0pMmvlT5Q1thhZiaRusj3+ImR5DZTvbyW9uhGWPR vbW7I2xF74JReIogxc8xiybHsMyDIGhKogWGQNMvMDvtzeT6hTDDN927wqFAFm4T9Oa+ YZOvSQOEiELWqBbsZNZ2MPbghmQrZY+cuikFOxei5weP5n/HnKYZXnaknJAqVkqoGFa5 7Z+TQt/rnfY3Jvosjus+z9HCSW5RvCyYhjIiql8dMMGpfntMLqDnt2RIQ+ZcbeeyYjjI vwsZacBJJbZSrn0vp4AJqFpJmCzC+1xKuLb4GjVq3euIIs1NuikQILl1e9DRdxxxd102 QemA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:cms-type:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:cc:to:subject:dkim-signature:dkim-filter; bh=bDBvRfRwXpfJfQj2KXHjRFIv2OKEmKMJBjpkDpCPm3o=; b=CKQH0INu3NA5rYQVGyU9sz3BqTBHlz+FbRxBkpLqUYbrcb3MMp8/PuonBFWa4ShUAZ Klc2sCtLx/Xil8HoDRsJ+xqSufPGT/cW7D41dbeto2vusceRHbmfQdKZ6l0lwyj3D+Xx ZCIaRepmvlNocBuzIJlWCeXE0CeGstnmVHUyER1abEWHm68K6nR4zRhLbRYl8Fv9XxGs 1tD0xbWAXxbKosTUiaA93iCzEoExac5nUxiFGeYvq7X/bey5wb9qcnJwfMW8h5aEt7/z E7OID4TW3CyUJ7kbmmRMST1wgctIz/a9esoKZpUA7pw550j/urs1sfJzRzN9bIDnNNrf n0RA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b="fEGc3xK/"; 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=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 13si3982923edx.388.2020.05.21.22.20.54; Thu, 21 May 2020 22:21:18 -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=@samsung.com header.s=mail20170921 header.b="fEGc3xK/"; 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=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728102AbgEVFTb (ORCPT + 99 others); Fri, 22 May 2020 01:19:31 -0400 Received: from mailout2.w1.samsung.com ([210.118.77.12]:44338 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726338AbgEVFTa (ORCPT ); Fri, 22 May 2020 01:19:30 -0400 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20200522051928euoutp02bdb25ff7e8b69ebb25e890de6ecb44ca~RQg1fplHF2205622056euoutp024 for ; Fri, 22 May 2020 05:19:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20200522051928euoutp02bdb25ff7e8b69ebb25e890de6ecb44ca~RQg1fplHF2205622056euoutp024 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1590124768; bh=bDBvRfRwXpfJfQj2KXHjRFIv2OKEmKMJBjpkDpCPm3o=; h=Subject:To:Cc:From:Date:In-Reply-To:References:From; b=fEGc3xK//4xmizDC3Lwt/WL6Lc1RO1I1CCKcjMXmd9E9cCATyEKAGwHBOJ3uqbVVS P/c5qSS7wMONMPJ8euUOxN0FJRNs8dsOqCfCUH8q41izHujPPR9qDJyCr4paUEBzjw GtEnDGARkdGqjIAvwaBiYnpPCO8oQ6l+UIKTXoHk= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20200522051928eucas1p2ae7e6d0237f73826f0ec5fe6346314be~RQg1IgnGu1567415674eucas1p2Q; Fri, 22 May 2020 05:19:28 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 1F.78.61286.0E067CE5; Fri, 22 May 2020 06:19:28 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20200522051927eucas1p107f4aae8f0f47043f067d7d6b58efd19~RQg04aWgR3127431274eucas1p1H; Fri, 22 May 2020 05:19:27 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200522051927eusmtrp132203103fb852f9fbbbdaf357a54095b~RQg030OQj2136521365eusmtrp1n; Fri, 22 May 2020 05:19:27 +0000 (GMT) X-AuditID: cbfec7f2-ef1ff7000001ef66-53-5ec760e0572c Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id B5.BE.08375.FD067CE5; Fri, 22 May 2020 06:19:27 +0100 (BST) Received: from [106.210.88.143] (unknown [106.210.88.143]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20200522051927eusmtip2f7fc78fc9283057109a1d9cdb3fa9efd~RQg0cUKZL3144231442eusmtip2O; Fri, 22 May 2020 05:19:27 +0000 (GMT) Subject: Re: [PATCH] PM: runtime: clk: Fix clk_pm_runtime_get() error path To: "Rafael J. Wysocki" , Linux PM Cc: LKML , Ulf Hansson , Krzysztof Kozlowski , Michael Turquette , Bartlomiej Zolnierkiewicz From: Marek Szyprowski Message-ID: Date: Fri, 22 May 2020 07:19:28 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <5127441.yGvM1JjtLk@kreacher> Content-Transfer-Encoding: 7bit Content-Language: en-US X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrLKsWRmVeSWpSXmKPExsWy7djPc7oPEo7HGUw5zGexccZ6Vovz5zew W1zeNYfN4nPvEUaLi6dcLc6cvsRqcXxtuAO7x/sbrewem1Z1snncubaHzWPL1XYWj74tqxg9 Pm+SC2CL4rJJSc3JLEst0rdL4MqYtWcbW8Fq/oqPl+6wNDAu4Oli5OSQEDCRWLngGVMXIxeH kMAKRokt66ZBOV8YJc4tOsIG4XxmlLjzaw9rFyMHWMvvkwYQ8eWMEmtmLGGEcN4zSnz7/YQd ZK6wgJfEh95mVhBbRCBIYu3cWWwgNrPAXUaJM/s4QWw2AUOJrrddYHFeATuJR3fbmEBsFgFV iT+HZjCC2KICsRKnF29mhKgRlDg58wkLiM0poCWx7ekRVoiZ8hLb385hhrDFJW49mQ/2goTA PnaJtrn3mSGudpE42p8K8bOwxKvjW9ghbBmJ05N7WCDqmxklHp5byw7h9DBKXG6CuEJCwFri zrlfbCCDmAU0Jdbv0ocIO0rsunGEHWI+n8SNt4IQN/BJTNo2HWotr0RHmxBEtZrErOPr4NYe vHCJeQKj0iwkn81C8s0sJN/MQti7gJFlFaN4amlxbnpqsWFearlecWJucWleul5yfu4mRmAi Ov3v+Kcdj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PDDz+pt9XiGeD6TyD9yfqFbp7vN8Q8OT/R5+QcvzNdukMsqauDoWcB/NTN5z 8+Av3XuHbpyyyZY/vXn9Iv6gm1qf3q2weriUJ17xoVFL2jKLf/5iIf0zre4utPu02Cyx5mSQ cRnf1a9KLMUZiYZazEXFiQCOKI8Y0wIAAA== X-CMS-MailID: 20200522051927eucas1p107f4aae8f0f47043f067d7d6b58efd19 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20200521170817eucas1p13d9477a0a5d13d2df876134cf41131d8 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200521170817eucas1p13d9477a0a5d13d2df876134cf41131d8 References: <5127441.yGvM1JjtLk@kreacher> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Rafael, On 21.05.2020 19:08, Rafael J. Wysocki wrote: > From: Rafael J. Wysocki > > clk_pm_runtime_get() assumes that the PM-runtime usage counter will > be dropped by pm_runtime_get_sync() on errors, which is not the case, > so PM-runtime references to devices acquired by the former are leaked > on errors returned by the latter. > > Fix this by modifying clk_pm_runtime_get() to drop the reference if > pm_runtime_get_sync() returns an error. > > Fixes: 9a34b45397e5 clk: Add support for runtime PM > Cc: 4.15+ # 4.15+ > Signed-off-by: Rafael J. Wysocki Frankly, I would rather fix the runtime_get_sync() instead of fixing the return path everywhere in the kernel. The current behavior of the pm_runtime_get_sync() is completely counter-intuitive then. I bet that in the 99% of the places where it is being called assume that no special fixup is needed in case of failure. This is one of the most common runtime PM related function and it is really a common pattern in the drivers to call: pm_runtime_get_sync() do something with the hardware pm_runtime_put() Do you really want to fix the error paths of the all such calls? > --- > drivers/clk/clk.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > Index: linux-pm/drivers/clk/clk.c > =================================================================== > --- linux-pm.orig/drivers/clk/clk.c > +++ linux-pm/drivers/clk/clk.c > @@ -114,7 +114,11 @@ static int clk_pm_runtime_get(struct clk > return 0; > > ret = pm_runtime_get_sync(core->dev); > - return ret < 0 ? ret : 0; > + if (ret < 0) { > + pm_runtime_put_noidle(core->dev); > + return ret; > + } > + return 0; > } > > static void clk_pm_runtime_put(struct clk_core *core) > > > > Best regards -- Marek Szyprowski, PhD Samsung R&D Institute Poland