lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <8bb7d291-f94a-4e96-b3ec-93fbe06c8407@linux.dev>
Date: Tue, 15 Jul 2025 11:42:05 -0400
From: Sean Anderson <sean.anderson@...ux.dev>
To: Andy Shevchenko <andriy.shevchenko@...el.com>
Cc: Jonathan Cameron <jic23@...nel.org>, Jean Delvare <jdelvare@...e.com>,
 Guenter Roeck <linux@...ck-us.net>, linux-iio@...r.kernel.org,
 linux-hwmon@...r.kernel.org, Andy Shevchenko <andy@...nel.org>,
 Nuno Sá <nuno.sa@...log.com>, linux-kernel@...r.kernel.org,
 David Lechner <dlechner@...libre.com>
Subject: Re: [PATCH 2/7] iio: inkern: Add API for reading/writing events

On 7/15/25 04:18, Andy Shevchenko wrote:
> On Mon, Jul 14, 2025 at 09:20:18PM -0400, Sean Anderson wrote:
>> Add an in-kernel API for reading/writing event properties. Like the
>> raw-to-processed conversion, with processed-to-raw we only convert the
>> integer part, introducing some round-off error.
>> 
>> A common case is for other drivers to re-expose IIO events as sysfs
>> properties with a different API. To help out with this, iio_event_mode
>> returns the appropriate mode. It can also be used to test for existence
>> if the consumer doesn't care about read/write capability.
> 
> ...
> 
>> +EXPORT_SYMBOL_GPL(iio_event_mode);
> 
> Can we move this to namespace? Otherwise it will be never ending story...
> Ditto for other new APIs.

Never ending story of what?

> ...
> 
>> +			if (scale64 <= INT_MAX && scale64 >= INT_MIN)
>> +				raw64 = processed / (int)scale64;
> 
> Do you need the casting? (I mean if the compiler is dumb enough to not see this)

AIUI 64-bit division is not available on 32-bit platforms. The cast
ensures we get 32-bit division.

> ...
> 
>> +		case IIO_VAL_INT_PLUS_MICRO:
>> +			scale64 = scale_val * scale * 1000000LL + scale_val2;
>> +			raw64 = div64_s64_rem(processed, scale64, &r);
>> +			raw64 = raw64 * 1000000 +
>> +				div64_s64(r * 1000000, scale64);
> 
> Logically this should be 1000000L, but can we somehow use the constants?
> Like
> 
> 			scale64 = (s64)MICRO * scale_val * scale + scale_val2;
> 			raw64 = div64_s64_rem(processed, scale64, &r);
> 			raw64 = raw64 * (s32)MICRO +
> 				div64_s64(r * (s64)MICRO, scale64);
> 

This follows iio_convert_raw_to_processed_unlocked but ok...

>> +			break;
> 
> Ditto for other cases?
> 
> ...
> 
>> +	*raw = clamp(raw64, (s64)INT_MIN, (s64)INT_MAX);
> 
> You already have similar approach here...

Well, I can spell it 0x7fffffffLL if you'd like...

>> +	ret = iio_convert_processed_to_raw_unlocked(chan, processed, &raw,
>> +						    scale);
>> +	if (ret < 0)
> 
> Why ' < 0' ?

Originally I returned IIO_VAL_INT but later decided against it.

--Sean

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ