Skip to content

Commit 7b3e9ea

Browse files
ukleineknunojsa
authored andcommitted
iio: adc: ltc2387: Properly initialize all members of struct pwm_state vars
When just some members of a struct get assigned a value the remaining members have no defined value. In this case this affects .polarity and .usage_power. Fix that by using an idiom that initializes all unmentioned struct members to their default value. Fixes: 4eabb45 ("drivers: iio: adc: Add support for LTC2387") Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
1 parent 5554625 commit 7b3e9ea

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

drivers/iio/adc/ltc2387.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,14 @@ static int ltc2387_set_sampling_freq(struct ltc2387_dev *ltc, int freq)
152152
target = DIV_ROUND_CLOSEST_ULL(ltc->ref_clk_rate, freq);
153153
ref_clk_period_ps = DIV_ROUND_CLOSEST_ULL(1000000000000ULL,
154154
ltc->ref_clk_rate);
155-
cnv_state.period = ref_clk_period_ps * target;
156-
cnv_state.duty_cycle = ref_clk_period_ps;
157-
cnv_state.phase = 0;
158-
cnv_state.time_unit = PWM_UNIT_PSEC;
159-
cnv_state.enabled = true;
155+
156+
cnv_state = (struct pwm_state) {
157+
.period = ref_clk_period_ps * target,
158+
.duty_cycle = ref_clk_period_ps,
159+
.time_unit = PWM_UNIT_PSEC,
160+
.enabled = true,
161+
};
162+
160163
ret = pwm_apply_state(ltc->cnv, &cnv_state);
161164
if (ret < 0)
162165
return ret;
@@ -166,11 +169,15 @@ static int ltc2387_set_sampling_freq(struct ltc2387_dev *ltc, int freq)
166169
clk_en_time = DIV_ROUND_UP_ULL(ltc->device_info->resolution, 4);
167170
else
168171
clk_en_time = DIV_ROUND_UP_ULL(ltc->device_info->resolution, 2);
169-
clk_en_state.period = cnv_state.period;
170-
clk_en_state.duty_cycle = ref_clk_period_ps * clk_en_time;
171-
clk_en_state.phase = cnv_state.phase + LTC2387_T_FIRSTCLK;
172-
clk_en_state.time_unit = PWM_UNIT_PSEC;
173-
clk_en_state.enabled = true;
172+
173+
clk_en_state = (struct pwm_state) {
174+
.period = cnv_state.period,
175+
.duty_cycle = ref_clk_period_ps * clk_en_time,
176+
.phase = cnv_state.phase + LTC2387_T_FIRSTCLK,
177+
.time_unit = PWM_UNIT_PSEC,
178+
.enabled = true,
179+
};
180+
174181
ret = pwm_apply_state(ltc->clk_en, &clk_en_state);
175182
if (ret < 0)
176183
return ret;

0 commit comments

Comments
 (0)