Skip to content

Commit cded217

Browse files
Natália Salvino Andréjic23
authored andcommitted
iio: light: HID: hid-sensor-als: Refactor channel initialization
Replace the local als_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 3a7f08f commit cded217

1 file changed

Lines changed: 6 additions & 12 deletions

File tree

drivers/iio/light/hid-sensor-als.c

Lines changed: 6 additions & 12 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>
@@ -117,17 +118,6 @@ static const struct iio_chan_spec als_channels[] = {
117118
IIO_CHAN_SOFT_TIMESTAMP(CHANNEL_SCAN_INDEX_TIMESTAMP)
118119
};
119120

120-
/* Adjust channel real bits based on report descriptor */
121-
static void als_adjust_channel_bit_mask(struct iio_chan_spec *channels,
122-
int channel, int size)
123-
{
124-
channels[channel].scan_type.sign = 's';
125-
/* Real storage bits will change based on the report desc. */
126-
channels[channel].scan_type.realbits = size * 8;
127-
/* Maximum size of a sample to capture is u32 */
128-
channels[channel].scan_type.storagebits = sizeof(u32) * 8;
129-
}
130-
131121
/* Channel read_raw handler */
132122
static int als_read_raw(struct iio_dev *indio_dev,
133123
struct iio_chan_spec const *chan,
@@ -335,7 +325,11 @@ static int als_parse_report(struct platform_device *pdev,
335325

336326
channels[index] = als_channels[i];
337327
st->als_scan_mask[0] |= BIT(i);
338-
als_adjust_channel_bit_mask(channels, index, st->als[i].size);
328+
channels[index].scan_type = (struct iio_scan_type) {
329+
.format = 's',
330+
.realbits = BYTES_TO_BITS(st->als[i].size),
331+
.storagebits = BITS_PER_TYPE(u32),
332+
};
339333
++index;
340334

341335
dev_dbg(&pdev->dev, "als %x:%x\n", st->als[i].index,

0 commit comments

Comments
 (0)