Skip to content

Commit 8344cd6

Browse files
GseoCgregkh
authored andcommitted
bus: rifsc: fix RIF configuration check for peripherals
[ Upstream commit d5ce3b4 ] Peripheral holding CID0 cannot be accessed, remove this completely incorrect check. While there, fix and simplify the semaphore checking that should be performed when the CID filtering is enabled. Fixes: a182084 ("bus: rifsc: introduce RIFSC firewall controller driver") Signed-off-by: Gatien Chevallier <gatien.chevallier@foss.st.com> Link: https://lore.kernel.org/r/20260129-fix_cid_check_rifsc-v1-1-ef280ccf764d@foss.st.com Signed-off-by: Alexandre Torgue <alexandre.torgue@foss.st.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 8bfa413 commit 8344cd6

1 file changed

Lines changed: 18 additions & 34 deletions

File tree

drivers/bus/stm32_rifsc.c

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -126,54 +126,38 @@ static int stm32_rifsc_grant_access(struct stm32_firewall_controller *ctrl, u32
126126
sec_reg_value = readl(rifsc_controller->mmio + RIFSC_RISC_SECCFGR0 + 0x4 * reg_id);
127127
cid_reg_value = readl(rifsc_controller->mmio + RIFSC_RISC_PER0_CIDCFGR + 0x8 * firewall_id);
128128

129-
/* First check conditions for semaphore mode, which doesn't take into account static CID. */
130-
if ((cid_reg_value & CIDCFGR_SEMEN) && (cid_reg_value & CIDCFGR_CFEN)) {
131-
if (cid_reg_value & BIT(RIF_CID1 + SEMWL_SHIFT)) {
132-
/* Static CID is irrelevant if semaphore mode */
133-
goto skip_cid_check;
134-
} else {
135-
dev_dbg(rifsc_controller->dev,
136-
"Invalid bus semaphore configuration: index %d\n", firewall_id);
137-
return -EACCES;
138-
}
139-
}
140-
141-
/*
142-
* Skip CID check if CID filtering isn't enabled or filtering is enabled on CID0, which
143-
* corresponds to whatever CID.
144-
*/
145-
if (!(cid_reg_value & CIDCFGR_CFEN) ||
146-
FIELD_GET(RIFSC_RISC_SCID_MASK, cid_reg_value) == RIF_CID0)
147-
goto skip_cid_check;
148-
149-
/* Coherency check with the CID configuration */
150-
if (FIELD_GET(RIFSC_RISC_SCID_MASK, cid_reg_value) != RIF_CID1) {
151-
dev_dbg(rifsc_controller->dev, "Invalid CID configuration for peripheral: %d\n",
152-
firewall_id);
153-
return -EACCES;
154-
}
155-
156-
skip_cid_check:
157129
/* Check security configuration */
158130
if (sec_reg_value & BIT(reg_offset)) {
159131
dev_dbg(rifsc_controller->dev,
160132
"Invalid security configuration for peripheral: %d\n", firewall_id);
161133
return -EACCES;
162134
}
163135

164-
/*
165-
* If the peripheral is in semaphore mode, take the semaphore so that
166-
* the CID1 has the ownership.
167-
*/
168-
if ((cid_reg_value & CIDCFGR_SEMEN) && (cid_reg_value & CIDCFGR_CFEN)) {
136+
/* Skip CID check if CID filtering isn't enabled */
137+
if (!(cid_reg_value & CIDCFGR_CFEN))
138+
goto skip_cid_check;
139+
140+
/* First check conditions for semaphore mode, which doesn't take into account static CID. */
141+
if (cid_reg_value & CIDCFGR_SEMEN) {
142+
if (!(cid_reg_value & BIT(RIF_CID1 + SEMWL_SHIFT))) {
143+
dev_dbg(rifsc_controller->dev,
144+
"Invalid bus semaphore configuration: index %d\n", firewall_id);
145+
return -EACCES;
146+
}
147+
169148
rc = stm32_rif_acquire_semaphore(rifsc_controller, firewall_id);
170149
if (rc) {
171-
dev_err(rifsc_controller->dev,
150+
dev_dbg(rifsc_controller->dev,
172151
"Couldn't acquire semaphore for peripheral: %d\n", firewall_id);
173152
return rc;
174153
}
154+
} else if (FIELD_GET(RIFSC_RISC_SCID_MASK, cid_reg_value) != RIF_CID1) {
155+
dev_dbg(rifsc_controller->dev, "Invalid CID configuration for peripheral: %d\n",
156+
firewall_id);
157+
return -EACCES;
175158
}
176159

160+
skip_cid_check:
177161
return 0;
178162
}
179163

0 commit comments

Comments
 (0)