Skip to content

Commit d5ce3b4

Browse files
GseoCAlexandre Torgue
authored andcommitted
bus: rifsc: fix RIF configuration check for peripherals
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>
1 parent a6e1842 commit d5ce3b4

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
@@ -687,54 +687,38 @@ static int stm32_rifsc_grant_access(struct stm32_firewall_controller *ctrl, u32
687687
sec_reg_value = readl(rifsc_controller->mmio + RIFSC_RISC_SECCFGR0 + 0x4 * reg_id);
688688
cid_reg_value = readl(rifsc_controller->mmio + RIFSC_RISC_PER0_CIDCFGR + 0x8 * firewall_id);
689689

690-
/* First check conditions for semaphore mode, which doesn't take into account static CID. */
691-
if ((cid_reg_value & CIDCFGR_SEMEN) && (cid_reg_value & CIDCFGR_CFEN)) {
692-
if (cid_reg_value & BIT(RIF_CID1 + SEMWL_SHIFT)) {
693-
/* Static CID is irrelevant if semaphore mode */
694-
goto skip_cid_check;
695-
} else {
696-
dev_dbg(rifsc_controller->dev,
697-
"Invalid bus semaphore configuration: index %d\n", firewall_id);
698-
return -EACCES;
699-
}
700-
}
701-
702-
/*
703-
* Skip CID check if CID filtering isn't enabled or filtering is enabled on CID0, which
704-
* corresponds to whatever CID.
705-
*/
706-
if (!(cid_reg_value & CIDCFGR_CFEN) ||
707-
FIELD_GET(RIFSC_RISC_SCID_MASK, cid_reg_value) == RIF_CID0)
708-
goto skip_cid_check;
709-
710-
/* Coherency check with the CID configuration */
711-
if (FIELD_GET(RIFSC_RISC_SCID_MASK, cid_reg_value) != RIF_CID1) {
712-
dev_dbg(rifsc_controller->dev, "Invalid CID configuration for peripheral: %d\n",
713-
firewall_id);
714-
return -EACCES;
715-
}
716-
717-
skip_cid_check:
718690
/* Check security configuration */
719691
if (sec_reg_value & BIT(reg_offset)) {
720692
dev_dbg(rifsc_controller->dev,
721693
"Invalid security configuration for peripheral: %d\n", firewall_id);
722694
return -EACCES;
723695
}
724696

725-
/*
726-
* If the peripheral is in semaphore mode, take the semaphore so that
727-
* the CID1 has the ownership.
728-
*/
729-
if ((cid_reg_value & CIDCFGR_SEMEN) && (cid_reg_value & CIDCFGR_CFEN)) {
697+
/* Skip CID check if CID filtering isn't enabled */
698+
if (!(cid_reg_value & CIDCFGR_CFEN))
699+
goto skip_cid_check;
700+
701+
/* First check conditions for semaphore mode, which doesn't take into account static CID. */
702+
if (cid_reg_value & CIDCFGR_SEMEN) {
703+
if (!(cid_reg_value & BIT(RIF_CID1 + SEMWL_SHIFT))) {
704+
dev_dbg(rifsc_controller->dev,
705+
"Invalid bus semaphore configuration: index %d\n", firewall_id);
706+
return -EACCES;
707+
}
708+
730709
rc = stm32_rif_acquire_semaphore(rifsc_controller, firewall_id);
731710
if (rc) {
732-
dev_err(rifsc_controller->dev,
711+
dev_dbg(rifsc_controller->dev,
733712
"Couldn't acquire semaphore for peripheral: %d\n", firewall_id);
734713
return rc;
735714
}
715+
} else if (FIELD_GET(RIFSC_RISC_SCID_MASK, cid_reg_value) != RIF_CID1) {
716+
dev_dbg(rifsc_controller->dev, "Invalid CID configuration for peripheral: %d\n",
717+
firewall_id);
718+
return -EACCES;
736719
}
737720

721+
skip_cid_check:
738722
return 0;
739723
}
740724

0 commit comments

Comments
 (0)