@@ -29,7 +29,8 @@ int st_sensors_get_buffer_element(struct iio_dev *indio_dev, u8 *buf)
struct st_sensor_data *sdata = iio_priv(indio_dev);
unsigned int num_data_channels = sdata->num_data_channels;
unsigned int byte_for_channel =
- indio_dev->channels[0].scan_type.storagebits >> 3;
+ DIV_ROUND_UP(indio_dev->channels[0].scan_type.realbits +
+ indio_dev->channels[0].scan_type.shift, 8);
addr = kmalloc(num_data_channels, GFP_KERNEL);
if (!addr) {
@@ -444,8 +444,10 @@ static int st_sensors_read_axis_data(struct iio_dev *indio_dev,
int err;
u8 *outdata;
struct st_sensor_data *sdata = iio_priv(indio_dev);
- unsigned int byte_for_channel = ch->scan_type.storagebits >> 3;
+ unsigned int byte_for_channel;
+ byte_for_channel = DIV_ROUND_UP(ch->scan_type.realbits +
+ ch->scan_type.shift, 8);
outdata = kmalloc(byte_for_channel, GFP_KERNEL);
if (!outdata)
return -ENOMEM;