From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-vs1-f41.google.com (mail-vs1-f41.google.com [209.85.217.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 D397C29A9E9 for ; Fri, 12 Dec 2025 02:45:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.217.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765507552; cv=none; b=XvL3DuAkEwcDvsyc9mFzibslKiSURTFiQ2djkFDMIc4eneaNtVtBisCtLtJMB/uUXYrbnD92liegSHI5RwJ1RvNXM5/SdAZ3AlOJ2ZR8kodUjjKJSFnn3Q3r4r4k/T+8bf+lDVeFAt+KI8IJHLnOxtl7KwCZj5MfrnXxH7nG/nc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765507552; c=relaxed/simple; bh=ROdGE9UYn9t3GKB795F+w4NovlxCcnGyj52uJR8yT5g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=YVU0hCY8aiJ6ZT2lrKTMFCUeN+kT+WCiaTKiOD/L+tS+jrMuB+Vt1Utl7K3YOYbPEu7c2kATgq7oQdMSVNDuGSmxVoIeL279puivUqp5VkT+5ne05CEx81IlwB0dTbyd46lB2dzk9nG/s0wwnbZVZFsudMBR5PxRZDu9K5WIsik= 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=KRohjAg9; arc=none smtp.client-ip=209.85.217.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="KRohjAg9" Received: by mail-vs1-f41.google.com with SMTP id ada2fe7eead31-5dfae681ff8so485041137.1 for ; Thu, 11 Dec 2025 18:45:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765507548; x=1766112348; 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=iYZRIuaNXC2L9F0wrej4K4cGwCXMfBa56Esw3K/nF6w=; b=KRohjAg9pi+ViCK3zzHXWnMXcvkwZP/iDMOdPEiQBEvZmIy9FLLlAQG095/jimVBkT WWTOvTNA/IdaovkqNwRV6FrFa/+AFQd6VXS3CvwTfHMkRjmiVF6Jal0jeHAcC5+8WWrt nPq/JXJVeNV+NL0k1defaXVdON9Q3yxoO9YiESfXbQtgizjRtEXJH0eqsUtBX/+cgEZc Ph/V0zrKykgUYCKcY4y1gLLogIwA2QHAVWkmFlhIsob3SNNV+UN6F9fAEdCPYh8LsLsx J99osHEdEd1wg+C7NWkBxARlYA6xh5Igw50Y3JIWRXrADJ4JIgmywtfTDce6HMefjgD1 X1bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765507548; x=1766112348; 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=iYZRIuaNXC2L9F0wrej4K4cGwCXMfBa56Esw3K/nF6w=; b=V7wT2Jgw+V3rmEQb2Y0hA47IyJv6jADtvo45yhW4CtWgo2Hrh0Lxiqx9NLdeWM2ebG Mee6pDfnpK08lUTHorRhup5EypqrPUo8gV8OZfIUyaaMCkBRbunJIe41CYDOTGYGrn0Y P7GUgpr4ZRFBIeCjU4D4azCdreES2FBKQ5cRfMQEiIuFiOItY+P51a3+hFSDUrlgiGox dF7Crs13+KdxFmzRoC20gugMYFB7TyTHTfHf8oy6hT5Cy0XcEbYGsu2BgvrXv3nlf8k5 9SihPr+pTLyD8wUx+kFyj3k74KHlQggyLk8jfgaFVL9tZFP1K38sCMwq31roHeHaKA6p 6ncA== X-Forwarded-Encrypted: i=1; AJvYcCXTF+3xzTVyFiYAgxRc8xRQwQFmu0fkBqaedel/YMsBYY6y7wAr3LLz0qm08CPro1KiCMS9QxRZ8rntxig=@vger.kernel.org X-Gm-Message-State: AOJu0YxyP08XJO/Q/QvWYaUWSZPjg+1/dGdSGIIQZWDZF2fynR2942bT f4Y/SzrwA7y3WYhD5Oysxy8PpsBpZq2l/zE0k9hIKvpz7nfQ1PR7F8uIgLm4vg== X-Gm-Gg: AY/fxX5vGOf6mflGzwb+d6lacZ2KD9bekV/e3Yr2lBpt/8Z4QWw+NYcq/WULDOANPHL CqtTjFNp7g2IkdJQsZSG7WJ1fbr4Kwe1BBUT5qW9RCMrqeZPFu9jHbpudEWpIMhJxTooJbvUZJK 0Ib73F0VeKGIDrAwgHGlzqNFmBdcb3Rtt6+d4bH3Kekp7yv/6v+8DijtNb88ZNWfVIb9YjG2pbi ElhKtNr0+JRog2wY7P/OY0jcIJXVfk66f5R4GHzar8c88m++oII31V7sV2C5OwYTJC8goaciChj IyZGLwf03URpFImzyyCjD1kPaeQeaNMkn3CPwKB9cnmlw2HWmalCXYeR3G0pmf9P1CiXfemm0H0 f86tu4tJjWrQXhVXaPgumhHzCnoODFGunfCc2PG1TRVUL25i4ZNZMxD0FPT3ZGx9zah5stLX5lw BsFqOIT64hdOD9zaLJj4Crl9Y= X-Google-Smtp-Source: AGHT+IH5i7dtBfVcr5pIDPh38IKpcxO7iBsFvqjyiDMjJP75f9PBiuTE5pSrUZG3ggjTiJvDMCDRxw== X-Received: by 2002:a05:6102:54a2:b0:5dd:c568:d30d with SMTP id ada2fe7eead31-5e82783585dmr129533137.30.1765507548500; Thu, 11 Dec 2025 18:45:48 -0800 (PST) Received: from [192.168.100.70] ([2800:bf0:82:3d2:875c:6c76:e06b:3095]) by smtp.gmail.com with ESMTPSA id ada2fe7eead31-5e7d0f25ce2sm1693762137.8.2025.12.11.18.45.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Dec 2025 18:45:48 -0800 (PST) From: Kurt Borja Date: Thu, 11 Dec 2025 21:45:25 -0500 Subject: [PATCH v2 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: 7bit Message-Id: <20251211-lock-impr-v2-7-6fb47bdaaf24@gmail.com> References: <20251211-lock-impr-v2-0-6fb47bdaaf24@gmail.com> In-Reply-To: <20251211-lock-impr-v2-0-6fb47bdaaf24@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=2580; i=kuurtb@gmail.com; h=from:subject:message-id; bh=ROdGE9UYn9t3GKB795F+w4NovlxCcnGyj52uJR8yT5g=; b=owGbwMvMwCUmluBs8WX+lTTG02pJDJnWjSeZoj/PfmBy4cD3SRt/BpS75GZkG51a/1Wv7M4Rx w1behXWdJSyMIhxMciKKbK0Jyz69igq763fgdD7MHNYmUCGMHBxCsBEXrYyMrSsPeb+OkilQE3R dts/rp81J080b85Kv6J0cPaRT25H7jYxMiysck6yNzwq+1b2Vs9Snvy5DCqSH+etDbdJ+12cmu8 wiwMA X-Developer-Key: i=kuurtb@gmail.com; a=openpgp; fpr=54D3BE170AEF777983C3C63B57E3B6585920A69A Use IIO_DEV_GUARD_ANY_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 8cb3fa38077e..943e5963d568 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 *indio_dev, bool continuous_irq) { struct opt4060_chip *chip = iio_priv(indio_dev); - int ret = 0; -any_mode_retry: - if (!iio_device_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 = 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 = opt4060_set_state_common(chip, true, true); - else - ret = opt4060_set_state_common(chip, continuous_sampling, - continuous_irq); - iio_device_release_buffer_mode(indio_dev); - } - return ret; + + IIO_DEV_GUARD_ANY_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); } /* -- 2.52.0