From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (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 3FE032FD677 for ; Thu, 4 Dec 2025 14:41:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764859294; cv=none; b=T+TZH4zg8u69Y+PReMJQreUeAYblTgpfmn/DCVCANv81MJRw79Iszz+LIR2Md5i5jLvEYpS+1uLRyB02FHPQq0CQc+kKW5ELwSlUFSx19D9+1CFXWoKbKZZNUH9LfNddevd3/z3DweFxqPTXwuu8mPWJWwZAS9sCRWrspnUu5GE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764859294; c=relaxed/simple; bh=uAbMxMyvm57aMdOKZPBzu7Mfg9sM22DttjO/XotaqdI=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=OLsOhmGqOgCMkg5YBokuEAr7AwcAHhGTq2v0/0CwhszjmdR9UDewg4cs3ml0NCRCbAMgntHt94qSXwE+lRro1ZuRSgTmpTbFp2XKuj5mOHfcjuwI1IE0qhYWbKw6i8dbexpPTXm1sXwGc45e/VWgCGaeIPPPX5E/NZGuavoY2+4= 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=ifugpqNu; arc=none smtp.client-ip=209.85.128.46 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="ifugpqNu" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-477a219db05so7419905e9.2 for ; Thu, 04 Dec 2025 06:41:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764859290; x=1765464090; darn=vger.kernel.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=SYgaHNAH7r57kAaWKROJc+fUVWL2egFyf5e3gACu0+M=; b=ifugpqNuFKSCWISv2en0YOmvevrsf3hEInorKtqAnB++86b+K9PNbsq+TAFUnkgHfW Vn7ple4mKbGvXgZ3LzUPzOnTKLIkQ3IwOOZDfWzr3XMU0ZezIptEpNe+kg4jH8oyVbYg t0k5KUXVDPbIAeleAOIwCA/R/VCMmffd0inHruECqjsCywjwkJHhebqgkn6BxTdOicUJ vgcFl+i9EzCwxcg0qsGocGIDoo8olDQ/3Yt+cjwQJ1HaK046yzfOOCOUvIAjLNEHrqgK NpT7dkUKhKeQADu6yBob4eDsX1U65B3Bua7vZ9wSU8kFlnfNnKaWzPdZAJaFp0I/+SIN YaYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764859290; x=1765464090; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=SYgaHNAH7r57kAaWKROJc+fUVWL2egFyf5e3gACu0+M=; b=NJXkHNI3rA0H0xpcNI/6kaISSjwSUFJFkOGSw3oqAVi6TxYGKjKLaidkcf/SdgChJI bXMhtIHxymVddbbQ0mQQmR13vSgqJPpe0uYGfzZyj1U6fh7YOUdb/8gNhEjnN1JgQUWC SPMZdPG076zbbPUTqaA+poiu+1+v8qkGFGz4KCO14mFDTx6Go2W7syXuJIGVxz647KLD Q2PDqImGbWbyhRquqQfgEmfIXfmg6kNekIH5xuekOhphXqSrFuUCroQGDi3GBt908zRp DYyjBSZN8AMqWAI9xof4tJZ4FhEqxo2yrWDC13/S1Og4vMJCyhuBymFCDA1c7KfCelIF 815Q== X-Forwarded-Encrypted: i=1; AJvYcCV0V110DGdbQGhxzC1+EKqaz1K/dUnZMLK5h0L95Ers5jaMtVDZvpdHKGOXfBPNS9NGuB0lffXGWgeUcJE=@vger.kernel.org X-Gm-Message-State: AOJu0YyTBo3T+/chv68a3yydPEbgOZoM3V0ko3L0yjzbuixmup8IGnyK r4aSjaj7a/UG2zxdvD7Ac4Nb4MC8fZbp7yAF2C7IG+PCKbRV4YxG1Il2 X-Gm-Gg: ASbGncu7ok8z/J7Wsq8w3WgvWRQDWi0O0PKTu9s2nvMse0q1K+gG3PNhlSeKOyN1JBG LczO2tKe/oYpETpq0DwxmSPmlhiFcaS1BdoGNFhbCb+im+y2xmdXplpUiJT1gswbkazKk+Sgk/H ugPYQ+j2GwHi8NV9uIsXnpLB1eL9ryhJA6KPkA7yfa/dPXXqkl47n++bnnY1Sh2EwXqrfh8jZ+K iMraXc+VpEIEG5iSAVGCsYl8Z9YfDN9ayMMv+NO9SR6eYh+zDUk72G3zh59ZVfo03/dRkNtMO23 NpUvA0GvCskt5ahKMCtFUYHCHZ51oYwV3zMOrGVUtrPPJPOeP7SXD+WNRF+stClkYj60XeP4pv6 2b0c5soPBEs/1DoFhZtwIjCAuRUZljdyKUhVBQb/m8GZ6ranDGr5ValMKLIZozRkHC8Ot2wFq1v UlpcxrqhHAsNUtEm4UrLQ= X-Google-Smtp-Source: AGHT+IGwPzcCScstkaW1JYgs6ST+2pHxRJAu6rrwNjx2W/K3deKlfF0F62zXGHhuoPdhomhltshf9Q== X-Received: by 2002:a05:600c:4f54:b0:475:de14:db1e with SMTP id 5b1f17b1804b1-4792af34a2emr67754295e9.24.1764859290271; Thu, 04 Dec 2025 06:41:30 -0800 (PST) Received: from [192.168.1.187] ([161.230.67.253]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4792b14ad9dsm41299175e9.12.2025.12.04.06.41.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Dec 2025 06:41:30 -0800 (PST) Message-ID: <17ac2fa9033104c3bf9260fbecc1c9a5b42fcbba.camel@gmail.com> Subject: Re: [PATCH RFC 6/6] iio: light: opt4060: Use cleanup.h for IIO locks From: Nuno =?ISO-8859-1?Q?S=E1?= To: Kurt Borja , Andy Shevchenko , Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Benson Leung , Antoniu Miclaus , Gwendal Grignou , Shrikant Raskar , Per-Daniel Olsson Cc: David Lechner , Nuno =?ISO-8859-1?Q?S=E1?= , Andy Shevchenko , Guenter Roeck , Jonathan Cameron , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, chrome-platform@lists.linux.dev Date: Thu, 04 Dec 2025 14:42:10 +0000 In-Reply-To: <20251203-lock-impr-v1-6-b4a1fd639423@gmail.com> References: <20251203-lock-impr-v1-0-b4a1fd639423@gmail.com> <20251203-lock-impr-v1-6-b4a1fd639423@gmail.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.58.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On Wed, 2025-12-03 at 14:18 -0500, Kurt Borja wrote: > Simplify and drop "hacky" busy-waiting code in > opt4060_set_driver_state() by using guard(). >=20 > Signed-off-by: Kurt Borja > --- > =C2=A0drivers/iio/light/opt4060.c | 52 +++++++++++++++-------------------= ----------- > =C2=A01 file changed, 17 insertions(+), 35 deletions(-) >=20 > 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 @@ > =C2=A0#include > =C2=A0#include > =C2=A0#include > +#include > =C2=A0 > =C2=A0/* OPT4060 register set */ > =C2=A0#define OPT4060_RED_MSB 0x00 > @@ -302,41 +303,22 @@ static int opt4060_set_driver_state(struct iio_dev = *indio_dev, > =C2=A0 =C2=A0=C2=A0=C2=A0 bool continuous_irq) > =C2=A0{ > =C2=A0 struct opt4060_chip *chip =3D iio_priv(indio_dev); > - int ret =3D 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 =3D opt4060_set_state_common(chip, continuous_sampling, > - =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 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, > - =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 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)) > + return opt4060_set_state_common(chip, true, true); > + I think that if we are open coding lock(mlock) plus iio_buffer_enabled, the= n iio_device_claim kind of loses it's real meaning. To me guard(iio_device_claim)(indio_dev); it's basically iio_dev_lock - Nuno S=C3=A1 > + /* > + * 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_i= rq); > =C2=A0} > =C2=A0 > =C2=A0/*