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: 677455 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CFF24C77B61 for ; Tue, 25 Apr 2023 09:49:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233707AbjDYJtV (ORCPT ); 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 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org 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) {