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.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,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 5652EC433B4 for ; Wed, 5 May 2021 12:27:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 21DEB613BC for ; Wed, 5 May 2021 12:27:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233333AbhEEM2k (ORCPT ); Wed, 5 May 2021 08:28:40 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]:3022 "EHLO frasgout.his.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232314AbhEEM2j (ORCPT ); Wed, 5 May 2021 08:28:39 -0400 Received: from fraeml736-chm.china.huawei.com (unknown [172.18.147.201]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4FZwkg6MwCz6rlcx; Wed, 5 May 2021 20:19:39 +0800 (CST) Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by fraeml736-chm.china.huawei.com (10.206.15.217) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Wed, 5 May 2021 14:27:41 +0200 Received: from localhost (10.52.120.138) by lhreml710-chm.china.huawei.com (10.201.108.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Wed, 5 May 2021 13:27:41 +0100 Date: Wed, 5 May 2021 13:26:02 +0100 From: Jonathan Cameron To: Mauro Carvalho Chehab CC: , , "Paul J. Murphy" , Daniele Alessandrelli , Mauro Carvalho Chehab , , , Dan Carpenter Subject: Re: [PATCH 06/25] media: i2c: imx334: fix the pm runtime get logic Message-ID: <20210505132602.00004b1f@Huawei.com> In-Reply-To: <20210505132426.201e9262@coco.lan> References: <9552f3daece8bec6869b518410b2998c3fc0a1fc.1620207353.git.mchehab+huawei@kernel.org> <20210505121040.00002094@Huawei.com> <20210505132426.201e9262@coco.lan> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; i686-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.52.120.138] X-ClientProxiedBy: lhreml725-chm.china.huawei.com (10.201.108.76) To lhreml710-chm.china.huawei.com (10.201.108.61) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 5 May 2021 13:24:26 +0200 Mauro Carvalho Chehab wrote: > Em Wed, 5 May 2021 12:10:40 +0100 > Jonathan Cameron escreveu: > > > On Wed, 5 May 2021 11:41:56 +0200 > > Mauro Carvalho Chehab wrote: > > > > > The PM runtime get logic is currently broken, as it checks if > > > ret is zero instead of checking if it is an error code, > > > as reported by Dan Carpenter. > > > > > > While here, use the pm_runtime_resume_and_get() as added by: > > > commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") > > > added pm_runtime_resume_and_get() in order to automatically handle > > > dev->power.usage_count decrement on errors. As a bonus, such function > > > always return zero on success. > > > > > > It should also be noticed that a fail of pm_runtime_get_sync() would > > > potentially result in a spurious runtime_suspend(), instead of > > > using pm_runtime_put_noidle(). > > > > Irony here is that pm_runtime_resume_and_get() returns <= 0 so with that > > function change, you can stick with if (ret) and still be correct. > > > > So only one of the two changes is needed to fix the bug. > > Yeah, I noticed ;-) > > On media, almost all devices have I2C bus(es), and I2C send/receive functions > return positive values. So, a good practice is to check for errors with: > > if (ret < 0) > > That's why I opted to keep both changes here ;-) Fair enough. Reviewed-by: Jonathan Cameron > > Regards, > Mauro > > > > > J > > > > > > Reported-by: Dan Carpenter > > > Reviewed-by: Daniele Alessandrelli > > > Signed-off-by: Mauro Carvalho Chehab > > > --- > > > drivers/media/i2c/imx334.c | 7 ++++--- > > > 1 file changed, 4 insertions(+), 3 deletions(-) > > > > > > diff --git a/drivers/media/i2c/imx334.c b/drivers/media/i2c/imx334.c > > > index 047aa7658d21..23f28606e570 100644 > > > --- a/drivers/media/i2c/imx334.c > > > +++ b/drivers/media/i2c/imx334.c > > > @@ -717,9 +717,9 @@ static int imx334_set_stream(struct v4l2_subdev *sd, int enable) > > > } > > > > > > if (enable) { > > > - ret = pm_runtime_get_sync(imx334->dev); > > > - if (ret) > > > - goto error_power_off; > > > + ret = pm_runtime_resume_and_get(imx334->dev); > > > + if (ret < 0) > > > + goto error_unlock; > > > > > > ret = imx334_start_streaming(imx334); > > > if (ret) > > > @@ -737,6 +737,7 @@ static int imx334_set_stream(struct v4l2_subdev *sd, int enable) > > > > > > error_power_off: > > > pm_runtime_put(imx334->dev); > > > +error_unlock: > > > mutex_unlock(&imx334->mutex); > > > > > > return ret; > > > > > > Thanks, > Mauro