From: David Lechner Date: Tue, 1 Jul 2025 21:37:53 +0000 (-0500) Subject: iio: adc: ad_sigma_delta: use BITS_TO_BYTES() macro X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e916934b591585140a59ac899ac356cd4a1f269f;p=thirdparty%2Fkernel%2Fstable.git 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 Reviewed-by: Andy Shevchenko Reviewed-by: Nuno Sá Link: https://patch.msgid.link/20250701-iio-adc-ad7173-add-spi-offload-support-v3-5-42abb83e3dac@baylibre.com Signed-off-by: Jonathan Cameron --- diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c index dd15c357d149..f91f7ae6dfca 100644 --- a/drivers/iio/adc/ad_sigma_delta.c +++ b/drivers/iio/adc/ad_sigma_delta.c @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -190,7 +191,7 @@ int ad_sd_reset(struct ad_sigma_delta *sigma_delta) u8 *buf; int ret; - size = DIV_ROUND_UP(reset_length, 8); + size = BITS_TO_BYTES(reset_length); buf = kcalloc(size, sizeof(*buf), GFP_KERNEL); if (!buf) return -ENOMEM; @@ -419,7 +420,7 @@ int ad_sigma_delta_single_conversion(struct iio_dev *indio_dev, data_reg = AD_SD_REG_DATA; ret = ad_sd_read_reg(sigma_delta, data_reg, - DIV_ROUND_UP(chan->scan_type.realbits + chan->scan_type.shift, 8), + BITS_TO_BYTES(chan->scan_type.realbits + chan->scan_type.shift), &raw_sample); out: @@ -453,6 +454,7 @@ EXPORT_SYMBOL_NS_GPL(ad_sigma_delta_single_conversion, "IIO_AD_SIGMA_DELTA"); static int ad_sd_buffer_postenable(struct iio_dev *indio_dev) { struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev); + const struct iio_scan_type *scan_type = &indio_dev->channels[0].scan_type; unsigned int i, slot, samples_buf_size; unsigned int channel; u8 *samples_buf; @@ -488,7 +490,7 @@ static int ad_sd_buffer_postenable(struct iio_dev *indio_dev) return ret; } - samples_buf_size = ALIGN(slot * indio_dev->channels[0].scan_type.storagebits / 8, + samples_buf_size = ALIGN(slot * BITS_TO_BYTES(scan_type->storagebits), sizeof(s64)); samples_buf_size += sizeof(s64); samples_buf = devm_krealloc(&sigma_delta->spi->dev, sigma_delta->samples_buf, @@ -544,6 +546,7 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p) { struct iio_poll_func *pf = p; struct iio_dev *indio_dev = pf->indio_dev; + const struct iio_scan_type *scan_type = &indio_dev->channels[0].scan_type; struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev); u8 *data = sigma_delta->rx_buf; unsigned int transfer_size; @@ -553,9 +556,7 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p) unsigned int reg_size; unsigned int data_reg; - reg_size = indio_dev->channels[0].scan_type.realbits + - indio_dev->channels[0].scan_type.shift; - reg_size = DIV_ROUND_UP(reg_size, 8); + reg_size = BITS_TO_BYTES(scan_type->realbits + scan_type->shift); if (sigma_delta->info->data_reg != 0) data_reg = sigma_delta->info->data_reg; @@ -617,7 +618,7 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p) } } - sample_size = indio_dev->channels[0].scan_type.storagebits / 8; + sample_size = BITS_TO_BYTES(scan_type->storagebits); sample_pos = sample_size * sigma_delta->current_slot; memcpy(&sigma_delta->samples_buf[sample_pos], data, sample_size); sigma_delta->current_slot++;