From nobody Fri Aug 14 15:49:22 2026 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 713924749EE for ; Fri, 14 Aug 2026 13:41:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786714879; cv=none; b=nJF8TcRudGCRQhZb/IRgpB31Qs2OJHRJrgrHIEZxr76QxJSxs/MeIOZVAd7NUDmgicH+hsH8JPduo5abAK6EtWE57thw1/9f4RDj4FloP/hBfu3X2JXcnJMNpZuxH3JVTZmuBnTZzykpaoLa1tQBTzUcZpPMytajXdok/dqOeuo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786714879; c=relaxed/simple; bh=d1Gvs4AL/f4vX3QgVhKPTz1KJyFcjbEiYJDmT1kb2Fw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Vc9Z3rrAqm7gYQn+EJ3o/iK2FL5wWjTtox3peEQchVsxswMSKw1JeNXDK4MG6s9OXrN7ahOjoKgbLu8OhMpcT8HAF27YVem1eJA3TtEAJcP6V4fTyuQxEonJSM/fZDgqLapg/jWpQ/vsrp29+fuDf66Jbjgt3ODfgHtDAYhH8cM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=d/V2rZYm; arc=none smtp.client-ip=209.85.214.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="d/V2rZYm" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-2ceb096e675so12827555ad.0 for ; Fri, 14 Aug 2026 06:41:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786714878; x=1787319678; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=N51mCAdH2/WtaJCTP7hQirjbIZKOCCBLaOzBiUgg0fk=; b=d/V2rZYmJSN0aTzkeq16PM4hXmyZ3ihMWVBgNTGbZVP5mzeXDnCzTweIwb+WoqbJQH 6IEu8KQLbXh7NOVWJOwe24KLShbz0vcpAEWW2h2b+pZk2BFkpzqJ6UNY3ChQgt+LJu64 cQFlXTyJjK/kQw9rCFDj6Ts8clgeEvEuE1oD4i/xRluXCawpCnG95nPui76rrEQwB75U k1SC94S76H1D3jHU/wnWsbyjMUacDUAYkRjC8duEKNj8ajcYsBw5yB576kOcJgIZFsKY l5C485I0ciN/kwnXau3oacuzGN/vAFTcvvXfmQpBCEJN1ZBDvmvhiVgFcjqUpmoCO8lN ojNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786714878; x=1787319678; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=N51mCAdH2/WtaJCTP7hQirjbIZKOCCBLaOzBiUgg0fk=; b=Em1snJIPfrnn7FC/GLURSgbFVXtiTnZJjOU/X6qWQYCXQsZIkuR09IT80e1dEDrLUr bnF6D4B7qQAH4392IWPJ+qZoiWVX6g6ecQ0YSgZS/a73lbzn3ttjiePsisEstjCuglBN Ab3Z73M2+6y+R9rRIwo6NLY+3yg1AAJ3+nvmYgJRv16yZaGR15n7wccUBfwJq3V26SZ6 RfJQBfHgJ4g13JCni19PYgy+e60uOMXLL+5wuw9hlKvfbQz+ZwJQKDCGZz28Am3pcTb1 oMek3/OZN8y3zoblkZcqjNi0BjXMBOQVgWft4fxjwqTaO+2/mrNVexqxfRTQcJGahXAs mPwA== X-Forwarded-Encrypted: i=1; AHgh+Ro1ZnTOJ1O9j+IH+lU8mW98laXKdBqJyFQMzGlmoR2WJ0nfz+sKRj9rk+qDSWS020F3PXF5dbAMKWU4erM=@vger.kernel.org X-Gm-Message-State: AOJu0YzL8A2PlD8gjj38bPmStFIxR8mSft7EXNMms12MFbMqBIeaKyI3 i2qL5DZ1A6F/xLHRbg8r704Y3JaYi/KC4tZx/rIiOkhcNyY9f5nlpMYu X-Gm-Gg: AR+sD10bn42yzon3EWtU/S2MDJuthgqs8flqKrNWsgrAoasxcvn9RBhC6Uv+27hWwWP te8cLLlgkRnIAbckQrS4esD8kCCfyM8HneJ123MdTjOZPKG8fsQkO01NI42/LvsFO44nuacfVAr nu/Ilr/AwIcAMX7+wNVXWKRCDXaoXTsBffZFGIuU7x9RUwMVIpooxOjaEDlFFf9rpRj/FOXeRZP 6HjRsJst723/kLYMPKsbfO38VteKcK04AfgxguDGfeRiy93KNFlNHkAg+m/TwySKnqP/5yvcJvM 5a72AxyJE97EcdQ8VS4OH0ZX/esECzSj1lVt1TpVTtsNxejR8XgSZCBhyF/ouTe2MNr8cIZTzX2 wBpI8QvHvmENO9eoplhyYwobQEzCq26uw5ojLzWevafxB/Rl13u4CTEMfRLMIhGvI/cW2VcH9y5 t4Yy3hZuto6z1lahvoTtL5MViRkoaztHqBZIWhFNnfgzSC40Nbd873P/gOaUfHI5W4j8pYxQVCF ylPjYGz X-Received: by 2002:a17:903:1a86:b0:2d1:134:b86e with SMTP id d9443c01a7336-2d3b082b567mr66513245ad.2.1786714877703; Fri, 14 Aug 2026 06:41:17 -0700 (PDT) Received: from haichao.tail057a43.ts.net ([2001:da8:e000:1206:e9af:7c0e:be31:2c3f]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2d3aebc3a08sm9516005ad.69.2026.08.14.06.41.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Aug 2026 06:41:17 -0700 (PDT) From: Ruoyu Wang To: Linus Walleij , Jonathan Cameron , David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , Andy Shevchenko , Lars-Peter Clausen , Alexandru Ardelean Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Ruoyu Wang Subject: [PATCH] iio: gyro: mpu3050: Fix runtime PM leak on trigger errors Date: Fri, 14 Aug 2026 21:41:11 +0800 Message-ID: <20260814134111.1387580-1-ruoyuw560@gmail.com> X-Mailer: git-send-email 2.51.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The first user of the MPU-3050 data-ready trigger takes a runtime PM reference before configuring the FIFO, sample engine and interrupt. If any of those operations fails, iio_trigger_attach_poll_func() tears down its IRQ resources without calling set_trigger_state(false). The buffer error path then releases only its preenable reference, leaving the trigger's reference held and preventing runtime suspend. Use pm_runtime_resume_and_get() so a resume failure does not leave a usage count behind. Route later setup failures through a common unwind that clears hw_irq_trigger and drops the trigger's reference. Successful enable and disable behavior is unchanged. This issue was found by a static analysis checker and confirmed by manual source review. Fixes: f11d59d87b8622 ("iio: Move attach/detach of the poll func to the cor= e") Signed-off-by: Ruoyu Wang --- drivers/iio/gyro/mpu3050-core.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/iio/gyro/mpu3050-core.c b/drivers/iio/gyro/mpu3050-cor= e.c index d84e04e4b4314..33a98a6e9cb84 100644 --- a/drivers/iio/gyro/mpu3050-core.c +++ b/drivers/iio/gyro/mpu3050-core.c @@ -988,20 +988,23 @@ static int mpu3050_drdy_trigger_set_state(struct iio_= trigger *trig, return 0; } else { /* Else we're enabling the trigger from this point */ - pm_runtime_get_sync(mpu3050->dev); + ret =3D pm_runtime_resume_and_get(mpu3050->dev); + if (ret) + return ret; + mpu3050->hw_irq_trigger =3D true; =20 /* Disable all things in the FIFO */ ret =3D regmap_write(mpu3050->map, MPU3050_FIFO_EN, 0); if (ret) - return ret; + goto err_pm_put; =20 /* Reset and enable the FIFO */ ret =3D regmap_set_bits(mpu3050->map, MPU3050_USR_CTRL, MPU3050_USR_CTRL_FIFO_EN | MPU3050_USR_CTRL_FIFO_RST); if (ret) - return ret; + goto err_pm_put; =20 mpu3050->pending_fifo_footer =3D false; =20 @@ -1013,12 +1016,12 @@ static int mpu3050_drdy_trigger_set_state(struct ii= o_trigger *trig, MPU3050_FIFO_EN_GYRO_ZOUT | MPU3050_FIFO_EN_FOOTER); if (ret) - return ret; + goto err_pm_put; =20 /* Configure the sample engine */ ret =3D mpu3050_start_sampling(mpu3050); if (ret) - return ret; + goto err_pm_put; =20 /* Clear IRQ flag */ ret =3D regmap_read(mpu3050->map, MPU3050_INT_STATUS, &val); @@ -1037,10 +1040,16 @@ static int mpu3050_drdy_trigger_set_state(struct ii= o_trigger *trig, =20 ret =3D regmap_write(mpu3050->map, MPU3050_INT_CFG, val); if (ret) - return ret; + goto err_pm_put; } =20 return 0; + +err_pm_put: + mpu3050->hw_irq_trigger =3D false; + pm_runtime_put_autosuspend(mpu3050->dev); + + return ret; } =20 static const struct iio_trigger_ops mpu3050_trigger_ops =3D { --=20 2.51.0