Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1348766pxv; Fri, 25 Jun 2021 10:46:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJywX9MsPsr8p/CY37anN5v6O5FLva1Kw77NSnLsIU1jrq6qiyh+kSHmPbthHx0nCzKLUtNC X-Received: by 2002:a05:6e02:12c9:: with SMTP id i9mr8199005ilm.113.1624643178444; Fri, 25 Jun 2021 10:46:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624643178; cv=none; d=google.com; s=arc-20160816; b=EkYItCFAO24w77sU+6IkngxSonaLr0cg4VrUYF0pZmwKpZt1QVC3aS1nxAPEQhruQQ 5iP6I62r19VQ8yB/wfJEzKr2BtVwHWNr02xkU5R1dZw/83EeL7Aot+gms68fpm536gIx ZqOgezvqMfLNDJwriL3+b2DU+DGcPoThiTS+dAjsfCmZLDiA31a2N1s91716QF75DFiM 0wkSDXzumubbTKczg8F8uoqCkeX/trMicezrj+5H5Ol5yKi8xs/LRg0NY6Wezuh8NGuc RB/1wMSFTHJmhcqQ9LFgpR8JKgD5xurJ/KG3E4TCbsM5yN1KwCVoGvtz0JYKu8AvRD7d 9uEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=OVTHm4sF3Md+1ZJ8KTrVDkxVcElq21ltpAZb83VRUP8=; b=QuLzEcBvXq83IJZhFDWBzfUGxTmODPDhfw7QU9WkNPuRC2P53k31DqF1x07ChVw6kC 2FoExhpdnqH+4kNh4dwzDUt09gFiweQnWVH35YoP6ZTwNETIWPPPzqGMR4RFSB8SIb4H qkD4Zo1wHbtHtcgbANGYrg58wr3wG13V/eMzDwSVTP93ZaTShN9M2noEFepozhcsQAIg 2QDgSPtJVyzBhudIrpDh1J95h3ajUo2MmkShiphYZQ8qjUmGU8MbxlaYavtWoG6d3dqT qD7f7r3ZVwVr/oY1bTFDhegcKZtGfKUgWgoFvT+GT4SgvAJOumy290ggjE9zdFFMaBu3 Wr0g== 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 j16si5892408ioo.11.2021.06.25.10.46.06; Fri, 25 Jun 2021 10:46: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; 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 S230020AbhFYRrr convert rfc822-to-8bit (ORCPT + 99 others); Fri, 25 Jun 2021 13:47:47 -0400 Received: from mail-ot1-f45.google.com ([209.85.210.45]:40568 "EHLO mail-ot1-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229531AbhFYRrr (ORCPT ); Fri, 25 Jun 2021 13:47:47 -0400 Received: by mail-ot1-f45.google.com with SMTP id d21-20020a9d72d50000b02904604cda7e66so8312776otk.7; Fri, 25 Jun 2021 10:45:26 -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:content-transfer-encoding; bh=9Pdg+c0bCKRv3vfZOsBUZeWcTgAgBkhLYfD+IypIHoU=; b=pHL7eNdoT86v1TpKlm2dSCWP9eg36bkOha3O4dcB1kXIgTYnNDkl5ypGec2Ktdjid0 WfMseHN4rEICEwcp4X0hav4zuSGHwv9Wd7gnMKHTk07oe20PfbXcgAXPOzhRPR7jsZof g2Lw7q+m3oR8RQczzQJryM3hxT/QQLnx+1Gt5WfFgUSPCfD8nmLWXxqmtgYJCC7lGnuY BUopDSuZLB8/qpKRd+TZ5+4R44LuBFkgEH4Fs4b+CARtofIrDhCRqGysCnCLeZBzIn2O 7P+j18Oz7796Ea5IioVV5ZO8QFfRN4qt9tPunH8abfCLTF3koRTX+uGXVcjRdZQ54wRE GfaQ== X-Gm-Message-State: AOAM533d5sSSvDV1eTXCX+Z/tLACzfPDLv3C14qJnPUizY+fRFWV+Nzo Z5IEPOA+JtWlFPevqjFwVFMrt87dBdU45qMp52NtvSYVQ3Q= X-Received: by 2002:a9d:1905:: with SMTP id j5mr10641075ota.321.1624643125712; Fri, 25 Jun 2021 10:45:25 -0700 (PDT) MIME-Version: 1.0 References: <1620791837-16138-1-git-send-email-zou_wei@huawei.com> <20210512045222.2yjm6yxikznohlmn@pengutronix.de> In-Reply-To: <20210512045222.2yjm6yxikznohlmn@pengutronix.de> From: "Rafael J. Wysocki" Date: Fri, 25 Jun 2021 19:45:14 +0200 Message-ID: Subject: Re: [PATCH -next] pwm: img: Fix PM reference leak in img_pwm_enable() To: =?UTF-8?Q?Uwe_Kleine=2DK=C3=B6nig?= Cc: Zou Wei , Thierry Reding , Lee Jones , Linux PWM List , Linux Kernel Mailing List , "Rafael J. Wysocki" , Kevin Hilman , Ulf Hansson , Linux PM Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 12, 2021 at 6:52 AM Uwe Kleine-König wrote: > > Hello, > > On Wed, May 12, 2021 at 11:57:17AM +0800, Zou Wei wrote: > > pm_runtime_get_sync will increment pm usage counter even it failed. > > Forgetting to putting operation will result in reference leak here. > > Fix it by replacing it with pm_runtime_resume_and_get to keep usage > > counter balanced. > > > > Reported-by: Hulk Robot > > Signed-off-by: Zou Wei > > --- > > drivers/pwm/pwm-img.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/drivers/pwm/pwm-img.c b/drivers/pwm/pwm-img.c > > index cc37054..11b16ec 100644 > > --- a/drivers/pwm/pwm-img.c > > +++ b/drivers/pwm/pwm-img.c > > @@ -156,7 +156,7 @@ static int img_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm) > > struct img_pwm_chip *pwm_chip = to_img_pwm_chip(chip); > > int ret; > > > > - ret = pm_runtime_get_sync(chip->dev); > > + ret = pm_runtime_resume_and_get(chip->dev); > > if (ret < 0) > > return ret; > > This patch looks right with my limited understanding of pm_runtime. A > similar issue in this driver was fixed in commit > > ca162ce98110 ("pwm: img: Call pm_runtime_put() in pm_runtime_get_sync() failed case") > > where (even though the commit log talks about pm_runtime_put()) a call > to pm_runtime_put_autosuspend() was added in the error path. > > I added the PM guys to Cc, maybe they can advise about the right thing > to do here. Does it make sense to use the same idiom in both > img_pwm_enable() and img_pwm_config()? I think so. And calling pm_runtime_put_autosuspend() in the img_pwm_enable() error path would work too.