]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
iio: magnetometer: HID: hid-sensor-magn-3d: Refactor channel initialization
authorNatália Salvino André <natalia.andre@ime.usp.br>
Tue, 19 May 2026 23:40:47 +0000 (20:40 -0300)
committerJonathan Cameron <jic23@kernel.org>
Sun, 31 May 2026 10:01:47 +0000 (11:01 +0100)
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>
drivers/iio/magnetometer/hid-sensor-magn-3d.c

index b01dd53eb1009fd445f17a8506691b3553d1c7df..23884825eb00fb05ebbd10b9b134cc34f9e1b23c 100644 (file)
@@ -3,6 +3,7 @@
  * HID Sensors Driver
  * Copyright (c) 2012, Intel Corporation.
  */
+#include <linux/bitops.h>
 #include <linux/device.h>
 #include <linux/platform_device.h>
 #include <linux/module.h>
@@ -132,17 +133,6 @@ static const struct iio_chan_spec magn_3d_channels[] = {
        IIO_CHAN_SOFT_TIMESTAMP(7)
 };
 
-/* Adjust channel real bits based on report descriptor */
-static void magn_3d_adjust_channel_bit_mask(struct iio_chan_spec *channels,
-                                               int channel, int size)
-{
-       channels[channel].scan_type.sign = 's';
-       /* Real storage bits will change based on the report desc. */
-       channels[channel].scan_type.realbits = size * 8;
-       /* Maximum size of a sample to capture is u32 */
-       channels[channel].scan_type.storagebits = sizeof(u32) * 8;
-}
-
 /* Channel read_raw handler */
 static int magn_3d_read_raw(struct iio_dev *indio_dev,
                              struct iio_chan_spec const *chan,
@@ -418,9 +408,11 @@ static int magn_3d_parse_report(struct platform_device *pdev,
                        if (i != CHANNEL_SCAN_INDEX_TIMESTAMP) {
                                /* Set magn_val_addr to iio value address */
                                st->magn_val_addr[i] = &st->iio_vals[*chan_count];
-                               magn_3d_adjust_channel_bit_mask(_channels,
-                                                               *chan_count,
-                                                               st->magn[i].size);
+                               _channels[*chan_count].scan_type = (struct iio_scan_type) {
+                                       .format = 's',
+                                       .realbits = BYTES_TO_BITS(st->magn[i].size),
+                                       .storagebits = BITS_PER_TYPE(u32),
+                               };
                        }
                        (*chan_count)++;
                }