Skip to content

Commit ceb2303

Browse files
dcpleungnashif
authored andcommitted
pwm: pwm_mchp_xec: fix potential out of bound access
Fix an issue discovered by Coverity where there is a potential out of bound access on the divisor arrays. Fixes #20495 Fixes #20496 Signed-off-by: Daniel Leung <[email protected]>
1 parent 5f63c9d commit ceb2303

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

drivers/pwm/pwm_mchp_xec.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ struct xec_params {
5959
u8_t div;
6060
};
6161

62-
u32_t max_freq_high_on_div[16] = {
62+
#define NUM_DIV_ELEMS 16
63+
64+
u32_t max_freq_high_on_div[NUM_DIV_ELEMS] = {
6365
48000000,
6466
24000000,
6567
16000000,
@@ -78,7 +80,7 @@ u32_t max_freq_high_on_div[16] = {
7880
3000000
7981
};
8082

81-
u32_t max_freq_low_on_div[16] = {
83+
u32_t max_freq_low_on_div[NUM_DIV_ELEMS] = {
8284
100000,
8385
50000,
8486
33333,
@@ -200,14 +202,14 @@ static struct xec_params *xec_compare_params(u32_t target_freq,
200202
u32_t freq_h = 0;
201203
u32_t freq_l = 0;
202204

203-
if (hc_params->div < UINT8_MAX) {
205+
if (hc_params->div < NUM_DIV_ELEMS) {
204206
freq_h = xec_compute_frequency(
205207
max_freq_high_on_div[hc_params->div],
206208
hc_params->on,
207209
hc_params->off);
208210
}
209211

210-
if (lc_params->div < UINT8_MAX) {
212+
if (lc_params->div < NUM_DIV_ELEMS) {
211213
freq_l = xec_compute_frequency(
212214
max_freq_low_on_div[lc_params->div],
213215
lc_params->on,

0 commit comments

Comments
 (0)