From nobody Sun Feb 8 14:51:59 2026 Received: from mail-vs1-f43.google.com (mail-vs1-f43.google.com [209.85.217.43]) (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 3374037E2EC for ; Tue, 20 Jan 2026 06:21:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.217.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768890089; cv=none; b=iymd2tnyqMlB/YJ+UUHTgTZ++EMasQUXRJIfpfnkddGJZNMWNh4QXJeoqregByH1FiOKzz5uffQHPcUFwxONEpQUr4+xBcH/Uq1e5ocvOVf5cF+72zGB6P8tvZIjuPRTcmkY/bV0ZFtrNzLDTEHaLMa6GswZylReALnEq6usJ30= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768890089; c=relaxed/simple; bh=K/GzZXmVDH5d3ajOh9Vses0jzRTbszvo9JEIlad+htc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=X4pOEIylUz4e5BG7fG92VLDorjR2OQJXLPTLpmHD3CJrxXDegF1Qih9WSFw/t6dymgB+PFfufZOeq71QK2CieCpOJmslGM/skGGh3XHilCcxUxydFDuYTsVXMy5T7ZJwvPDGjnbZsR5qhMOVDF5HKNE6luoXYJONSLMc7h1hypY= 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=FYYuH+kx; arc=none smtp.client-ip=209.85.217.43 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="FYYuH+kx" Received: by mail-vs1-f43.google.com with SMTP id ada2fe7eead31-5eeff7e8bb3so3400744137.1 for ; Mon, 19 Jan 2026 22:21:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768890087; x=1769494887; 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=FYYuH+kxM1EGSoCC3HVZbHB6CGQjjBoqCO9fH5NY+5uq5ECQ5hV0w6Nuz3KBeAfTBW Q43b296pQ+H/76mHpGFhtd6voE+ahyBaqxRAJXTGENvElue+9ujKy7eUOaSxbCTo5/E9 f6NYk5HmnipR8KH2yl5jQD+cim6VTai204uKAs6IeoVebeeAEqKliL+60+/IwfvH8+hl qlLWQsU0QF2zxu62z2suYxrbHmsiuVfV5XYoyR/vPAGhAetCo3Cop7wleGlvVimO4nWs ElozcjgoWvAB8A/NNYuLQ/UABdULgnYFm6qNWySiyW+gJG0EZn4izvYcnRfL1r/B0NdC RN2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768890087; x=1769494887; 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=fAzQwbssgr09/dxjflWvXM0MzdtTXLbD7y1zvCfZIUEeGNlnLOfVwVU3I/YWhbyguZ S//TNpNw2e9bcuXRnkqelR8snAVU3EKJ5zw2WV7Rj6TkQd0bbK0MLeC8/k0dlkkWd3Mr QotH2dji5DeFy2/9HZsi35iNHwqG3g2H8tHPeYNVG/aZAd1zLsACWmNpQdzM/T86VP7M 4WACXAHAzSmhetGE/qjKQxt3gQQOV+EkoUNbMPznK8myOw0r2ovWW9g6YI6dCysVIplB P64i6AlpqFofj+klKf1XiYaH2Docf8hP7ty0F8RNboxnyAQhq3FP/wOYfzFuvmgjnUoR x1Aw== X-Forwarded-Encrypted: i=1; AJvYcCXbRg0hnvM3DnJYqcA0E9WTv+LhGO7bI2F+gagd6mgs/5A7xg5Rd3gu0iHGxUQA8PP/XJvbqJVmn0H9SPU=@vger.kernel.org X-Gm-Message-State: AOJu0YzJcMak2jwFB5KXfJTHXlbpnIRu9/yCrL+9IuAB/K6whfH4h8bo BLM2WY7Ei2KnCZ3JkwFQoGSX+AGh+YpmdFtVFnATx5YkTWAWsVmV/uXV X-Gm-Gg: AZuq6aIMUbeObgjCZndvf3lXfqveWMM7M6J1bCvKi/yrCOPvJ0GRiwOHhy2JGl4wVjF 8Ld1jroYKxT3FuCU9V1Zeu52RijCl7356UorpemsiCHcwqq06YFcBrTJctn7XF3H0Sx+qrSWqdD SOSolIlnu9FT5jgA4yCmzh4td0gBBcbOdjqfT/IT+abbpTV88Kq//uTgl0qnfpFXyp3yiu97H10 91T3Yl7NMdcF4V7JPhN82XHriPuN2CzFw1Gebb4PdOWsL/5Nybjfvwy5LVYo9zAcPmjD0LxbUuT ktMLZE+ImkCHwB9dmp5bit3L+Nzs1rnrOxGoOq8oSro5M3Ij7bvgK+5mbt9jesb+96fLdH2hlp7 DkjNaCQ/NqJaTL9Y8Sq1GyUMVO2odqtjsRtHXY68NzqcikU54PuDepZLV7PiYQmI1MQfeJ7/Kem Jr1Oh5g0VGfTf1 X-Received: by 2002:a05:6102:3584:b0:5ef:aeff:82fc with SMTP id ada2fe7eead31-5f50aa1028emr250763137.37.1768890087050; Mon, 19 Jan 2026 22:21:27 -0800 (PST) Received: from [192.168.100.253] ([2800:bf0:82:11a2:7ac4:1f2:947b:2b6]) by smtp.gmail.com with ESMTPSA id ada2fe7eead31-5f1a6900c1esm4057944137.3.2026.01.19.22.21.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jan 2026 22:21:26 -0800 (PST) From: Kurt Borja Date: Tue, 20 Jan 2026 01:20:47 -0500 Subject: [PATCH v5 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: <20260120-lock-impr-v5-7-d4d22347041f@gmail.com> References: <20260120-lock-impr-v5-0-d4d22347041f@gmail.com> In-Reply-To: <20260120-lock-impr-v5-0-d4d22347041f@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=kA0DAAoWFmBDOPSf1GYByyZiAGlvHtSjrwC1JnQanLoLExLJTwrpwdoltjp5KmS8n1f6i+dHS Yh1BAAWCgAdFiEEh2Ci9uJabu1OwFXfFmBDOPSf1GYFAmlvHtQACgkQFmBDOPSf1Gb/KAD7BdoF qUPP0diCbpCK9p45EPoIqdtrwlBjt1YOYDEaEvAA/2iqEPiM5dVqGN7bLWinI7Y1nD5Qgy9ZPUt 10sazV1EN 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