Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

iio: gts-helpers: fix integration time units

The IIO ABI mandates expressing integration times in seconds. The GTS
helper errorneously uses micro seconds in integration_times_available.
Fix this by converting the lists to IIO_VAL_INT_PLUS_MICRO.

Fixes: 38416c28e168 ("iio: light: Add gain-time-scale helpers")
Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
Link: https://lore.kernel.org/r/eeacd192c259e885850b5a2dd8b776bccfc44fa8.1681722914.git.mazziesaccount@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Matti Vaittinen and committed by
Jonathan Cameron
e6506513 b7b04f39

+32 -10
+32 -10
drivers/iio/industrialio-gts-helper.c
··· 337 337 return ret; 338 338 } 339 339 340 + static void iio_gts_us_to_int_micro(int *time_us, int *int_micro_times, 341 + int num_times) 342 + { 343 + int i; 344 + 345 + for (i = 0; i < num_times; i++) { 346 + int_micro_times[i * 2] = time_us[i] / 1000000; 347 + int_micro_times[i * 2 + 1] = time_us[i] % 1000000; 348 + } 349 + } 350 + 340 351 /** 341 352 * iio_gts_build_avail_time_table - build table of available integration times 342 353 * @gts: Gain time scale descriptor ··· 362 351 */ 363 352 static int iio_gts_build_avail_time_table(struct iio_gts *gts) 364 353 { 365 - int *times, i, j, idx = 0; 354 + int *times, i, j, idx = 0, *int_micro_times; 366 355 367 356 if (!gts->num_itime) 368 357 return 0; ··· 389 378 } 390 379 } 391 380 } 392 - gts->avail_time_tables = times; 393 - /* 394 - * This is just to survive a unlikely corner-case where times in the 395 - * given time table were not unique. Else we could just trust the 396 - * gts->num_itime. 397 - */ 398 - gts->num_avail_time_tables = idx; 381 + 382 + /* create a list of times formatted as list of IIO_VAL_INT_PLUS_MICRO */ 383 + int_micro_times = kcalloc(idx, sizeof(int) * 2, GFP_KERNEL); 384 + if (int_micro_times) { 385 + /* 386 + * This is just to survive a unlikely corner-case where times in 387 + * the given time table were not unique. Else we could just 388 + * trust the gts->num_itime. 389 + */ 390 + gts->num_avail_time_tables = idx; 391 + iio_gts_us_to_int_micro(times, int_micro_times, idx); 392 + } 393 + 394 + gts->avail_time_tables = int_micro_times; 395 + kfree(times); 396 + 397 + if (!int_micro_times) 398 + return -ENOMEM; 399 399 400 400 return 0; 401 401 } ··· 705 683 return -EINVAL; 706 684 707 685 *vals = gts->avail_time_tables; 708 - *type = IIO_VAL_INT; 709 - *length = gts->num_avail_time_tables; 686 + *type = IIO_VAL_INT_PLUS_MICRO; 687 + *length = gts->num_avail_time_tables * 2; 710 688 711 689 return IIO_AVAIL_LIST; 712 690 }