From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (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 14EF633C52F for ; Mon, 1 Jun 2026 09:42:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780306937; cv=none; b=pm0ou5JD3vKj3Quf9mgk/lnf0JNfAb9zi1JMQ0ypT/L9Ub9aLm64E3DavXw2dZ6LYGHeDhyhYH8zcX96PXUxlHdAX48C6crD822CkvEQQycaPfuOkUMV0v5vfxcJMolO3Z5fiq8KR3+ifx/s1sqLS9vv2ceNRKvhnIcAPlSaDi8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780306937; c=relaxed/simple; bh=M4KJACFzvesHU8ZcNTqZNU2lBZR0p+BUriDvgnQRgKA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=AQJkuui5Hdhyirq3GoksHH2KOjXqO2qCKNt+VfgeHiytfAo3iKSwOvnpKG2lU+vubq4iVu8wYfaU/XGZKD7sQJK1k5sBx1M9OxO3cuffdD3x91FdlMAIu8kWm/o/Jn8EiamrgglB8w8X3yAhJF/9WAU1fNR4sgaxPdfD64O8uuU= 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=Ofa4pL1O; arc=none smtp.client-ip=209.85.128.42 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="Ofa4pL1O" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-4903997fcb5so101567505e9.2 for ; Mon, 01 Jun 2026 02:42:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780306934; x=1780911734; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=yej0wnG6WIrmpOSuTlhVpOj2TC3TsG+QHTev2H2YE0M=; b=Ofa4pL1OoOUvRPRqyi5+VclYD2rgWkRgX/TAF4TGLvgpBhTUL1cxiFA2OJqFuwEDTy 1OE6qpGBY2BdtNAKBl8GG35OFYjgGnSxwcLTXxOf479Nmxeb47sff9VUc3b9goWt37L4 wuQJFSpfoNRPW020fAEvrKILrfK6YIHl9fXNafqRI3MsESArpp+mv3NRzv+5uBI5evU6 f/oBPJlPCd7DkdGj7CE6jagHQPKdB3BbkPGtpTYzcdhFJi3lmeWTEfMKHcrEh4ia89aH hSe826dL9jxehElWDqx6gTK6Y8PgenysEXwTJZofUsE2w1jdxLLdpAOP/nH+FiIwSe9+ utjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780306934; x=1780911734; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=yej0wnG6WIrmpOSuTlhVpOj2TC3TsG+QHTev2H2YE0M=; b=rkVJBf07/AvS9xGJ5+6KcxndobPbob8UHrJ6VIoPxfhEHHd72K0mmDFCZeeh5ktU8h lzTC+9sS5tR088vkl52gTwZONLxpIBdmkaa8lMsFYgVI2kFgTR2JPfkEb/Y/dSEZLeHt iANjthFChsnJmqeiNwFOiR6NMMyWuVw5Pqk8/SmOdhVabAaOfWBncrxhcoFfuwsQVlRm 3X69VL/TruC3DGCxC1JgvNXW7qFitINp5gskpHC7yfcIPx3gTsmzndooFR1ZuOz5zhpw onCCqWIipWOdPHSE7MldqTkCK91g7Q6SzVHpqmhBsr8EZLTc2qSe6w8CcgJJ9Dmkp365 MTHg== X-Gm-Message-State: AOJu0Ywn/KEjQunDiPjwrlEQojgbgYugeOG70qCC6pcs6Y1uiyl3kUq/ 0Lv/oEn5XS9Azq829fwr28gfkYRIEuGpxoeWr34MteF5vv/UHN32084E X-Gm-Gg: Acq92OEOgw0q+vrYpYVuTKIcYGH83Ipi+jTFFXz02u9h2R/+OaMljzgxkuAaPTYdk70 8dth3w1zu0ebFH9vJKJwx6ZG08b5Pn4TgmUw6voIgQvlcv9+qePOoOdn1qYnz8nwOg7avpXwXLb hf/32pOgv8wA5FNXBkoif4EbVrq2e5UpQJyNmqFx+/G7eoYAGEBkHh71CA3vMxRdjIfMh+5/qoW KBB9OdmTA5SSPahyjWbAecMnQWnidjVegYOKfrPuQHGgWsZbXUEZFEYSnIzcmDSYhSKb+z9PpF/ cMdcoD0yzcEW3p44e7wbFAfCnz/Lk8161TDDjihwzmfVzKCFmGhIlu/Ql8m1z5gZnTgzROobGuy 3pNu1W6h4rgcidD3x1jlv3D/JRrTH5hIhRxpg6Pj3ywMXJPG1WtuE7KfbvdNpF5wa2AcNKR7ZOt 4jOwx+rIlECS/xGrIOPZfQtTqPqQ== X-Received: by 2002:a05:600d:8497:10b0:490:6869:9601 with SMTP id 5b1f17b1804b1-490a292a48fmr129304845e9.6.1780306934316; Mon, 01 Jun 2026 02:42:14 -0700 (PDT) Received: from nsa ([148.63.225.166]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4909d6f3612sm241891185e9.12.2026.06.01.02.42.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jun 2026 02:42:13 -0700 (PDT) Date: Mon, 1 Jun 2026 10:43:11 +0100 From: Nuno =?utf-8?B?U8Oh?= To: rodrigo.alencar@analog.com Cc: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-doc@vger.kernel.org, Jonathan Cameron , David Lechner , Andy Shevchenko , Lars-Peter Clausen , Michael Hennerich , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Corbet , Andrew Morton , Petr Mladek , Steven Rostedt , Andy Shevchenko , Rasmus Villemoes , Sergey Senozhatsky , Shuah Khan Subject: Re: [PATCH v15 06/12] iio: core: add decimal value formatting into 64-bit value Message-ID: References: <20260531-adf41513-iio-driver-v15-0-da09adf1c0dd@analog.com> <20260531-adf41513-iio-driver-v15-6-da09adf1c0dd@analog.com> 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-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20260531-adf41513-iio-driver-v15-6-da09adf1c0dd@analog.com> On Sun, May 31, 2026 at 09:30:49AM +0100, Rodrigo Alencar via B4 Relay wrote: > From: Rodrigo Alencar > > Create new format types for iio values (IIO_VAL_DECIMAL64_*), which > defines the representation of fixed decimal point values into a single > 64-bit number. This new format increases the range of represented values, > allowing for integer parts greater than 2^32, as bits are not "wasted" > in the fractional part, which can be seen in IIO_VAL_INT_PLUS_MICRO and > IIO_VAL_INT_PLUS_NANO. Helpers are created to compose and decompose 64-bit > decimals into integer values used in IIO formatting interfaces, which > creates consistency and avoid error-prone manual assignments when using > wordpart macros. When doing the parsing, kstrtodec64() is used with the > scale defined by the specific decimal format type. > > Signed-off-by: Rodrigo Alencar > --- > drivers/iio/industrialio-core.c | 47 +++++++++++++++++++++++++++++++++-------- > include/linux/iio/types.h | 30 ++++++++++++++++++++++++++ > 2 files changed, 68 insertions(+), 9 deletions(-) > > diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c > index bd6f4f9f4533..a88088cac641 100644 > --- a/drivers/iio/industrialio-core.c > +++ b/drivers/iio/industrialio-core.c > @@ -19,6 +19,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -26,7 +27,6 @@ > #include > #include > #include > -#include > > #include > #include > @@ -655,6 +655,7 @@ static ssize_t __iio_format_value(char *buf, size_t offset, unsigned int type, > int size, const int *vals) > { > int tmp0, tmp1; > + int l = 0; > s64 tmp2; > bool scale_db = false; > > @@ -698,7 +699,6 @@ static ssize_t __iio_format_value(char *buf, size_t offset, unsigned int type, > case IIO_VAL_INT_MULTIPLE: > { > int i; > - int l = 0; > > for (i = 0; i < size; ++i) > l += sysfs_emit_at(buf, offset + l, "%d ", vals[i]); > @@ -707,8 +707,25 @@ static ssize_t __iio_format_value(char *buf, size_t offset, unsigned int type, > case IIO_VAL_CHAR: > return sysfs_emit_at(buf, offset, "%c", (char)vals[0]); > case IIO_VAL_INT_64: > - tmp2 = (s64)((((u64)vals[1]) << 32) | (u32)vals[0]); > + tmp2 = iio_val_s64_from_s32s(vals); I might be missing something but can't we just call iio_val_s64_compose()? Likely even inline in sysfs_emit_at()? It would match your call to iio_val_s64_decompose() below. And the above makes me wonder if the compose()/decompose() are not the only helpers we need? At least in terms of parameters? I mean, just assuming we only have two integers instead of allowing s32* and opening the door for misbehave :)? Don't feel too strong about the above anyways! - Nuno Sá