Skip to content

Commit da097d8

Browse files
committed
Mask set and way parameters before shifting to prevent overflow
1 parent aa3e5d0 commit da097d8

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/peripheral/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,8 +1019,8 @@ impl Cbp {
10191019
// Cortex-M7 have a DCACHE or ICACHE at all, it seems safe to do the same thing as the
10201020
// CMSIS-Core implementation and use fixed values.
10211021
unsafe { self.dcisw.write(
1022-
(((way as u32) << CBP_SW_WAY_POS) & CBP_SW_WAY_MASK) |
1023-
(((set as u32) << CBP_SW_SET_POS) & CBP_SW_SET_MASK));
1022+
(((way as u32) & (CBP_SW_WAY_MASK >> CBP_SW_WAY_POS)) << CBP_SW_WAY_POS) |
1023+
(((set as u32) & (CBP_SW_SET_MASK >> CBP_SW_SET_POS)) << CBP_SW_SET_POS));
10241024
}
10251025
}
10261026

@@ -1043,8 +1043,8 @@ impl Cbp {
10431043
pub fn dccsw(&self, set: u16, way: u16) {
10441044
// See comment for dcisw() about the format here
10451045
unsafe { self.dccsw.write(
1046-
(((way as u32) << CBP_SW_WAY_POS) & CBP_SW_WAY_MASK) |
1047-
(((set as u32) << CBP_SW_SET_POS) & CBP_SW_SET_MASK));
1046+
(((way as u32) & (CBP_SW_WAY_MASK >> CBP_SW_WAY_POS)) << CBP_SW_WAY_POS) |
1047+
(((set as u32) & (CBP_SW_SET_MASK >> CBP_SW_SET_POS)) << CBP_SW_SET_POS));
10481048
}
10491049
}
10501050

@@ -1061,8 +1061,8 @@ impl Cbp {
10611061
pub fn dccisw(&self, set: u16, way: u16) {
10621062
// See comment for dcisw() about the format here
10631063
unsafe { self.dccisw.write(
1064-
(((way as u32) << CBP_SW_WAY_POS) & CBP_SW_WAY_MASK) |
1065-
(((set as u32) << CBP_SW_SET_POS) & CBP_SW_SET_MASK));
1064+
(((way as u32) & (CBP_SW_WAY_MASK >> CBP_SW_WAY_POS)) << CBP_SW_WAY_POS) |
1065+
(((set as u32) & (CBP_SW_SET_MASK >> CBP_SW_SET_POS)) << CBP_SW_SET_POS));
10661066
}
10671067
}
10681068

0 commit comments

Comments
 (0)