From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (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 147D6298CAB for ; Thu, 4 Jun 2026 09:23:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780565030; cv=none; b=Twa7ALhfVFLBuxBBWHmchBzxq156cBkDrg2JBXLSz6aK8ZENSKsBYp5UysKkZ59lU8vwHqJGCK+a9Jn7v+hD7qKyDmqUs8tfbjad1xC7MpPdnDqzrNGjZQSmt2uq27xrH5S2YG+OohxL9boHTJkX0ZTgWCuGAYh2jytvO3VDTi8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780565030; c=relaxed/simple; bh=T6PJIcN0CqXy1IMyNX5j7l7VoaRlD1edtziIdcR7Ezw=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=XhsFMJ71Qw+wAHTGF8M5FSPciWDdAPXji8ZbbEKrEyPaKLFsCgDbP5IXNRpj+mVLxSYxbAeFCAycJ82DGBS2DkHBq+n3tyBKwlA3TN0orOY24HHrF7pptV91woyBBejtWOkxGslczZjmWzYqgN+uRYTWiAIEf8svJeaKXG8NCfI= 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=C1fbb2dv; arc=none smtp.client-ip=209.85.221.54 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="C1fbb2dv" Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-45fd461e4a5so380231f8f.0 for ; Thu, 04 Jun 2026 02:23:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780565027; x=1781169827; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id:from:to :cc:subject:date:message-id:reply-to; bh=E1VE4yRo1ptgnYBqpUBjxBfNspfbEp7xrbxqWVzPNzw=; b=C1fbb2dvHxijK0jOpH4PMUoBFfGybQauCkcJL6AVFTIMRKF+Ny2SzisWeZLIl/0Vwf EXNmTCOhseM4BZrXupUNvGFumlAVqobzdRVUkd53Tz7JtjzWAGtPNAX94woh3RNZscf5 20sgQYCqsiug7fe6dAD6v/p79EyT4r8ypMTzLgkjfp04e9AxNb3+VuyMEwJaqeO+wtaL zjb1YXBinFnSRxSjEY+hVYjaGi3s1m0eHuq4dEo0KwTp/NWi0Xyjc7Zo7w3aRJmgwOj/ pKiS3rbz1Xr0AEBM0U5kbKg2NUze/Rn1iX2my6kaJZ2VMGZf6KVfgyiBTO7Cf12hxTG9 MUiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780565027; x=1781169827; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from: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=E1VE4yRo1ptgnYBqpUBjxBfNspfbEp7xrbxqWVzPNzw=; b=oOSvVlwfSzwKfrbDJCSAQqcA4oBQIwpzUGLPdercQUPtcQ4Rr85tsDOpiYfKR6DLp0 T40TuJWZyhqsL7UlAQfeCREC83U4ssYqYGvdMwM9FvaeCsnM2yE5Qs9TDWo1LulRrZWL EXmUsPMCG3iNwfoJVEq91QMpIuDWnmweCSFTpMc1cRNDrWpCVqj81zofWDxlIMNMuDBh T9g1eh0OjBG4rDi9SmI10uczj8/yiUf75TDFjovhbNzFFeJlG1XallSOo9anoQ4dJYPf P6g1CnpPa92LwID56VtkYhhPUiY+8jJ1jr06ffGEBrUrBAOQfpoYfEm2ggeOKJYxu+SB LFmg== X-Forwarded-Encrypted: i=1; AFNElJ/Mc9tJ0Q2WV5zBZG9Y/M0mI+ThwX8w4lxj0Nfb8QMCtY+BeQIggqjEPL4/nrGZWw/AX88YN+kxXFeJPGk=@vger.kernel.org X-Gm-Message-State: AOJu0YwfT2o81ldUjkr8HKbOFLhKy90Ce7DWZ0ioc/vPy8sEnQWwU17e n+73e62pMbkcWrsY66mUSuDwbdXIJrJiPJo72b2tL1PHNxGAIOlaq47g X-Gm-Gg: Acq92OFBgzOxFdoKLGzZv7EtDhOyzlASsLya9JaICdVsmh+KwgEV6wC9vK4Ve2PdOuH N/x6DHoyNGxc8BgvAA/e2fmbLl265WB8IVrnoLe22mCkOafRlTklDINEsjYluHwpD983I57LNPr +E/3/RQw9cKnMH6IU/db1wch8pisdchhS6jD+DIRCpGapSOD3D9EIvqABbtpYA+QUNcrP1YW+2h eQA4BcZuV5U3kQbbWKuiCw/w5XFYN6Z3x5HHvKpwWvECako0NWSMAl3UFBYqK/GN02MM6OPWn7J 3XvH1O2MZO3AwtWdRREp8UWKhIivn78UN93L3sRhkNNNLpZiEg8HewCQa8H9x11DNU4+HYOX3Dt Y014Tp+SN0LmP5w+jOxbz0/ph4nVOEpmpVspbCRJBEbxgPAyYaIrg5rLafKuKVBouf36rePyQq4 TtWltzZigyI/u3GLfPYl5ogzB9Y/xNH+Ij01Hk55YF X-Received: by 2002:a05:6000:46da:b0:44a:247e:67b1 with SMTP id ffacd0b85a97d-460216bdebemr7681514f8f.5.1780565027275; Thu, 04 Jun 2026 02:23:47 -0700 (PDT) Received: from [192.168.37.44] ([217.61.173.50]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4601f2dc577sm14667219f8f.3.2026.06.04.02.23.46 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 04 Jun 2026 02:23:46 -0700 (PDT) Message-ID: <9c0bec93-e102-4655-8074-fd544b16d912@gmail.com> Date: Thu, 4 Jun 2026 11:23:46 +0200 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 v3 8/8] iio: tcs3472: implement wait time and sampling frequency From: Aldo Conte To: jic23@kernel.org Cc: dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org, shuah@kernel.org, joshua.crofts1@gmail.com, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linux.dev References: <20260522123420.45495-1-aldocontelk@gmail.com> <20260522123420.45495-9-aldocontelk@gmail.com> Content-Language: en-US In-Reply-To: <20260522123420.45495-9-aldocontelk@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 22/05/26 14:34, Aldo Conte wrote: > static int tcs3472_req_data(struct tcs3472_data *data) > { > int tries = 50; > @@ -166,16 +214,131 @@ static int tcs3472_read_raw(struct iio_dev *indio_dev, > *val = 0; > *val2 = (256 - data->atime) * 2400; > return IIO_VAL_INT_PLUS_MICRO; > + case IIO_CHAN_INFO_SAMP_FREQ: { > + unsigned int cycle_us = tcs3472_cycle_time_us(data); > + > + tcs3472_cycle_to_freq(cycle_us, val, val2); > + return IIO_VAL_INT_PLUS_MICRO; > + } > default: > return -EINVAL; > } > }Hi Jonathan, One more thing on v4 before I send it. For Sashiko's "tries too short" finding, I made the timeout dynamic based on the actual cycle time: cycle_us = tcs3472_cycle_time_us(data); timeout_ms = max(1000U, (cycle_us * 2) / USEC_PER_MSEC); tries = DIV_ROUND_UP(timeout_ms, 20); 2 * cycle_us gives some safety margin, and the 1-second floor keeps the original behavior on default configurations. This solves the timeout issue but introduces a new concern: tcs3472_cycle_time_us() reads data->{enable,wlong,wtime,atime} without holding the lock, both here and in the SAMP_FREQ case of read_raw() (also flagged by Sashiko). For the SAMP_FREQ case I'll just add guard(mutex)(&data->lock) before the call: case IIO_CHAN_INFO_SAMP_FREQ: { unsigned int cycle_us; guard(mutex)(&data->lock); cycle_us = tcs3472_cycle_time_us(data); tcs3472_cycle_to_freq(cycle_us, val, val2); return IIO_VAL_INT_PLUS_MICRO; } For tcs3472_req_data() I plan to use scoped_guard() only around the cycle_us computation: scoped_guard(mutex, &data->lock) cycle_us = tcs3472_cycle_time_us(data); timeout_ms = max(1000U, (cycle_us * 2) / USEC_PER_MSEC); tries = DIV_ROUND_UP(timeout_ms, 20); while (tries--) { ... } Could this be ok? Thanks, Aldo