Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp639572rwl; Wed, 5 Apr 2023 05:58:34 -0700 (PDT) X-Google-Smtp-Source: AKy350Zha49LwcxVWyeE8yO+2NoiaFfCEHtYIdycL59aAfZ4iGy+i1vjboHj32Ixvm6IMlYSoKrl X-Received: by 2002:a17:906:3ac5:b0:939:e7d6:7c52 with SMTP id z5-20020a1709063ac500b00939e7d67c52mr2719565ejd.20.1680699514224; Wed, 05 Apr 2023 05:58:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1680699514; cv=pass; d=google.com; s=arc-20160816; b=qVFpBNqgz6uxKd5w/SPBQg0ZOXfg9C3lx9zhYoGYc8BkEgUumTqREJr0jK0H149yhF SYJGWQERqJY2My2A4Q/BYBfdBENfXKdcooMMeuTl+e8MPQ4PSkmuTv86s8V4Uu2sQ8Jw rkCJUOOGkG6KiqEjOUVcdRCtO7dS5SLVy8yceJ5V2lJpf+RRRZ89tRda/t+U0Ry8e8wi hJxBA0klgOmwTlEa/FWnYGR9LYelLjUYzckT6IV21JayrOt+QfVtNlo1w4oDzf1uo0Ld N+zPBNfPJH4CuFThMxygs5n3ENjttJ0OtsEcPDX284uu4bAwUozgfhZ5IG7GE3bqoCOT mMjA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=HNlTPAbjdtS26ypADnDdofnih8dcbhDcszLgzK/cR+0=; b=pCVZ8c2X6yqot9bSu0168CmhMfayoK4TZnrOUcTQAP8dZ5Vpi9c44oCKn+/ipz4Szw lWfvw6eQc00hHruR8qAKvEFvgqF7gdpNRxVE1sJrVwERmljapx7ARrj1R1GzcNXm4e/m p8omQkxOVFeHnCFiw90Zj1xy1CGtH7djd5J+MeR0rtwUCOJl5OTpmwuEgSGvPIMTSFyw i+XpzlL5EseaXF2Rj0MPb27Df8JG/Fy4uPK6tkCQoHiN43A01fGHMrXIA4jcI6Pm3J8a ZfqkcVUo+ADWtFYSsRGXZcuw+nS3wFC+NJaQxoBks297twhiSPL06G1joQIhOkMh9jsr JsSw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@iki.fi header.s=lahtoruutu header.b=bI7FZgFM; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g9-20020a17090604c900b00930625d6a34si326789eja.972.2023.04.05.05.58.09; Wed, 05 Apr 2023 05:58:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@iki.fi header.s=lahtoruutu header.b=bI7FZgFM; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235652AbjDEMzo (ORCPT + 99 others); Wed, 5 Apr 2023 08:55:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238051AbjDEMzm (ORCPT ); Wed, 5 Apr 2023 08:55:42 -0400 Received: from lahtoruutu.iki.fi (lahtoruutu.iki.fi [185.185.170.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21F9530FE; Wed, 5 Apr 2023 05:55:33 -0700 (PDT) Received: from hillosipuli.retiisi.eu (dkzcv-3yyyyyyyyyyyyyt-3.rev.dnainternet.fi [IPv6:2001:14ba:4505:1fdc::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: sailus) by lahtoruutu.iki.fi (Postfix) with ESMTPSA id 4Ps4Ny5fhqz49Q2n; Wed, 5 Apr 2023 15:55:30 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1680699331; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=HNlTPAbjdtS26ypADnDdofnih8dcbhDcszLgzK/cR+0=; b=bI7FZgFMqo//ViNpPq7jYGOxhp9IesTmsJVAX0Eo5c7D6ga+bpA92xBtBLRiDa9OwVSrtB +nTDzTQyID4tjKmyR4TpS6doUA0xu8HagJGnoUI1ngkqbOnCQ0kQXPcLBEg6IUJ4SDciCC IP/xkhXdI3xIZg/BGvX14LVBrLDyalGAFndCb2cPuA0SuyamIe/odMhJ4qRDrxga8XD2NF 1BcP1VNcgLJ/q3W7gBpKWa8Qb2FVAI5Ty3xw5CacKhOpctyoyqJWA6xbewDwXwRm6dj1WX gtzqg4asxpRsgZbuV22pRytuzAGrzszawafHtnK6HEEyYK88RKkafZi7jRkL4Q== ARC-Seal: i=1; s=lahtoruutu; d=iki.fi; t=1680699331; a=rsa-sha256; cv=none; b=MrEsYbXqv8x/IMkRuiqwAMNR6s6kHHfREWcaSzHUlSnPlVxxCEFP4SvbobAFIE1KJFwxA7 EJb0safaC+6u0omwm4fTd2nLoG8cQXPPIgbQUa2ZBgiPUXx4VbqB1BDQrFYGUWOmLB+vwc /JGJ9XupAVcHPBvz6jWZrwsE1BYJCmdPavY2J5RbuzuDsRr/W4PY6vJjtCwgsQfCvkaay2 dhCf9FW/OFifHqghRQ0W4nCY2ldntAk0iM7UOiYRWeYeMvVFG731jAF5W5g3yoRG0k1g0r r5tKjqnVCCOMAZQlqdsWfRHlt0rHnW1uNw+QHUKc8ug4lmgGjyP71Dcf+sYzpg== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=sailus smtp.mailfrom=sakari.ailus@iki.fi ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1680699331; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=HNlTPAbjdtS26ypADnDdofnih8dcbhDcszLgzK/cR+0=; b=O3PXthfiZO+Fw2/XArNmAJKVG3Dgdv2a5dBezMRzTrzIdijwbbllX/PEhcBeeoWKBaL7Ql JKzBCk2hJxmd6TJexn04kUM5Tx3zWbMXYwKPqNC5Ei0+6cKRYVaXJa4d8JZhpUaMU0in0Z iVjXPu7h+Yw2BTDulmUTZmjZ/0vVDlyiJ61AAFZkg2cxV3fxNYeEUuVzk38jq+ZzGgUS+3 pUbeU6L0Fonff3Hny5UndBPqIqAyXbyTmpDv1HUbAXLXy6S9teYzedAM3aNsAgQiE4i0KF jp47D47tioQ6Yp4vhsfE+qcuInNEXyvv5NbS2OPLVWBRH14qoYGvtiAbO44PrA== Received: from valkosipuli.retiisi.eu (valkosipuli.localdomain [192.168.4.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by hillosipuli.retiisi.eu (Postfix) with ESMTPS id 4B2A7634C91; Wed, 5 Apr 2023 15:52:53 +0300 (EEST) Date: Wed, 5 Apr 2023 15:52:52 +0300 From: Sakari Ailus To: Martin Kepplinger Cc: mchehab@kernel.org, laurent.pinchart@ideasonboard.com, kernel@puri.sm, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v1 1/2] media: hi846: fix usage of pm_runtime_get_if_in_use() Message-ID: References: <20230405092904.1129395-1-martin.kepplinger@puri.sm> <20230405092904.1129395-2-martin.kepplinger@puri.sm> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230405092904.1129395-2-martin.kepplinger@puri.sm> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Martin, On Wed, Apr 05, 2023 at 11:29:03AM +0200, Martin Kepplinger wrote: > pm_runtime_get_if_in_use() does not only return nonzero values when > the device is in use, it can return a negative errno too. > > And especially during resuming from system suspend, when runtime pm > is not yet up again, this can very well happen. And in such a case > the subsequent pm_runtime_put() call would result in a refcount underflow! I think this issue should have a more generic solution, it's very difficult to address this in drivers only with the current APIs. pm_runtime_get_if_in_use() will also return an error if runtime PM is disabled, so this patch will break the driver for that configuration. > > Fix it by correctly using pm_runtime_get_if_in_use(). > > Signed-off-by: Martin Kepplinger > --- > drivers/media/i2c/hi846.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/media/i2c/hi846.c b/drivers/media/i2c/hi846.c > index 5b5ea5425e984..0b0eda2e223cd 100644 > --- a/drivers/media/i2c/hi846.c > +++ b/drivers/media/i2c/hi846.c > @@ -1544,7 +1544,7 @@ static int hi846_set_ctrl(struct v4l2_ctrl *ctrl) > exposure_max); > } > > - if (!pm_runtime_get_if_in_use(&client->dev)) > + if (pm_runtime_get_if_in_use(&client->dev) <= 0) > return 0; > > switch (ctrl->id) { -- Kind regards, Sakari Ailus