From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (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 AA71947427C for ; Tue, 18 Aug 2026 13:31:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787059865; cv=none; b=u4KTAxKHZ1KEhjFJAssY49sETvhL9hWQQn9Dk+88GkTNt/24SmpVWdu9Oepn91drEQFHirdLkzJuggvD89znvLWrNz1kCUwal0EPHI02kPArC4Y/Mw7GGS2H7pbA9K0uYYlMCcvkg/lP5Q3TOZ0bSc7iD20li7dTp9Q9FtKgQQA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787059865; c=relaxed/simple; bh=T0JJJLUuhNcrIAsh1KIF8Nwu4qzw5TFxBskkWdQOYYk=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=goJ78iKkvBzMdh1iPlAg9ICkkfEiTX3f1BQ/99+FvgfC7aR+hW62c7jHIhDrxg3jSu9FljABk8b5EM84ADnyUg8YDXEDh2+iI7FKhgmNGjoazutvM7F2A2wv7PDaUj7B4KzGUilDMfoGpOnokoAAh+QweprAZC0T5l7GcCOQgSY= 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=ob4cudml; arc=none smtp.client-ip=209.85.210.178 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="ob4cudml" Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-84f38f3b36eso3036583b3a.1 for ; Tue, 18 Aug 2026 06:31:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787059864; x=1787664664; 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=LNuQ7ERVi19pNvBz+ivTEZwwR+8EHVvrbTUExY6Tln8=; b=ob4cudml3zQFT5rbZbSeBR7P/KeBFxZS+tk1+zj9ipSl83NyaLbqYQ2nYDvTPDUA6z 4VG+6+wgP5mOvc/PfFxP5Mvay/o+AsUE3Q5lSe6qbRlQgBt79K85y/5Zaq5nwazCEchK buz2vr8gIIPPYvGH4RD549IxxF4uAVP6NYEPF+8dUj3vCWvoTRIamk6ktb2nNhUlruMB oTIbaai5zezQTd5Cbs0ICa8ufKGdb9bQmnrznw+gadqTlOYZs1LiagmRzkFwtqm7ezSQ F/y0Ap+RBf8L0x05Uir+oPLI1o2g2UI28c9Hj/bLhA1egL0mTlvmYNSGsXlcXBx0tuQK 847g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787059864; x=1787664664; 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=LNuQ7ERVi19pNvBz+ivTEZwwR+8EHVvrbTUExY6Tln8=; b=g/pHDbEjVv/6PxR2FFMihBkT4ZspJiUbSla28lvw19/rKq2yjoBb1Rajaq9VVFXdo9 ipP0hETl1Z2/yl/LIK2Tmo+AWAP7Zc0TLGHXUZ57JqjnEqkpx90/iM3glYEg9OII/Okz 7C9sdWcox13YMcJFBEbqBBQAC9kfJYsRqDOfmxUYPtSDsyEEpTkjcfgFwbPV4p3sB0fV wKXgiJmLl+3WvuUvT5FMtgbVI9kAreMObil9L2Ajk7nFW4w/rtg1M8BZ+rrURk1CFpoM O8XAuSBBBn6H3x2ZtQ2k1bAVobg/JRSD66/IwZKgYuXB5+mbZx052Cj5K05Hrl2zK5Cb oVBA== X-Forwarded-Encrypted: i=1; AHgh+RpLDV0JirDN1YD9Kj2fxq3HM9MtsoZHSkCsVeO2DsO2tUJ+wWodA2MenzBBSuc8Wg7NqGZVNzxw0d6qq/I=@vger.kernel.org X-Gm-Message-State: AOJu0YwZpINT1qvPWc9nnOrHCnntsROZvIcjNQbXx/bJT3xDJXYOZqEl 3Gz/jhD2Hpnb5+lrbkk02h6/RR0gc+4nfi01dESN55gDFrGBDySDNwEk X-Gm-Gg: AR+sD11BxyANSPyElHO6DGIiqJze1mr5UyNQ285ibxxL/2fTyPbLnNtUs1qrUa+OUdE w1viTCiIcu9N+bz49f2Vr/dxp6Lg7Gn0lIfRowGsRsiAwVtNyDpRB56FQel5hBCKKMvcPqkOkzQ FIAA8EhvcvE5NdUHy8dzCHPLBghDorfmNRZ3iIxi837ppKS9rUfArAWO6lPxPoRaa+IHMyVCZot emUmKZJSs8Bmz5K5mZ7xEv4SvTOOmN3nTDSdcffPMT4cfAN4y0uLs+u1w6M6CReG3qQ4IGfbVtv C3MzDw3Ddd2qeSfBHGyQOZ+4KI+FrRok5CI+hUxelXtSkIuc5Hz4ia0NZc88gp3e97z9gGPE8Is FjVL+QQ6Z7e4xs2XFDnWXG/TYANpBItj+z73O7U+i38Ab95d7WKYYCL0lHkOlQMrkqSp03DtLGG 1qYhIXMH4y7iSQazCSyo8HPqH3HXoLn0Rmi+nhm+II0hD56YgFhYSS2iImjPlmYJgRZieudHvnn 5X8mOUy X-Received: by 2002:a05:6a00:428e:b0:848:8445:6956 with SMTP id d2e1a72fcca58-84fde223e4cmr36519557b3a.18.1787059863800; Tue, 18 Aug 2026 06:31:03 -0700 (PDT) Received: from haichao.tail057a43.ts.net ([2001:da8:e000:1206:2c00:7ca6:1bcd:6269]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-851c2fc690bsm644505b3a.14.2026.08.18.06.31.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Aug 2026 06:31:03 -0700 (PDT) From: Ruoyu Wang To: Linus Walleij , Jonathan Cameron Cc: David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , Andy Shevchenko , Andy Shevchenko , Lars-Peter Clausen , Alexandru Ardelean , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Ruoyu Wang Subject: [PATCH v2] iio: gyro: mpu3050: Fix runtime PM leak on trigger errors Date: Tue, 18 Aug 2026 21:30:46 +0800 Message-ID: <20260818133046.858005-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: 8bit 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_ACQUIRE_IF_ENABLED_AUTOSUSPEND() so a failed resume does not leave a usage count behind and later setup failures automatically release the acquired reference. Disarm the scoped cleanup after the interrupt has been enabled, leaving the disable path to release the trigger's reference. Keep hw_irq_trigger clear unless interrupt setup succeeds. 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 core") Suggested-by: Andy Shevchenko Signed-off-by: Ruoyu Wang --- Changes in v2: - Use the PM_RUNTIME_ACQUIRE*() cleanup API requested by Andy Shevchenko. - Retain the runtime PM reference only after trigger setup succeeds. Link: https://lore.kernel.org/r/20260814134111.1387580-1-ruoyuw560@gmail.com/ --- drivers/iio/gyro/mpu3050-core.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/iio/gyro/mpu3050-core.c b/drivers/iio/gyro/mpu3050-core.c index d84e04e4b4314..d3ae998445115 100644 --- a/drivers/iio/gyro/mpu3050-core.c +++ b/drivers/iio/gyro/mpu3050-core.c @@ -988,8 +988,10 @@ 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); - mpu3050->hw_irq_trigger = true; + PM_RUNTIME_ACQUIRE_IF_ENABLED_AUTOSUSPEND(mpu3050->dev, pm); + ret = PM_RUNTIME_ACQUIRE_ERR(&pm); + if (ret) + return ret; /* Disable all things in the FIFO */ ret = regmap_write(mpu3050->map, MPU3050_FIFO_EN, 0); @@ -1035,9 +1037,14 @@ static int mpu3050_drdy_trigger_set_state(struct iio_trigger *trig, if (mpu3050->irq_opendrain) val |= MPU3050_INT_OPEN; + mpu3050->hw_irq_trigger = true; ret = regmap_write(mpu3050->map, MPU3050_INT_CFG, val); - if (ret) + if (ret) { + mpu3050->hw_irq_trigger = false; return ret; + } + + retain_and_null_ptr(pm); } return 0; -- 2.51.0