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: adc: ad_sigma_delta: use BITS_TO_BYTES() macro

Use the BITS_TO_BYTES() macro instead of dividing by 8 to convert bits
to bytes.

This makes it more obvious what unit conversion is taking place.

In one instance, we also avoid the temporary assignment to a variable
as it was confusing that reg_size was being used with two different
units (bits and bytes).

scan_type is factored out to reduce line wrapping.

Signed-off-by: David Lechner <dlechner@baylibre.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Link: https://patch.msgid.link/20250701-iio-adc-ad7173-add-spi-offload-support-v3-5-42abb83e3dac@baylibre.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

David Lechner and committed by
Jonathan Cameron
e916934b 1a913da6

+8 -7
+8 -7
drivers/iio/adc/ad_sigma_delta.c
··· 7 7 */ 8 8 9 9 #include <linux/align.h> 10 + #include <linux/bitops.h> 10 11 #include <linux/device.h> 11 12 #include <linux/err.h> 12 13 #include <linux/interrupt.h> ··· 191 190 u8 *buf; 192 191 int ret; 193 192 194 - size = DIV_ROUND_UP(reset_length, 8); 193 + size = BITS_TO_BYTES(reset_length); 195 194 buf = kcalloc(size, sizeof(*buf), GFP_KERNEL); 196 195 if (!buf) 197 196 return -ENOMEM; ··· 420 419 data_reg = AD_SD_REG_DATA; 421 420 422 421 ret = ad_sd_read_reg(sigma_delta, data_reg, 423 - DIV_ROUND_UP(chan->scan_type.realbits + chan->scan_type.shift, 8), 422 + BITS_TO_BYTES(chan->scan_type.realbits + chan->scan_type.shift), 424 423 &raw_sample); 425 424 426 425 out: ··· 454 453 static int ad_sd_buffer_postenable(struct iio_dev *indio_dev) 455 454 { 456 455 struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev); 456 + const struct iio_scan_type *scan_type = &indio_dev->channels[0].scan_type; 457 457 unsigned int i, slot, samples_buf_size; 458 458 unsigned int channel; 459 459 u8 *samples_buf; ··· 490 488 return ret; 491 489 } 492 490 493 - samples_buf_size = ALIGN(slot * indio_dev->channels[0].scan_type.storagebits / 8, 491 + samples_buf_size = ALIGN(slot * BITS_TO_BYTES(scan_type->storagebits), 494 492 sizeof(s64)); 495 493 samples_buf_size += sizeof(s64); 496 494 samples_buf = devm_krealloc(&sigma_delta->spi->dev, sigma_delta->samples_buf, ··· 546 544 { 547 545 struct iio_poll_func *pf = p; 548 546 struct iio_dev *indio_dev = pf->indio_dev; 547 + const struct iio_scan_type *scan_type = &indio_dev->channels[0].scan_type; 549 548 struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev); 550 549 u8 *data = sigma_delta->rx_buf; 551 550 unsigned int transfer_size; ··· 556 553 unsigned int reg_size; 557 554 unsigned int data_reg; 558 555 559 - reg_size = indio_dev->channels[0].scan_type.realbits + 560 - indio_dev->channels[0].scan_type.shift; 561 - reg_size = DIV_ROUND_UP(reg_size, 8); 556 + reg_size = BITS_TO_BYTES(scan_type->realbits + scan_type->shift); 562 557 563 558 if (sigma_delta->info->data_reg != 0) 564 559 data_reg = sigma_delta->info->data_reg; ··· 618 617 } 619 618 } 620 619 621 - sample_size = indio_dev->channels[0].scan_type.storagebits / 8; 620 + sample_size = BITS_TO_BYTES(scan_type->storagebits); 622 621 sample_pos = sample_size * sigma_delta->current_slot; 623 622 memcpy(&sigma_delta->samples_buf[sample_pos], data, sample_size); 624 623 sigma_delta->current_slot++;