Skip to content

Commit 3390026

Browse files
Natália Salvino Andréjic23
authored andcommitted
iio: magnetometer: HID: hid-sensor-magn-3d: Refactor channel initialization
Replace the local magn_3d_adjust_channel_bit_mask() function with a compound literal for scan_type initialization to improve code readability. Signed-off-by: Natália Salvino André <natalia.andre@ime.usp.br> Co-developed-by: Pietro Di Consolo Gregorio <pietro.gregorio@usp.br> Signed-off-by: Pietro Di Consolo Gregorio <pietro.gregorio@usp.br> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
1 parent e6cd877 commit 3390026

1 file changed

Lines changed: 6 additions & 14 deletions

File tree

drivers/iio/magnetometer/hid-sensor-magn-3d.c

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* HID Sensors Driver
44
* Copyright (c) 2012, Intel Corporation.
55
*/
6+
#include <linux/bitops.h>
67
#include <linux/device.h>
78
#include <linux/platform_device.h>
89
#include <linux/module.h>
@@ -132,17 +133,6 @@ static const struct iio_chan_spec magn_3d_channels[] = {
132133
IIO_CHAN_SOFT_TIMESTAMP(7)
133134
};
134135

135-
/* Adjust channel real bits based on report descriptor */
136-
static void magn_3d_adjust_channel_bit_mask(struct iio_chan_spec *channels,
137-
int channel, int size)
138-
{
139-
channels[channel].scan_type.sign = 's';
140-
/* Real storage bits will change based on the report desc. */
141-
channels[channel].scan_type.realbits = size * 8;
142-
/* Maximum size of a sample to capture is u32 */
143-
channels[channel].scan_type.storagebits = sizeof(u32) * 8;
144-
}
145-
146136
/* Channel read_raw handler */
147137
static int magn_3d_read_raw(struct iio_dev *indio_dev,
148138
struct iio_chan_spec const *chan,
@@ -418,9 +408,11 @@ static int magn_3d_parse_report(struct platform_device *pdev,
418408
if (i != CHANNEL_SCAN_INDEX_TIMESTAMP) {
419409
/* Set magn_val_addr to iio value address */
420410
st->magn_val_addr[i] = &st->iio_vals[*chan_count];
421-
magn_3d_adjust_channel_bit_mask(_channels,
422-
*chan_count,
423-
st->magn[i].size);
411+
_channels[*chan_count].scan_type = (struct iio_scan_type) {
412+
.format = 's',
413+
.realbits = BYTES_TO_BITS(st->magn[i].size),
414+
.storagebits = BITS_PER_TYPE(u32),
415+
};
424416
}
425417
(*chan_count)++;
426418
}

0 commit comments

Comments
 (0)