From nobody Fri Jul 24 22:51:57 2026 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 A6B874322FF for ; Wed, 22 Jul 2026 16:23:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784737384; cv=none; b=AQr2gPvqMQUElmVwxkuMxLeVITYwT2cNv/F7Egm3rbOU1jEXMtsoMJ3P7YNS444TlFZuRuevz5suZHvtTlBLd5zuAqz3uuDgwI8Cof4/+PYlxF2zQLxPr4pelBF5wf28U+e6h1u+i9q1NuwIiQoxw0D5kydQ0YtyQy1/IFlBRZ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784737384; c=relaxed/simple; bh=b1zwzYrehw2xMiWnP3qCyD8im9SRTQveIPIOMZLKT+Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WcTl9JtzmCLCBH2rJ67WCxMURcnf74or8GneNyJLz9BjX7K8JNYeccyhXF0vXDH6KS+0nwz8tZQ5QW/02fUu72QLWi7ZAqWxHvACX5OOf5evLl8/FzMlpxmfTIzFljyMp+0cRUasG30XEkcaGHPkKBUM3x1E9mMxlMBbz2c4AEU= 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=EPD0YiEM; arc=none smtp.client-ip=209.85.214.182 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="EPD0YiEM" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-2caf228a910so101842335ad.2 for ; Wed, 22 Jul 2026 09:23:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784737382; x=1785342182; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=jUyRifTnAdWj9oo8ReezTF2SEzJ7h//arZ1iHXc2iOE=; b=EPD0YiEMo2RVUVO6QZYs3rC/cxuYbI80TXdGaWKx3JliJ9cCOpd6J/LBpt0mf/KM4a 7WeNu3KMdMha5zB3jf2jkTfhgukvoNcHumxF2HZ4aEMaZ24WxtlAb1SgyOiSNTj4WuEn v8ej1sY1U8c0yRLLF7rGpnWRMX2kDA4xSAo8+7Ga13ZyAt4EypZeSdW1JaXKjtfP+FrH sTfscTN5Ebpu4ckXEPtevUigLaTLqfdU2N3L17l40X7attFqoLEpwy0iVU2Qpk/RV75V WRdFSRy7tdhlG6v/GmT/I4k5sSDxPVnjDUhdjymFLs/XcVcO3gUWk/6bZw9ut19fkHTJ JpqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784737382; x=1785342182; h=content-transfer-encoding:mime-version:references:in-reply-to :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=jUyRifTnAdWj9oo8ReezTF2SEzJ7h//arZ1iHXc2iOE=; b=VVluY8qYKdp1NbRZRHGMHPnpANZXtjLyCmU6lilMguVZseyYl8985cBqlS1Z+w6uEU eHosm7SOizG0umlTxWzPsQAXpvSFBTGUnbDuQrT859zT6WyFLBiNxvb3z+/7K1XUPqE2 8V5RA2WHCg36LlC2jCCLSDuvqzhq6YrRPYp5q45pN+mYzx2Irsh0OZMEoexWQTUg/p5j p4atIlhxnGx0gnKrKE21c4zgZSFTB3Hw0EZ6mQFjBsJYfSkbsaA9kwCAQ1xiV2tL80PC 1csovHhF670LYB/CV6SKogiRoCX7adDXW+E/V3zaCeYuV1zcjevf2cYwAqtL30QUAtNf BJ0w== X-Forwarded-Encrypted: i=1; AHgh+RrNadj2dW3XwHfUgkSGDMIWNRBqDBAo0yU6QK/VXiFgjO3zE4ugo4bDucSMDqGPyNaMQsI7m3IhS83x34c=@vger.kernel.org X-Gm-Message-State: AOJu0YwqI6rzarjiF5gKQFxMz9/QpkbeKUlbzolVmW7LuQpdd7DAn3Qr ihtugAnmlzhYW3s/sDDyV+JBuD5WdSj1uU+n27DvtOP0X8hvmjtlwfs= X-Gm-Gg: AR+sD13Y/QuxFPB0uQ5z0W0GNqLMou+GhvqS3RbvPM9Ij+hNzwFi3sZQAXc1FuBJ3Lu /sF+TlBc2psimTGUvmaccaQzw/GGboEUzsahvcVvzMtFAFL9Yb4oUng+u5JmMSM+1djYQbIsXiN 7iG9bPREpg0bh6cSjzChu2f3xu1/7eVOoBO8DIRahuTPZJTZ/u4ilpi5xl8Wv+7iqWlhjNVG7+G hgrBfiT9y8jZ9xuvNeclVEYkvczmvf/3VWy/k2uKIOSlc7AMjBCko8437Dq8kU2LMpxfUtXC11v H3K36Jja7CptNpy8T1PYJRQogamFmUmGUphQA3oHpDGoisjiHz1aKqrmcS/1kVbCOzIxzwawUwU Q4N2qvbcNCGhXvXrPO926D0pUw5UgAz+fbSazfZzcLF8DYZJSIR8xj+Vm088WpkebrTl/umLTGP oHbwpoYsTrExupYxVcLTwFfvzu/zs0vKK5HhYcxRpeECryIKFABS8j X-Received: by 2002:a17:902:e944:b0:2cc:f7c6:8320 with SMTP id d9443c01a7336-2cf34a28988mr236046735ad.46.1784737381719; Wed, 22 Jul 2026 09:23:01 -0700 (PDT) Received: from localhost.localdomain ([101.0.62.129]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3147dc1e3d9sm9260471eec.5.2026.07.22.09.22.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jul 2026 09:23:01 -0700 (PDT) From: Nikhil Gautam To: Jonathan Cameron Cc: Linus Walleij , David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , Andy Shevchenko , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Nikhil Gautam Subject: [PATCH v2 1/3] iio: light: gp2ap002: Fix unbalanced runtime PM on repeated event writes Date: Wed, 22 Jul 2026 21:52:45 +0530 Message-Id: <20260722162247.8229-2-nikhilgtr@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260722162247.8229-1-nikhilgtr@gmail.com> References: <20260722162247.8229-1-nikhilgtr@gmail.com> 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 IIO core does not filter duplicate writes to the event enable attribute, so writing the same value twice invokes write_event_config() twice. Enabling twice leaks a runtime PM reference, preventing the device from ever suspending again; disabling twice underflows the usage count and triggers a "Runtime PM usage count underflow" warning. Bail out early when the requested state matches the current state. While at it, switch to pm_runtime_resume_and_get() so a failed resume is propagated to userspace instead of silently marking the event enabled. Fixes: 97d642e23037c ("iio: light: Add a driver for Sharp GP2AP002x00F") Signed-off-by: Nikhil Gautam --- drivers/iio/light/gp2ap002.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/iio/light/gp2ap002.c b/drivers/iio/light/gp2ap002.c index 42859e5b1089..966459994995 100644 --- a/drivers/iio/light/gp2ap002.c +++ b/drivers/iio/light/gp2ap002.c @@ -343,6 +343,10 @@ static int gp2ap002_write_event_config(struct iio_dev = *indio_dev, bool state) { struct gp2ap002 *gp2ap002 =3D iio_priv(indio_dev); + int ret; + + if (state =3D=3D gp2ap002->enabled) + return 0; =20 if (state) { /* @@ -350,14 +354,15 @@ static int gp2ap002_write_event_config(struct iio_dev= *indio_dev, * already) and reintialize the sensor by using runtime_pm * callbacks. */ - pm_runtime_get_sync(gp2ap002->dev); - gp2ap002->enabled =3D true; + + ret =3D pm_runtime_resume_and_get(gp2ap002->dev); + if (ret) + return ret; } else { - pm_runtime_mark_last_busy(gp2ap002->dev); pm_runtime_put_autosuspend(gp2ap002->dev); - gp2ap002->enabled =3D false; } =20 + gp2ap002->enabled =3D state; return 0; } =20 --=20 2.39.5 From nobody Fri Jul 24 22:51:57 2026 Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.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 11E0B439F99 for ; Wed, 22 Jul 2026 16:23:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784737388; cv=none; b=ka1UpAT8Y49J29ObqgNnwZ30p0yJQhLJVxJ6NVvCQzaoROuXJSe3o6ufNQFg1ENG3rWNe72F7V9+igXXAnvfOkBoYgPKydvr6ueWmnGnGuA2nKSFkzZ0p6JcOJJtGvVptutjmKlwi63+dBDjAUoCbtFEua/fO2zqT8cZgTfAxus= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784737388; c=relaxed/simple; bh=dpiqy8v3njUhl+5M8+H78HgeeoztOF42HF07K+INYGQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Yq+g2eccfy16fXegSDWFHxxCoNR0zGheXXY5RcN1DJWgf623xfllvh5qvnWGLlmC9hRJ4AFbdqQbnOTFEC18I2zIDbOJyCPiTyAhRerqYrrRlxGcCwVPJddVGDh3BJSbCj81ElBV8KqnwZ5VK1SR7p+IDw/z8RZXUnAST+svj3I= 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=BKiBQXKJ; arc=none smtp.client-ip=209.85.215.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="BKiBQXKJ" Received: by mail-pg1-f178.google.com with SMTP id 41be03b00d2f7-ca88130e09aso7940531a12.3 for ; Wed, 22 Jul 2026 09:23:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784737386; x=1785342186; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=LdG079b6jK+3Fw2UuAshVoyvrHhYqH1e6aG8pN/SHkE=; b=BKiBQXKJe2Lm5zfmmUiNYRShJjd8Q66d0SlvQiH6YWFXoeQ+vDUnzTkJobLJXzfHKq ErBtsvG04VNJ6CxvC18JRw0wl3hu3e5+Ve2WEEehcVT3HkYjStqr9MT7EReyioDMk2LG zASkO8u92H4P3MyRXx5CI3py7yhdZPAfhRPWnXBNmGu+RreoXSdbrFZp4/YsvioSauhC HL++XY04arqLkNE4c19HJjpddvl0IcU2A2dlhbZi7mxIMulI5q/j+xBgryIjg1Ooaqa6 BTUvcuUKHi2Ym4A5Z2HD8o8VQbAVHHr1gaDIDP48TPP+YBKwma1QDzksiZ1SSfRzgllT MOWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784737386; x=1785342186; h=content-transfer-encoding:mime-version:references:in-reply-to :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=LdG079b6jK+3Fw2UuAshVoyvrHhYqH1e6aG8pN/SHkE=; b=VZ1QG3xyc7aWTvltXiB8P7++EWpPzYkSHv0Bgk2PHkcNRjfTenMxFW0u9B6Qaig6n4 EEdFZ4q1navJxrrVJK2PIX+dg9QKBi+P27241Yejk5VgtejPQN1EtJxwpQ/IQN9wn0OJ Avm3d0MYYgljQHrC8VW2vc1FtgUBx4Gckr8+mLFY7kZoc5dxJtrz0fKoJChXjO1iOrjS K6dQJd6XFW/3OuR3fckOYVuAMDg92r8FwHVYUAk6I27nW652PIPSmO5My75bq5cUrsmY 4akbXMpLlNQHVYlk12iCwNlpkOA6mro0hMHTGiOTxXNyEh+oEadhYx19CkSl/7kXDtf/ GQtw== X-Forwarded-Encrypted: i=1; AHgh+RoL6YTYt3aYAF+5ezUb0w917UJ34YIa8HdS8OTp7VaOMU2V8O00vseo9bPgG3sopCeQ62yO83cZoOrCWzQ=@vger.kernel.org X-Gm-Message-State: AOJu0YzCnszpZL+eFUYHCQ98f+Rc1XKhG++SBrMV/otTA+3TUx+4X6Ee z3VvEswO4z9acQZULAHekS9KB4y2FWbVEn2uXBvxQyja1Cc7HkfRr0g= X-Gm-Gg: AR+sD11syD/2a7HCjlwxzv0XpRNgzdeRqwD2QwOJ+AywZz/JXr9XP5wQ/fLrRvbkXAM vKWmDOCgRrRTWlW04nf44BICsHlJXYinNNXV/1aaD96nWNupb+6OX5atnbx7ToD5jOjHEEgDxbD 7AlVEu9yaMbBbMIl+65eNsMnGwHXcmPHDnoDcHdvUIXPCoOJ9OGlkQ1+5VKvrvcwYcJowon1Wik 7OJm9jGAtphu1TfF5ObPvKIOLGzaD4lua/DZ2BvKALnOzt+TCu9vEM3p7ABv0j6Ys9bUSk7+bgW y9wTTTBAZeIk3qxLP6LpXlfVMztG33kCaZIsiyy/N+0gj5kPie1dhrXJa3IfrXIW0sZ225Ij4JF DzW3H+7rcaE96MBvi25kbbpE7sbIMYLSZ5MX9ZLutjpRB3ozHEuPQbJu9ue4rr3GQeGnPLY0tb5 i4wHRl52tKEb+o45qRCzpDJ5bg251tPskuqNPnYZ9vOQ== X-Received: by 2002:a05:6a20:4c8:b0:3c4:1c9f:d90 with SMTP id adf61e73a8af0-3c41c9f2e30mr7154477637.39.1784737386122; Wed, 22 Jul 2026 09:23:06 -0700 (PDT) Received: from localhost.localdomain ([101.0.62.129]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3147dc1e3d9sm9260471eec.5.2026.07.22.09.23.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jul 2026 09:23:05 -0700 (PDT) From: Nikhil Gautam To: Jonathan Cameron Cc: Linus Walleij , David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , Andy Shevchenko , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Nikhil Gautam Subject: [PATCH v2 2/3] iio: light: gp2ap002: re-enable irq if runtime suspend fails Date: Wed, 22 Jul 2026 21:52:46 +0530 Message-Id: <20260722162247.8229-3-nikhilgtr@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260722162247.8229-1-nikhilgtr@gmail.com> References: <20260722162247.8229-1-nikhilgtr@gmail.com> 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" gp2ap002_runtime_suspend() disables the irq before writing OPMOD. If the write fails, the callback returns an error with the irq still disabled while the PM core marks the device active again. re-enable the irq before returning the error so the irq state matches the active state the PM core restores. Fixes: 97d642e23037c ("iio: light: Add a driver for Sharp GP2AP002x00F") Signed-off-by: Nikhil Gautam --- drivers/iio/light/gp2ap002.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/iio/light/gp2ap002.c b/drivers/iio/light/gp2ap002.c index 966459994995..e8ba9c00dabb 100644 --- a/drivers/iio/light/gp2ap002.c +++ b/drivers/iio/light/gp2ap002.c @@ -649,6 +649,7 @@ static int gp2ap002_runtime_suspend(struct device *dev) /* Disable chip and IRQ, everything off */ ret =3D regmap_write(gp2ap002->map, GP2AP002_OPMOD, 0x00); if (ret) { + enable_irq(gp2ap002->irq); dev_err(gp2ap002->dev, "error setting up operation mode\n"); return ret; } --=20 2.39.5 From nobody Fri Jul 24 22:51:57 2026 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) (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 64625432303 for ; Wed, 22 Jul 2026 16:23:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784737393; cv=none; b=eKmOrBUv/tafw57HTv7MoM4ig0UB6mKrDiibokRr+w+DpXbXuFzDzac3zdk4zhqabEwZcJ2QbwWZUnHTZtr58Xuhnayf5X/7StFWPqZBQP0NxmZZ0O18UKcH5ajiTn0SRrJA83CmXkGnz3AtQBfsfGUEOAEAg5TgoPcwEA7di9U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784737393; c=relaxed/simple; bh=i8HPqvtfirXrkg9CRJQYHnwQufUh+A0XBBmT0sSXqHM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nizvMjJ6zFba88ZkYRmKK/0+gtOzcPLLhbrchEe1X+7s2SJch+xUDj0UDTbDOum4N/nODKpcJhGDRPNQU8oxFiJKxvG5hzkwEI4ITbELwoCxQWIHAvTYSxX87UkwkFjQUzVvPRQ/977uFYIfx9/rsge0+MvrIFV79+0Zzu1U2XA= 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=aVKoNCHg; arc=none smtp.client-ip=209.85.215.180 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="aVKoNCHg" Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-c9b373d5af0so9651230a12.2 for ; Wed, 22 Jul 2026 09:23:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784737391; x=1785342191; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=eVAyazMl5WkniAlf75NkROON8JhWPspf9inm470FnWQ=; b=aVKoNCHgSBtdvfPTGMJRrjtE86jXGz5j+q/SxLV53aCQ2XtuMyyqQL/OqLSFjK9FXV FQ3rY40NO8uKnjht9+r4AhHUw596geoOtdvtCuPeO7pN878WZ89uVTCwLbvDGa4lg4dk uru4pyfgEGCOsXQ9M/by1nxE0IcReTQBzT3ayz4Nx7ZTi7NBnJ/uBo6zy/3ToQCY/Qj2 VRu/RGCExPxyBIqv09hF8vnFYqnIhE0BqQSZk/sIone4k+I29uvYakPHO7YuKoOI1Wh6 mjKTmJklyU4psj5Q1pUejU5XxlU67Y8a6nNGcBX0BmrvBJQtUY8IYTkNQcqXFK/e6wZd wNtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784737391; x=1785342191; h=content-transfer-encoding:mime-version:references:in-reply-to :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=eVAyazMl5WkniAlf75NkROON8JhWPspf9inm470FnWQ=; b=Cu3rnIvZhL4ggqBsv97qjnT6aZYA6C+PYHeT95P4U1MuSq10mFPTmAaA9btUNgSflB Co/vcOr41ZPLVzICVXp9rkI/F+J+h0Yak7WQWdv471A47uEgWE4hgM1Aijb25CL0cl3H dTmZFKhQ0dxGJJMAzKzAT/7/Z2mlUXuQN5v84YIsZirQ+rSMU0JCk964YWg7X9EqwzRC m0ABTlI8b1HizgH2XWuZr5W84yZUskKecrlf4pxe5C/8O/7TxfhZxgM+h7dq1qQs4mUM LsiyUwTRXujBa9HJmSdowTv5Rz1pp2KaREjIG264y0vQ2VxiBOI4zkda0zmOhuMU0Goe D9oQ== X-Forwarded-Encrypted: i=1; AHgh+RrN8o28kk+2ji12DSwBNMsh1XPgpYj9pkkpD2Id0yM5w7wlfSW9AR6azxhniBvu7fEcMwLxz5zWBlktgpA=@vger.kernel.org X-Gm-Message-State: AOJu0YxpaVAoy4FZ5nTnzRdEZwKuiz2Da8og8XBSsbAtqSwvI/hs/sGF GiZUHQFacwQexq24lOlDM7spPhofnMbBMOpgZq+dVc/EghVHgeG8SfA= X-Gm-Gg: AR+sD10hng2efV7CVDkPxTSimf2iXgMbQBhIUxWOOkaPyE8l9Sih4A1azjj4YmORX8i PghElVh+j1TtiHN2Qbhabk0HKzXkNetmrrYHsfgFwcWjhB2kaqO0KcGkHrhEYKWQxGs3EuL2tLX EJ1FCIW+WQGe5knlsPPToR8hFp/gRsc3cj99C83+xrQuM9aZT7eeQ61hHiBQuJQQzT3EI4HLjyH kILFMggzmI8x23D4sYaJkC4Vm/Itt4Zr7gJ5V6CiI12SZAK86ts+hBUUx+SH6n/i2kc5WTtyXdW 0JXXfzI95TSKps5J460DBmeHT0KInt1wabnMyRN3k70qdx7W5IBE/sXFXb46cGZjgyvh+ANgGgl Rk2WNTiMotp+IOgfOlqLGv7CTTfOfTJs3StTCppMe4FR6tWQDyE7exGgh6BEPJtMYUsEzNI8zDD UqTKkle/Mp9q73erIh6LYvXIBvpiy4Qw5nLDBL3j2zuA== X-Received: by 2002:a05:6a20:cc0b:b0:3c3:ac5d:b6de with SMTP id adf61e73a8af0-3c3ad7da25cmr27209656637.22.1784737390679; Wed, 22 Jul 2026 09:23:10 -0700 (PDT) Received: from localhost.localdomain ([101.0.62.129]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3147dc1e3d9sm9260471eec.5.2026.07.22.09.23.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jul 2026 09:23:09 -0700 (PDT) From: Nikhil Gautam To: Jonathan Cameron Cc: Linus Walleij , David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , Andy Shevchenko , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Nikhil Gautam Subject: [PATCH v2 3/3] iio: light: gp2ap002: Fix regulator leaks in runtime resume error path Date: Wed, 22 Jul 2026 21:52:47 +0530 Message-Id: <20260722162247.8229-4-nikhilgtr@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260722162247.8229-1-nikhilgtr@gmail.com> References: <20260722162247.8229-1-nikhilgtr@gmail.com> 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" If enabling vio fails, vdd is left enabled; if re-initializing the sensor fails, both regulators are left enabled. unwind previously enabled regulators on failure, mirroring the error handling already used in probe. Fixes: 97d642e23037c ("iio: light: Add a driver for Sharp GP2AP002x00F") Signed-off-by: Nikhil Gautam --- drivers/iio/light/gp2ap002.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/iio/light/gp2ap002.c b/drivers/iio/light/gp2ap002.c index e8ba9c00dabb..430336b51f83 100644 --- a/drivers/iio/light/gp2ap002.c +++ b/drivers/iio/light/gp2ap002.c @@ -677,7 +677,7 @@ static int gp2ap002_runtime_resume(struct device *dev) ret =3D regulator_enable(gp2ap002->vio); if (ret) { dev_err(dev, "failed to enable VIO regulator in resume path\n"); - return ret; + goto out_disable_vdd; } =20 msleep(20); @@ -685,13 +685,19 @@ static int gp2ap002_runtime_resume(struct device *dev) ret =3D gp2ap002_init(gp2ap002); if (ret) { dev_err(dev, "re-initialization failed\n"); - return ret; + goto out_disable_vio; } =20 /* Re-activate the IRQ */ enable_irq(gp2ap002->irq); =20 return 0; + +out_disable_vio: + regulator_disable(gp2ap002->vio); +out_disable_vdd: + regulator_disable(gp2ap002->vdd); + return ret; } =20 static DEFINE_RUNTIME_DEV_PM_OPS(gp2ap002_dev_pm_ops, gp2ap002_runtime_sus= pend, --=20 2.39.5