Skip to content

Commit 2ab4f40

Browse files
cris-masudeep-holla
authored andcommitted
firmware: arm_scmi: Fix device node validation for mailbox transport
When mailboxes are used as a transport it is possible to setup the SCMI transport layer, depending on the underlying channels configuration, to use one or two mailboxes, associated, respectively, to one or two, distinct, shared memory areas: any other combination should be treated as invalid. Add more strict checking of SCMI mailbox transport device node descriptors. Fixes: 5c8a47a ("firmware: arm_scmi: Make scmi core independent of the transport type") Cc: <[email protected]> # 4.19 Signed-off-by: Cristian Marussi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sudeep Holla <[email protected]>
1 parent b2b76e9 commit 2ab4f40

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

drivers/firmware/arm_scmi/mailbox.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,39 @@ static bool mailbox_chan_available(struct device_node *of_node, int idx)
5252
"#mbox-cells", idx, NULL);
5353
}
5454

55+
static int mailbox_chan_validate(struct device *cdev)
56+
{
57+
int num_mb, num_sh, ret = 0;
58+
struct device_node *np = cdev->of_node;
59+
60+
num_mb = of_count_phandle_with_args(np, "mboxes", "#mbox-cells");
61+
num_sh = of_count_phandle_with_args(np, "shmem", NULL);
62+
/* Bail out if mboxes and shmem descriptors are inconsistent */
63+
if (num_mb <= 0 || num_sh > 2 || num_mb != num_sh) {
64+
dev_warn(cdev, "Invalid channel descriptor for '%s'\n",
65+
of_node_full_name(np));
66+
return -EINVAL;
67+
}
68+
69+
if (num_sh > 1) {
70+
struct device_node *np_tx, *np_rx;
71+
72+
np_tx = of_parse_phandle(np, "shmem", 0);
73+
np_rx = of_parse_phandle(np, "shmem", 1);
74+
/* SCMI Tx and Rx shared mem areas have to be distinct */
75+
if (!np_tx || !np_rx || np_tx == np_rx) {
76+
dev_warn(cdev, "Invalid shmem descriptor for '%s'\n",
77+
of_node_full_name(np));
78+
ret = -EINVAL;
79+
}
80+
81+
of_node_put(np_tx);
82+
of_node_put(np_rx);
83+
}
84+
85+
return ret;
86+
}
87+
5588
static int mailbox_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
5689
bool tx)
5790
{
@@ -64,6 +97,10 @@ static int mailbox_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
6497
resource_size_t size;
6598
struct resource res;
6699

100+
ret = mailbox_chan_validate(cdev);
101+
if (ret)
102+
return ret;
103+
67104
smbox = devm_kzalloc(dev, sizeof(*smbox), GFP_KERNEL);
68105
if (!smbox)
69106
return -ENOMEM;

0 commit comments

Comments
 (0)