Received: by 2002:a25:1104:0:0:0:0:0 with SMTP id 4csp503000ybr; Fri, 22 May 2020 11:41:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzldZvwdfsw1RhfnMSJ4knu/pv6fbt0Auiy+4sWzQGVDP4byXh2tvkL0bZv7fYE4ybyuQrQ X-Received: by 2002:aa7:d35a:: with SMTP id m26mr4106212edr.25.1590172897780; Fri, 22 May 2020 11:41:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590172897; cv=none; d=google.com; s=arc-20160816; b=OiGnpSCrCWvpk1Nm6Q9mwsMUktUuOaK9eiEgAxkVnL7sP9NxZsM242Lhk+tM2hDX/D MyPTUWygxFSkOUiEF2aEdLmk0peFncVRReJDxodFHaPrZpN7Z0k/ysgGHnHj3YnWM8FF DhrkDpOG+FqQBM02tqQIw1hZbmzPINr7tnKlW05YOr/cKDcWqUtBjfr7M6TmtD0qJFcw eV88AfWAO1u6B6TLswUz32chkBn5brmhIwodoXkwOWmS36QTgnt1VDtFjsRfwU7G8F5w K3O3oRNif4Ie1xugHLPzfHRGmktfzZ2I+e0MqvHq9mVRQ3oX80RvG4ff6pD98bW/bNR/ TARQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=p3zMsrxZhwgrwcGduQr/UXxqaWPWrG8kkAgCM3744ZY=; b=OAX6BddW+X35F4RDiCURWiE841fWppcIUHZ/djFv1Y5+zKFbxsPai7zPTP9BvQuo5j nLCOB8IAuNy2PN+PvlymN/D1X45sUA1gCJM1LdbTgC08TxB3sOqCgm9To/sAiUWvC1Fo uGaP5dlXqEa4fHcoVUYiJhC6AXR10J/7xIea4AiLX7cEZnk5DlSPDDacKDDVAEAVuO9N E4/NnsvIY4wJr4C7S19Ig3c2t1cSyHH1oakO7HbtRR6/BxS7zUcyUzQttQSt0b4biU3r RZi7FFapnXp3MJXoBeB7qWdj4C2sA52FTYcvw6siBxIuYgeapRGvfwYFL5GH7s7slu9y zZBA== ARC-Authentication-Results: i=1; mx.google.com; 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 r8si5678377eju.564.2020.05.22.11.41.14; Fri, 22 May 2020 11:41:37 -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; 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 S1730869AbgEVSjv (ORCPT + 99 others); Fri, 22 May 2020 14:39:51 -0400 Received: from mail-oi1-f193.google.com ([209.85.167.193]:37923 "EHLO mail-oi1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730808AbgEVSjv (ORCPT ); Fri, 22 May 2020 14:39:51 -0400 Received: by mail-oi1-f193.google.com with SMTP id j145so10155933oib.5; Fri, 22 May 2020 11:39:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=p3zMsrxZhwgrwcGduQr/UXxqaWPWrG8kkAgCM3744ZY=; b=T0p/cKQQznyxbTBGqE5w1LwgAcfC46Dh81Uvyw+fzAQA7y5KY/kRfEfDI9sIPwICqf 86fS2VcfU9iMs04Wm/tdShWzsOATRbmJKmJPbxxvE05KLAi62QZe4GJsjmxRqlbajdMG p8DHzojZS93h5I64vHrgEGfzLXWNba7A77knVOhUnvJSzUizcsvRs3c9oFZ827shj7gr 6YIMOJ1tGXqlAi7LavtSh+dyHghEdVZ1kh/M33QfrYFuQLEeUxVLE6MJTFLc8RkwEtnB csfYPBzdc1Fls+7kteHMFAAJECQeV3ks3vq3BnWVdjVTEI1eiOqVrlefwftoJ75g4tc9 5guQ== X-Gm-Message-State: AOAM530kvfJaFszB4aUuMBZR1ea9JMN3B4okhUKcQcZf5GsPLYrmjI/R LCLiqZoJ1wLs+1uhsRcCXABHZ3IU0D4wRdi4GuC59w== X-Received: by 2002:a05:6808:486:: with SMTP id z6mr3689687oid.103.1590172790038; Fri, 22 May 2020 11:39:50 -0700 (PDT) MIME-Version: 1.0 References: <5127441.yGvM1JjtLk@kreacher> In-Reply-To: From: "Rafael J. Wysocki" Date: Fri, 22 May 2020 20:39:38 +0200 Message-ID: Subject: Re: [PATCH] PM: runtime: clk: Fix clk_pm_runtime_get() error path To: Marek Szyprowski Cc: "Rafael J. Wysocki" , Linux PM , LKML , Ulf Hansson , Krzysztof Kozlowski , Michael Turquette , Bartlomiej Zolnierkiewicz Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 22, 2020 at 7:19 AM Marek Szyprowski wrote: > > 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? No, I don't, and that's why I'm proposing this patch. The caller that does what you said above is OK now and if the behavior of pm_runtime_get_sync() changed, that caller would need to be updated. OTOH, a caller that fails to drop the reference on an error returned by pm_runtime_get_sync() is buggy (and has ever been so). I'd rather update the buggy callers than the ones that are OK. Thanks! > > > > --- > > 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 >