From nobody Sun Feb 8 11:25:59 2026 Received: from mail-ua1-f41.google.com (mail-ua1-f41.google.com [209.85.222.41]) (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 566AC1D798E for ; Sun, 18 Jan 2026 15:45:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768751116; cv=none; b=D3WpDQoVIuMwPDz2sORKrZa+3dsiIo7aiDYmHDcl1xTVjoqoUlqDPOrDLmVpsp309xtPqU8UjIqnRF0BZgaXVcWL44AWRmCa4Thp60fID3yjweGw7XYwQlo2DnNFsjhOWuqSqtNJMy18Vp/8cjQ/UHFNWYXk0fMKFY5z24VHBqQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768751116; c=relaxed/simple; bh=K/GzZXmVDH5d3ajOh9Vses0jzRTbszvo9JEIlad+htc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XgURx1j9BgmCq6rufmkKegu5WCbn3CB76XdwSCW1uc2LFCkkOKqIKD7xdetuTZM8LWeUJMu8JX51yiU1QSyqEqhXe4tq5haZJ5Fl+VXkohET65L/3xfjEBq8F92QYs/Cs073qmXWZnqsM4rC6skgdWAhC1wC3PSaKAgXnYgN2xU= 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=eONvwQ+1; arc=none smtp.client-ip=209.85.222.41 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="eONvwQ+1" Received: by mail-ua1-f41.google.com with SMTP id a1e0cc1a2514c-94240659ceaso991451241.3 for ; Sun, 18 Jan 2026 07:45:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768751108; x=1769355908; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=SUuEqo1bBPTtYvx/6MqHHwRERlW4p1/ugxXmq/ssirA=; b=eONvwQ+1y3RaaoDq2SjOK+W8t4cWq5V727BqcxUo3q0zexkDCy+ePe0EJiBokHg48x 50PbRgXmGDls/cUqflqS7GPNGQJpk2UuW/aKfwwoB2NWc2A5OVysb4fqcRuYCz4GVyjU W1puEEVZ6XXzN8CtF3wzVz7jAV67G4gm1/5j4pkWFNE0rn66LaH3R6z86ydo4mfmVqQl wKmmLGZUuSu6ylKYcf7mtCRf6z+Ldbo8RACZgxp1QPF2zPFGN8IjG7kpVKqydtVsFEDv HGZ2noJCw6ZwlAlo8YZSZx9h98W0Wcpj+NDeVdQ1eL1r2QkKmldmlu0VIoyCPvtyYU4S 5sOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768751108; x=1769355908; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=SUuEqo1bBPTtYvx/6MqHHwRERlW4p1/ugxXmq/ssirA=; b=mg9aWFnEpg0jg+f5XH15IxuejeGB8uxAY2EZwpXETm/7aU7oAF8l/PTSMR/JhqR1cV 9lWQCm5+J5WFN7IZcz2eMLMWspxK1RcEhLj9twxHqax7eXenGUt5ASi14Roah5tc4/JX cNKmtfJQ+ZV/TDkhSvIqFA78Bc2Lh2944+0TLOBHB6jec9YAyJdpPkD/ruzi1FI23yg5 YTG8EcvGTTJVOhNOEsa1K7T9/EM9ir4mCEFm5oYKwo3FoN5hLwCl8unzxtNHnnK801b2 qmXyvUBu4DHBOJJDV3R+eMp2LuPZdUzAX0OqHLtWYmhnkL8/oHbrAEaaT3c1S/FikgAN BTNQ== X-Forwarded-Encrypted: i=1; AJvYcCXQJV29pWkR/JvII9k9JU3IP3f7FbY9NsUIpa/RWbWRnJFj9LzkiNz+bfY4pEOYWxiTM1lZGvkGdhucNJQ=@vger.kernel.org X-Gm-Message-State: AOJu0YzxNLDubHBzuVHqHh3Mo8pZrgfAsTEfLxhFRF6K6/zm7G4+1fHG GN6dl8s77Wi/7cvQ9nXm5777Q72Xk86o0RCGVQY3xIdhGQJ3SVKX11Le X-Gm-Gg: AY/fxX5v4ayBQ/sfyPQ05Zvxjoth4jx/UWuRJXyziZsmkC7NeUaWNYagpgnIHdBGeV1 uVQkJtwIXB+Hd4CXh915OvN+g6XmJl2MaEIAG/5kBZ33Qk8WMolCk5c/tySnYHbJXdAeSMWO+q4 7QrcdFCH0tGPZDG+bHoDBBTrWC9GWTCPInHXoNQcyhiH3go8HKMdTN5nO+Or2jL8u7fbP8DyjS7 SoCfPG014CtGY0FF7adPx8uk8SGW0kuG+DT2Vo84woC3l/gXk9SEmHrwnmwHLvIpOvS+oQBe18q YQcHxOfX4PXWO8Rn8oZXg7TB7NWklY175y3+XNN//YbZe1VtaMsXu46vHxGPFvHZ5sL1VfVOERj 7rYemF6RxFq4lChdlM1Eq1Xz6vZ8FZW8q2o5+nKpBgOf+oNxFFcHM5XNiN/42Gk07pQM6J1mRmE CoEJkAmFExAcAc X-Received: by 2002:a05:6102:38c9:b0:5db:d60a:6b24 with SMTP id ada2fe7eead31-5f1a5527da2mr2484137137.22.1768751107999; Sun, 18 Jan 2026 07:45:07 -0800 (PST) Received: from [192.168.100.253] ([2800:bf0:82:11a2:7ac4:1f2:947b:2b6]) by smtp.gmail.com with ESMTPSA id ada2fe7eead31-5f1a6d3ca2esm2832731137.10.2026.01.18.07.45.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Jan 2026 07:45:07 -0800 (PST) From: Kurt Borja Date: Sun, 18 Jan 2026 10:44:34 -0500 Subject: [PATCH v4 7/7] iio: light: opt4060: Use IIO cleanup helpers Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260118-lock-impr-v4-7-6c8d0aee8ed2@gmail.com> References: <20260118-lock-impr-v4-0-6c8d0aee8ed2@gmail.com> In-Reply-To: <20260118-lock-impr-v4-0-6c8d0aee8ed2@gmail.com> To: Andy Shevchenko , Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Benson Leung , Antoniu Miclaus , Gwendal Grignou , Shrikant Raskar , Per-Daniel Olsson Cc: David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko , Guenter Roeck , Jonathan Cameron , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, chrome-platform@lists.linux.dev, Kurt Borja X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=2688; i=kuurtb@gmail.com; h=from:subject:message-id; bh=K/GzZXmVDH5d3ajOh9Vses0jzRTbszvo9JEIlad+htc=; b=owGbwMvMwCUmluBs8WX+lTTG02pJDJk5/z9efWr+Xjwq72RES8m2CyrWnD3Hl+pwmrgYfxLYr ZO1amNlRykLgxgXg6yYIkt7wqJvj6Ly3vodCL0PM4eVCWQIAxenAExEQ4WR4V1Q1p3SkOX1NZxR 6XZG2W/4HgQtZT74dGqV7PYjx4+9SWP4w8lyUSt/QbZJTPfrdVk19xOLD16O6vD6OcNm6lEdPt0 HjAA= X-Developer-Key: i=kuurtb@gmail.com; a=openpgp; fpr=54D3BE170AEF777983C3C63B57E3B6585920A69A Use IIO_DEV_GUARD_CURRENT_MODE() cleanup helper to simplify and drop busy-waiting code in opt4060_set_driver_state(). Reviewed-by: David Lechner Reviewed-by: Nuno S=C3=A1 Signed-off-by: Kurt Borja --- drivers/iio/light/opt4060.c | 52 +++++++++++++++--------------------------= ---- 1 file changed, 17 insertions(+), 35 deletions(-) diff --git a/drivers/iio/light/opt4060.c b/drivers/iio/light/opt4060.c index 8c4a1f562a83..d6e915ab355d 100644 --- a/drivers/iio/light/opt4060.c +++ b/drivers/iio/light/opt4060.c @@ -302,41 +302,23 @@ static int opt4060_set_driver_state(struct iio_dev *i= ndio_dev, bool continuous_irq) { struct opt4060_chip *chip =3D iio_priv(indio_dev); - int ret =3D 0; -any_mode_retry: - if (!iio_device_try_claim_buffer_mode(indio_dev)) { - /* - * This one is a *bit* hacky. If we cannot claim buffer mode, - * then try direct mode so that we make sure things cannot - * concurrently change. And we just keep trying until we get one - * of the modes... - */ - if (!iio_device_claim_direct(indio_dev)) - goto any_mode_retry; - /* - * This path means that we managed to claim direct mode. In - * this case the buffer isn't enabled and it's okay to leave - * continuous mode for sampling and/or irq. - */ - ret =3D opt4060_set_state_common(chip, continuous_sampling, - continuous_irq); - iio_device_release_direct(indio_dev); - return ret; - } else { - /* - * This path means that we managed to claim buffer mode. In - * this case the buffer is enabled and irq and sampling must go - * to or remain continuous, but only if the trigger is from this - * device. - */ - if (!iio_trigger_validate_own_device(indio_dev->trig, indio_dev)) - ret =3D opt4060_set_state_common(chip, true, true); - else - ret =3D opt4060_set_state_common(chip, continuous_sampling, - continuous_irq); - iio_device_release_buffer_mode(indio_dev); - } - return ret; + + IIO_DEV_GUARD_CURRENT_MODE(indio_dev); + + /* + * If we manage to claim buffer mode and we are using our own trigger, + * IRQ and sampling must go to or remain continuous. + */ + if (iio_buffer_enabled(indio_dev) && + iio_trigger_validate_own_device(indio_dev->trig, indio_dev)) + return opt4060_set_state_common(chip, true, true); + + /* + * This path means that we managed to claim direct mode. In this case + * the buffer isn't enabled and it's okay to leave continuous mode for + * sampling and/or irq. + */ + return opt4060_set_state_common(chip, continuous_sampling, continuous_irq= ); } =20 /* --=20 2.52.0