From nobody Mon Feb 9 13:01:26 2026 Received: from mail-ua1-f52.google.com (mail-ua1-f52.google.com [209.85.222.52]) (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 9BCA431ED68 for ; Tue, 6 Jan 2026 08:07:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767686849; cv=none; b=uz1SHxzMg+/5awvH2RmjhaPoE+Dg3h79ih3iBn+fTspvaJgZ85pWtBB7Y+VipMlsoXWA0C0w1MzL7yP8O0/wUMzTv0SALCBaErbNdxN/VHqhj6f0pNb2bfNX6yll4JhM3oWbJCny2/8XZUGvYm5+h5B6vXf1qIxjqGt1FNFQCOM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767686849; c=relaxed/simple; bh=wLQkfH84L3nWLNYNBgcXpFCEELbehsGmWWxLa2vh72M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AE5U68Y9zv+IiNxDL3R56APVZWxMQkczjFZfbNvOlBHNzuFeI0+mrmZtygdYWvX3+qCNGmm/OQkk6wxIrHQlNb582NstRxqHJjOiplU6dcZpi0/kaIjBlIxoMGOvtMXWFzlTHyt1rbQvSBj8hnbqzW/lTc48E/JLAP6aOfdh4Ok= 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=H1BgVE3m; arc=none smtp.client-ip=209.85.222.52 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="H1BgVE3m" Received: by mail-ua1-f52.google.com with SMTP id a1e0cc1a2514c-93f4f04d9f6so1359508241.0 for ; Tue, 06 Jan 2026 00:07:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767686846; x=1768291646; 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=IydZnnaEgCiF4tRpM0JqQAl0iXFoV2F5d6i1TSIygpQ=; b=H1BgVE3m5tnJ7/5O8mlB3fHP9NgtX1JuzKUrYjBFoXeA+8uw3PfDu5Ac9qEDyjjok7 mrKvBresRsxRwwczmJuKRsPf3QzsYeADHPjh/kflUWSbeY/D4VB4M7t/woy3047Wwy+2 SjkQfrowiNi3F23o4zsIwVFhKFUYlZ86Xpd4ws9KXplrVMMf92I8z3ujEbESTbHQ1w6f OmT9yTtuUIU+uwfWRTF0P1r9GFoiI/n/AQz+yQ4XKiGn6uo/UYQsjhLMTeS9NE/YJ+bE hgDtxTlr6roxiUPvvS6V6NGTDCdzN2KiqwdkpRXVsUvtakdXwQJIh2mxW2lIhFbhfOj+ dFIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767686846; x=1768291646; 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=IydZnnaEgCiF4tRpM0JqQAl0iXFoV2F5d6i1TSIygpQ=; b=udaTXO8RQ/Uw3bqCqRcCj4WqFlBSuUWxZhaDayr0XfsY2mcx6Dhs7CjTfocbMP6v80 pyE5wbxF/WTQUelYWqODWLPnWQvSHOugiR88J4qQK+NH26f2dEV+HiHK5cu40YR2AD6k sI95iICXxusZOPO+GPTX+7mK7qNJuLzJ8DvKsyLOGxbp3Qc+z/ucxngGl3+MghjlJM3T q42vVfd/HHqzjYpSE95svmvov+KM5ryDgvFUkfA3W0XaXWjU3dMfJxQoL3Bv6iHqOfIi /1u181MQAqY10W83NfPq9cdckFnwvdfcCEE5Pe/vu4PViR0UNVaK4f2KWG2r1NPqVlO/ /T1w== X-Forwarded-Encrypted: i=1; AJvYcCVOABQCeDFQrp/sGGCY6hdnZ5If5RKaiQX6A+pBD19cC4s1A4ZSNdoyx7FIAh2bkFTrkiNo47eCh3n6Srg=@vger.kernel.org X-Gm-Message-State: AOJu0YwAEvrLW3asgaW6cCNz1c5yVxeJIXXBXJQYLulB0g/Bq8JzhJW/ HGMlwj/vUxMG6GK+YGTpDwKwLl3t0fb1SVHyuSBDQnhBAA8KZiceFP1X X-Gm-Gg: AY/fxX7HZtSh+KO0uoXuGtLIyG9NNbIk7OMSXtkesOM0UO9vCqesoti3JFrkKxKu6fv 3iY/WiZswOZivVyQSRdeEzhuuW/4+mJXxCjeLJR3OBJish+xKJrF9R2Pj78ix5CzVXX05M27VY+ FcTvrSDqlFbZpW6pgFKW+PBgcNRvxPBpTjYZUTQuxVD6b/wD88P4CqSHnbEHlTRf62uYt8VocG1 DtaarLS3LzJdo53x6npV9yq2vdFscMBP5V6huukKbYYtiRmvT13JfmkkXDnndJbTdY+q4yZuWFm uNM/jjo+WJ0sRwsLoazR1fy1mnTZ3TIRmi65zFMyXPaeDOjvW9YxpXfMDTOihxydeJyoodh+9Kr tCKPyhX+JwWi5tddJ3REGkGw7STMnXKjUvjF2JlPz73BMg00k8oC2yBy8LdcvUdKIaNsfVRMEQJ /TgznGgHd317d2 X-Google-Smtp-Source: AGHT+IGMzI/cOqZ43QXZ7a5RlfUrH5CNRBYOY+ps8BI9qD34V+0PqH3koe/uQqhNWbT7bakQngPE0Q== X-Received: by 2002:a05:6102:41a5:b0:5d5:f6ae:3903 with SMTP id ada2fe7eead31-5ec75772675mr663970137.20.1767686846422; Tue, 06 Jan 2026 00:07:26 -0800 (PST) Received: from [192.168.100.253] ([2800:bf0:82:11a2:7ac4:1f2:947b:2b6]) by smtp.gmail.com with ESMTPSA id a1e0cc1a2514c-944124a3386sm457615241.11.2026.01.06.00.07.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jan 2026 00:07:25 -0800 (PST) From: Kurt Borja Date: Tue, 06 Jan 2026 03:07:02 -0500 Subject: [PATCH v3 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: <20260106-lock-impr-v3-7-1db909b192c0@gmail.com> References: <20260106-lock-impr-v3-0-1db909b192c0@gmail.com> In-Reply-To: <20260106-lock-impr-v3-0-1db909b192c0@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=2592; i=kuurtb@gmail.com; h=from:subject:message-id; bh=wLQkfH84L3nWLNYNBgcXpFCEELbehsGmWWxLa2vh72M=; b=owGbwMvMwCUmluBs8WX+lTTG02pJDJkxh1ZZLly6fU/3oVnceUXdgQrl5s9XfjBatl7l8LvJE 8SeHfH52lHKwiDGxSArpsjSnrDo26OovLd+B0Lvw8xhZQIZwsDFKQATcZNm+F/+RFrepeK68zpN lvAJXpZuJr9u9bomyiUc76pf6te5goWR4f+5Ssv1Z9lFLX76L/g4K0Fs7Vcfv7/lFtturOAN3Ht 2Ew8A 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(). 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