From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ot1-f52.google.com (mail-ot1-f52.google.com [209.85.210.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 DCEFE2E091C for ; Wed, 3 Dec 2025 22:41:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764801663; cv=none; b=HhKO5ALZTFeC50CvY1+BxFnMYrf7BCWJiMrh3XSLpVW/puN8U6RhHC0PECxCCoORvqUEstipuFh2AljlExfxwmdd6AQ+rRJ0IkawTwEc6pEPlva67yPJcMmJxssw155H8DJVtM+Wmz56s36ZEmUL1si6Lg+N5uBukVUSeZJ/49A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764801663; c=relaxed/simple; bh=SUQIyZJZp+O7Vp//jfjuuVMp8y8KVbrJbuI0BpFAPZ0=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=kJVkmFADsPFw2tJt8PDRYhajPAmNhZWPvVOYS4KGLsQlbo/YJ7/lZ14YV0w3vcnX8CYNSclfiTP3aR5abav0YQa5UqwToyuUV7iHC7mH6Sv4YNolDRmtcZBetwHqW4lHGV6KBFM8G/79n/ss8T2PHoR0HCAI+SzzHrLXMAF7FgY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=Drttv1iu; arc=none smtp.client-ip=209.85.210.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="Drttv1iu" Received: by mail-ot1-f52.google.com with SMTP id 46e09a7af769-7c52fa75cd3so243106a34.3 for ; Wed, 03 Dec 2025 14:41:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1764801661; x=1765406461; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=fae2T8A00LxuEcnVsoAj9zMjZYXT6dEfKw1jD+A44wY=; b=Drttv1iuhKnZu/tN9TQgwTuAdcfBuye8YxZ1AZqAUUvUg8fFYnXL3QNHnHPoD9Oqks +F8RSNP83iSxP41JCH5g3nlLp0KOSfLxl+7LG4bvRxc9Zy6+jOvouIDHVmGyxYAwEbbD Hu+JjRFPqS4/YgtPZ3mzps5+5xAN4W9dyqkeMoPcVCWqGzQX/W9+N/G+DBAkwrIg8bxY kLTPo9u7MJUPd+QKZt2rFv5YGDxs+e3Ssw5N1+CmN4Tof1SDYUPuP/hO/liWE1iivHKd e4zJWkPbGwj57fOLlCrV7NW+GQItOKD+4JnDYF6G9GRu6LVc6FsQxyIKRgHbphWa97Sh NfjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764801661; x=1765406461; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=fae2T8A00LxuEcnVsoAj9zMjZYXT6dEfKw1jD+A44wY=; b=kOId7vsCFyC31dCCBu+00RVe8Tk7JnPzF8bKbScE7WH2WuJ+1diHHJwnzm0OKctzG7 xA4NdV9t1KCKN9qakg28WATsXeOB1nsyE2SR0likxkW88sYwR2/2CdL++I54q0IWaxGl I3or+6uZ8lZS5XWuR32hSkY44wpVskZBhSWOXuHtaqGuguz6iMPeEG9y/wb8DYtmAZRh hoiWRXYEyJsIS6oRbSeOjS5H89PJhlsZDoY2lCBavIvwIIA1nhD4x8pILiwl/eGtEwvr 2yB81XqxQ6DmsNlK7RyXX7NbYg4XfSeCETY4pQvWpQ57QJ4HrijFInuN+axi24E4uLMp lPXg== X-Forwarded-Encrypted: i=1; AJvYcCX5zBpRLItpjUBGfq6Du7Fa9/35mAB6WfxzSWa5aE3nLKBJr92wDXuFuAngchZ5BhNdcS3qgmUWWGK3qPc=@vger.kernel.org X-Gm-Message-State: AOJu0YwVUV30vEelkzRYOr5/4Yll4dSjlxWFXjFAZRV8Dj3LryMqWbcx kg0DM2ynSlUQvwW5gtImV9MY5hcMl571Ah7FHygiO6N9hPg3udU17jXU7Y6rp7t6yJc= X-Gm-Gg: ASbGncujBnn6dOTX7UkD08dL2qCTnxrzfdSbILlrGe4wOd2SowRPj95HaIHnbr8G9KY NHnlSXuHoF7NAhGlFQUV5Oo+K39dW22A8beRc5zUs7U+PSqSxHoClG/NSH+VS8ZhvBtZjjefbnd hDXm860qaktUQFFBcpPcQUjqDJG/o3/irOEUyLbSEVl1YwielU87mTySKOj5B+r5OXCTkuWfgnu eKx2upp7BC0YDCWasCSOrwrAtsKjB9szcfucXFvwBAoi1k9hyK9Sh54U3P8cunCQVemRnHYE3wh 6E048peykjYhiPXL2FQUsdRSjyqUkvFPemSVOsAcH5647xNPsktO7qv8lNcWxYCKBHk9/Q8TgMz Hc/nCLSBs15UgoeOaMFAmTMstGdsncQXX7irTJgo5xbKxXlI7N4pqBdBKFjmRaRnv7AJprrhGuG QJ/ei1C406YV/59xon8w== X-Google-Smtp-Source: AGHT+IE8ahaPipDh8W8AoMJnvq7L+yJGEo+dv7+OKVdTyAgpgP0LgOtF5++RGJ1xwcQ5dHaHz4vquw== X-Received: by 2002:a05:6830:410e:b0:7c7:568d:cba with SMTP id 46e09a7af769-7c94d8c65cfmr2925018a34.0.1764801660974; Wed, 03 Dec 2025 14:41:00 -0800 (PST) Received: from ?IPV6:2600:8803:e7e4:500:25f4:78dc:7b9e:e7a4? ([2600:8803:e7e4:500:25f4:78dc:7b9e:e7a4]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7c95acdb599sm1821a34.28.2025.12.03.14.40.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 03 Dec 2025 14:41:00 -0800 (PST) Message-ID: Date: Wed, 3 Dec 2025 16:40:58 -0600 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH RFC 6/6] iio: light: opt4060: Use cleanup.h for IIO locks To: Kurt Borja , Andy Shevchenko , Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Benson Leung , Antoniu Miclaus , Gwendal Grignou , Shrikant Raskar , Per-Daniel Olsson Cc: =?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 References: <20251203-lock-impr-v1-0-b4a1fd639423@gmail.com> <20251203-lock-impr-v1-6-b4a1fd639423@gmail.com> Content-Language: en-US From: David Lechner In-Reply-To: <20251203-lock-impr-v1-6-b4a1fd639423@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 12/3/25 1:18 PM, Kurt Borja wrote: > Simplify and drop "hacky" busy-waiting code in > opt4060_set_driver_state() by using guard(). > > 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 500899d7bd62..903963606143 100644 > --- a/drivers/iio/light/opt4060.c > +++ b/drivers/iio/light/opt4060.c > @@ -22,6 +22,7 @@ > #include > #include > #include > +#include > > /* OPT4060 register set */ > #define OPT4060_RED_MSB 0x00 > @@ -302,41 +303,22 @@ 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(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(indio_dev); > - } > - return ret; > + > + guard(iio_device_claim)(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_using_own(indio_dev)) The commit message does not explain why this was changed from iio_trigger_validate_own_device() to iio_trigger_using_own(). I'm guessing that is why we also dropped the `!`? > + 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); > } > > /* >