From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=3.0 tests=BAYES_00,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_2 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1A94AC43460 for ; Sun, 11 Apr 2021 15:07:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E965B610A6 for ; Sun, 11 Apr 2021 15:07:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236027AbhDKPHS (ORCPT ); Sun, 11 Apr 2021 11:07:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:51582 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235503AbhDKPHQ (ORCPT ); Sun, 11 Apr 2021 11:07:16 -0400 Received: from jic23-huawei (cpc108967-cmbg20-2-0-cust86.5-4.cable.virginm.net [81.101.6.87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 190C4610C7; Sun, 11 Apr 2021 15:06:57 +0000 (UTC) Date: Sun, 11 Apr 2021 16:07:20 +0100 From: Jonathan Cameron To: Dinghao Liu Cc: kjlu@umn.edu, Linus Walleij , Lars-Peter Clausen , Peter Meerwald-Stadler , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] iio: light: gp2ap002: Fix rumtime PM imbalance on error Message-ID: <20210411160720.037c405c@jic23-huawei> In-Reply-To: <20210407034927.16882-1-dinghao.liu@zju.edu.cn> References: <20210407034927.16882-1-dinghao.liu@zju.edu.cn> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 7 Apr 2021 11:49:27 +0800 Dinghao Liu wrote: > When devm_request_threaded_irq() fails, we should decrease the > runtime PM counter to keep the counter balanced. But when > iio_device_register() fails, we need not to decrease it because > we have already decreased it before. Whilst agree with your assessment that the code is wrong, I'm not totally sure why we need to do the pm_runtime_get_noresume() in the first place. Why do we need to hold the reference for the operations going on here? What can race against this that might care about that reference count? Jonathan > > Signed-off-by: Dinghao Liu > --- > drivers/iio/light/gp2ap002.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/drivers/iio/light/gp2ap002.c b/drivers/iio/light/gp2ap002.c > index 7ba7aa59437c..040d8429a6e0 100644 > --- a/drivers/iio/light/gp2ap002.c > +++ b/drivers/iio/light/gp2ap002.c > @@ -583,7 +583,7 @@ static int gp2ap002_probe(struct i2c_client *client, > "gp2ap002", indio_dev); > if (ret) { > dev_err(dev, "unable to request IRQ\n"); > - goto out_disable_vio; > + goto out_put_pm; > } > gp2ap002->irq = client->irq; > > @@ -613,8 +613,9 @@ static int gp2ap002_probe(struct i2c_client *client, > > return 0; > > -out_disable_pm: > +out_put_pm: > pm_runtime_put_noidle(dev); > +out_disable_pm: > pm_runtime_disable(dev); > out_disable_vio: > regulator_disable(gp2ap002->vio);