Skip to content

Commit d2e53ce

Browse files
committed
Merge tag 'scmi-fixes-6.3' of git://git.kernel.org/pub/scm/linux/kernel/git/sudeep.holla/linux into soc/fixes
Arm SCMI fixes for v6.3 Few fixes addressing issues around validation of device tree SCMI node, allowing raw SCMI access even on systems which fail to probe the normal driver stack, duplicate header inclusion, clean up return statement using literal values instead of variable to simplify and use of devm_bitmap_zalloc instead of devm_kcalloc to improve semantic. * tag 'scmi-fixes-6.3' of git://git.kernel.org/pub/scm/linux/kernel/git/sudeep.holla/linux: firmware: arm_scmi: Use the bitmap API to allocate bitmaps firmware: arm_scmi: Fix device node validation for mailbox transport firmware: arm_scmi: Fix raw coexistence mode behaviour on failure path firmware: arm_scmi: Remove duplicate include header inclusion firmware: arm_scmi: Return a literal instead of a variable firmware: arm_scmi: Clean up a return statement in scmi_probe Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnd Bergmann <[email protected]>
2 parents 38557b2 + d617808 commit d2e53ce

File tree

3 files changed

+45
-9
lines changed

3 files changed

+45
-9
lines changed

drivers/firmware/arm_scmi/bus.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include <linux/kernel.h>
1515
#include <linux/slab.h>
1616
#include <linux/device.h>
17-
#include <linux/of.h>
1817

1918
#include "common.h"
2019

@@ -436,7 +435,7 @@ struct scmi_device *scmi_device_create(struct device_node *np,
436435
/* Nothing to do. */
437436
if (!phead) {
438437
mutex_unlock(&scmi_requested_devices_mtx);
439-
return scmi_dev;
438+
return NULL;
440439
}
441440

442441
/* Walk the list of requested devices for protocol and create them */

drivers/firmware/arm_scmi/driver.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2221,8 +2221,8 @@ static int __scmi_xfer_info_init(struct scmi_info *sinfo,
22212221
hash_init(info->pending_xfers);
22222222

22232223
/* Allocate a bitmask sized to hold MSG_TOKEN_MAX tokens */
2224-
info->xfer_alloc_table = devm_kcalloc(dev, BITS_TO_LONGS(MSG_TOKEN_MAX),
2225-
sizeof(long), GFP_KERNEL);
2224+
info->xfer_alloc_table = devm_bitmap_zalloc(dev, MSG_TOKEN_MAX,
2225+
GFP_KERNEL);
22262226
if (!info->xfer_alloc_table)
22272227
return -ENOMEM;
22282228

@@ -2657,6 +2657,7 @@ static int scmi_probe(struct platform_device *pdev)
26572657
struct scmi_handle *handle;
26582658
const struct scmi_desc *desc;
26592659
struct scmi_info *info;
2660+
bool coex = IS_ENABLED(CONFIG_ARM_SCMI_RAW_MODE_SUPPORT_COEX);
26602661
struct device *dev = &pdev->dev;
26612662
struct device_node *child, *np = dev->of_node;
26622663

@@ -2731,16 +2732,13 @@ static int scmi_probe(struct platform_device *pdev)
27312732
dev_warn(dev, "Failed to setup SCMI debugfs.\n");
27322733

27332734
if (IS_ENABLED(CONFIG_ARM_SCMI_RAW_MODE_SUPPORT)) {
2734-
bool coex =
2735-
IS_ENABLED(CONFIG_ARM_SCMI_RAW_MODE_SUPPORT_COEX);
2736-
27372735
ret = scmi_debugfs_raw_mode_setup(info);
27382736
if (!coex) {
27392737
if (ret)
27402738
goto clear_dev_req_notifier;
27412739

2742-
/* Bail out anyway when coex enabled */
2743-
return ret;
2740+
/* Bail out anyway when coex disabled. */
2741+
return 0;
27442742
}
27452743

27462744
/* Coex enabled, carry on in any case. */
@@ -2764,6 +2762,8 @@ static int scmi_probe(struct platform_device *pdev)
27642762
ret = scmi_protocol_acquire(handle, SCMI_PROTOCOL_BASE);
27652763
if (ret) {
27662764
dev_err(dev, "unable to communicate with SCMI\n");
2765+
if (coex)
2766+
return 0;
27672767
goto notification_exit;
27682768
}
27692769

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)