From patchwork Tue Apr 25 09:47:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kepplinger X-Patchwork-Id: 91547 X-Patchwork-Delegate: sakari.ailus@iki.fi Received: from vger.kernel.org ([23.128.96.18]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from ) id 1prFIZ-009qbH-UZ; Tue, 25 Apr 2023 09:49:24 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233707AbjDYJtV (ORCPT + 1 other); Tue, 25 Apr 2023 05:49:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233676AbjDYJtQ (ORCPT ); Tue, 25 Apr 2023 05:49:16 -0400 Received: from comms.puri.sm (comms.puri.sm [159.203.221.185]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47E737AA6; Tue, 25 Apr 2023 02:48:48 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by comms.puri.sm (Postfix) with ESMTP id E0A7DE218A; Tue, 25 Apr 2023 02:48:17 -0700 (PDT) Received: from comms.puri.sm ([127.0.0.1]) by localhost (comms.puri.sm [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id vushg0EI5uh4; Tue, 25 Apr 2023 02:48:16 -0700 (PDT) From: Martin Kepplinger DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=puri.sm; s=comms; t=1682416096; bh=htkeGWGZq0gFSHJqOcTrHfNQ30U5mGxJy6/7r//b6Ww=; h=From:To:Cc:Subject:Date:From; b=bgWqPBESIU25QMG7/GCBD90eLfRQVAlgRZK2DC+dUy1NoUeOZgI6WLOAto+XafvtU 14BqHGq/4Icn9TyHsY28eQnSMfZtuTWW+RTsrqiJ6bRzylat9aFmBrml/GNfTyxndl JYSuPzdCRvbQLiim5+6diwKW4pi/iXKH1VrzyL5KlLPS2X+1J31WjzjtEX8FNraASC 808vxtj88AgMR13q34oFsQDOXrwGYn48DdizcVAJYRl+Cqn28RNbR9RRXGMMfMEZBQ R98n5bgCBYTlQ3GhoE+a7msL+8OK1CHBJqxLdTxuntYGVzK4vby/34mV+zCr/3VDnT IEYw7qmDnp4Rg== To: laurent.pinchart@ideasonboard.com Cc: kernel@puri.sm, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, martin.kepplinger@puri.sm, mchehab@kernel.org, sakari.ailus@iki.fi Subject: [PATCH v2] media: hi846: fix usage of pm_runtime_get_if_in_use() Date: Tue, 25 Apr 2023 11:47:47 +0200 Message-Id: <20230425094747.2769693-1-martin.kepplinger@puri.sm> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham 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-media@vger.kernel.org X-LSpam-Score: -2.5 (--) X-LSpam-Report: No, score=-2.5 required=5.0 tests=BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1 autolearn=ham autolearn_force=no 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, -EAGAIN is being returned, so the subsequent pm_runtime_put() call results in a refcount underflow. Fix system-resume by handling -EAGAIN of pm_runtime_get_if_in_use(). Signed-off-by: Martin Kepplinger --- revision history ---------------- v2 (thank you Sakari and Laurent): * drop the other patch (the streaming-state in suspend/resume needs to be solved differently). * Sakari pointed out that many drivers are affected by this and that runtime-pm might need changes instead. I think this patch doesn't hurt and could serve as a reminder to do so. v1: initial submission: https://lore.kernel.org/linux-media/20230405092904.1129395-1-martin.kepplinger@puri.sm/ drivers/media/i2c/hi846.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/media/i2c/hi846.c b/drivers/media/i2c/hi846.c index 306dc35e925f..f8709cdf28b3 100644 --- a/drivers/media/i2c/hi846.c +++ b/drivers/media/i2c/hi846.c @@ -1353,7 +1353,8 @@ static int hi846_set_ctrl(struct v4l2_ctrl *ctrl) exposure_max); } - if (!pm_runtime_get_if_in_use(&client->dev)) + ret = pm_runtime_get_if_in_use(&client->dev); + if (!ret || ret == -EAGAIN) return 0; switch (ctrl->id) {