Skip to content

Commit 50467d8

Browse files
dlechjic23
authored andcommitted
iio: imu: bno055: make bno055_sysfs_attr const
Add const qualifier to struct bno055_sysfs_attr and its array fields. All of this is read-only data so it can be made const. Signed-off-by: David Lechner <dlechner@baylibre.com> Link: https://patch.msgid.link/20250709-iio-const-data-19-v2-2-fb3fc9191251@baylibre.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent 399b883 commit 50467d8

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

drivers/iio/imu/bno055/bno055.c

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -114,35 +114,35 @@
114114
#define BNO055_UID_LEN 16
115115

116116
struct bno055_sysfs_attr {
117-
int *vals;
117+
const int *vals;
118118
int len;
119-
int *fusion_vals;
120-
int *hw_xlate;
119+
const int *fusion_vals;
120+
const int *hw_xlate;
121121
int hw_xlate_len;
122122
int type;
123123
};
124124

125-
static int bno055_acc_lpf_vals[] = {
125+
static const int bno055_acc_lpf_vals[] = {
126126
7, 810000, 15, 630000, 31, 250000, 62, 500000,
127127
125, 0, 250, 0, 500, 0, 1000, 0,
128128
};
129129

130-
static struct bno055_sysfs_attr bno055_acc_lpf = {
130+
static const struct bno055_sysfs_attr bno055_acc_lpf = {
131131
.vals = bno055_acc_lpf_vals,
132132
.len = ARRAY_SIZE(bno055_acc_lpf_vals),
133-
.fusion_vals = (int[]){62, 500000},
133+
.fusion_vals = (const int[]){62, 500000},
134134
.type = IIO_VAL_INT_PLUS_MICRO,
135135
};
136136

137-
static int bno055_acc_range_vals[] = {
137+
static const int bno055_acc_range_vals[] = {
138138
/* G: 2, 4, 8, 16 */
139139
1962, 3924, 7848, 15696
140140
};
141141

142-
static struct bno055_sysfs_attr bno055_acc_range = {
142+
static const struct bno055_sysfs_attr bno055_acc_range = {
143143
.vals = bno055_acc_range_vals,
144144
.len = ARRAY_SIZE(bno055_acc_range_vals),
145-
.fusion_vals = (int[]){3924}, /* 4G */
145+
.fusion_vals = (const int[]){3924}, /* 4G */
146146
.type = IIO_VAL_INT,
147147
};
148148

@@ -166,37 +166,37 @@ static struct bno055_sysfs_attr bno055_acc_range = {
166166
* = hwval * (dps_range/(2^15 * k))
167167
* where k is rad-to-deg factor
168168
*/
169-
static int bno055_gyr_scale_vals[] = {
169+
static const int bno055_gyr_scale_vals[] = {
170170
125, 1877467, 250, 1877467, 500, 1877467,
171171
1000, 1877467, 2000, 1877467,
172172
};
173173

174-
static int bno055_gyr_scale_hw_xlate[] = {0, 1, 2, 3, 4};
175-
static struct bno055_sysfs_attr bno055_gyr_scale = {
174+
static const int bno055_gyr_scale_hw_xlate[] = {0, 1, 2, 3, 4};
175+
static const struct bno055_sysfs_attr bno055_gyr_scale = {
176176
.vals = bno055_gyr_scale_vals,
177177
.len = ARRAY_SIZE(bno055_gyr_scale_vals),
178-
.fusion_vals = (int[]){1, 900},
178+
.fusion_vals = (const int[]){1, 900},
179179
.hw_xlate = bno055_gyr_scale_hw_xlate,
180180
.hw_xlate_len = ARRAY_SIZE(bno055_gyr_scale_hw_xlate),
181181
.type = IIO_VAL_FRACTIONAL,
182182
};
183183

184-
static int bno055_gyr_lpf_vals[] = {12, 23, 32, 47, 64, 116, 230, 523};
185-
static int bno055_gyr_lpf_hw_xlate[] = {5, 4, 7, 3, 6, 2, 1, 0};
186-
static struct bno055_sysfs_attr bno055_gyr_lpf = {
184+
static const int bno055_gyr_lpf_vals[] = {12, 23, 32, 47, 64, 116, 230, 523};
185+
static const int bno055_gyr_lpf_hw_xlate[] = {5, 4, 7, 3, 6, 2, 1, 0};
186+
static const struct bno055_sysfs_attr bno055_gyr_lpf = {
187187
.vals = bno055_gyr_lpf_vals,
188188
.len = ARRAY_SIZE(bno055_gyr_lpf_vals),
189-
.fusion_vals = (int[]){32},
189+
.fusion_vals = (const int[]){32},
190190
.hw_xlate = bno055_gyr_lpf_hw_xlate,
191191
.hw_xlate_len = ARRAY_SIZE(bno055_gyr_lpf_hw_xlate),
192192
.type = IIO_VAL_INT,
193193
};
194194

195-
static int bno055_mag_odr_vals[] = {2, 6, 8, 10, 15, 20, 25, 30};
196-
static struct bno055_sysfs_attr bno055_mag_odr = {
195+
static const int bno055_mag_odr_vals[] = {2, 6, 8, 10, 15, 20, 25, 30};
196+
static const struct bno055_sysfs_attr bno055_mag_odr = {
197197
.vals = bno055_mag_odr_vals,
198198
.len = ARRAY_SIZE(bno055_mag_odr_vals),
199-
.fusion_vals = (int[]){20},
199+
.fusion_vals = (const int[]){20},
200200
.type = IIO_VAL_INT,
201201
};
202202

@@ -553,7 +553,8 @@ static const struct iio_chan_spec bno055_channels[] = {
553553
};
554554

555555
static int bno055_get_regmask(struct bno055_priv *priv, int *val, int *val2,
556-
int reg, int mask, struct bno055_sysfs_attr *attr)
556+
int reg, int mask,
557+
const struct bno055_sysfs_attr *attr)
557558
{
558559
const int shift = __ffs(mask);
559560
int hwval, idx;
@@ -582,7 +583,8 @@ static int bno055_get_regmask(struct bno055_priv *priv, int *val, int *val2,
582583
}
583584

584585
static int bno055_set_regmask(struct bno055_priv *priv, int val, int val2,
585-
int reg, int mask, struct bno055_sysfs_attr *attr)
586+
int reg, int mask,
587+
const struct bno055_sysfs_attr *attr)
586588
{
587589
const int shift = __ffs(mask);
588590
int best_delta;
@@ -763,7 +765,8 @@ static int bno055_read_simple_chan(struct iio_dev *indio_dev,
763765
}
764766
}
765767

766-
static int bno055_sysfs_attr_avail(struct bno055_priv *priv, struct bno055_sysfs_attr *attr,
768+
static int bno055_sysfs_attr_avail(struct bno055_priv *priv,
769+
const struct bno055_sysfs_attr *attr,
767770
const int **vals, int *length)
768771
{
769772
if (priv->operation_mode != BNO055_OPR_MODE_AMG) {

0 commit comments

Comments
 (0)