Skip to content

Commit 1e7cbfa

Browse files
Rishabh Bhatnagarsudeep-holla
authored andcommitted
firmware: arm_scmi: Free mailbox channels if probe fails
Mailbox channels for the base protocol are setup during probe. There can be a scenario where probe fails to acquire the base protocol due to a timeout leading to cleaning up of all device managed memory including the scmi_mailbox structure setup during mailbox_chan_setup function. | arm-scmi soc:qcom,scmi: timed out in resp(caller: version_get+0x84/0x140) | arm-scmi soc:qcom,scmi: unable to communicate with SCMI | arm-scmi: probe of soc:qcom,scmi failed with error -110 Now when a message arrives at cpu slightly after the timeout, the mailbox controller will try to call the rx_callback of the client and might end up accessing freed memory. | rx_callback+0x24/0x160 | mbox_chan_received_data+0x44/0x94 | __handle_irq_event_percpu+0xd4/0x240 This patch frees the mailbox channels setup during probe and adds some more error handling in case the probe fails. Link: https://lore.kernel.org/r/[email protected] Tested-by: Cristian Marussi <[email protected]> Reviewed-by: Cristian Marussi <[email protected]> Signed-off-by: Rishabh Bhatnagar <[email protected]> Signed-off-by: Sudeep Holla <[email protected]>
1 parent 46abe13 commit 1e7cbfa

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

drivers/firmware/arm_scmi/driver.c

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,6 +1787,21 @@ void scmi_protocol_device_unrequest(const struct scmi_device_id *id_table)
17871787
mutex_unlock(&scmi_requested_devices_mtx);
17881788
}
17891789

1790+
static int scmi_cleanup_txrx_channels(struct scmi_info *info)
1791+
{
1792+
int ret;
1793+
struct idr *idr = &info->tx_idr;
1794+
1795+
ret = idr_for_each(idr, info->desc->ops->chan_free, idr);
1796+
idr_destroy(&info->tx_idr);
1797+
1798+
idr = &info->rx_idr;
1799+
ret = idr_for_each(idr, info->desc->ops->chan_free, idr);
1800+
idr_destroy(&info->rx_idr);
1801+
1802+
return ret;
1803+
}
1804+
17901805
static int scmi_probe(struct platform_device *pdev)
17911806
{
17921807
int ret;
@@ -1833,7 +1848,7 @@ static int scmi_probe(struct platform_device *pdev)
18331848

18341849
ret = scmi_xfer_info_init(info);
18351850
if (ret)
1836-
return ret;
1851+
goto clear_txrx_setup;
18371852

18381853
if (scmi_notification_init(handle))
18391854
dev_err(dev, "SCMI Notifications NOT available.\n");
@@ -1846,7 +1861,7 @@ static int scmi_probe(struct platform_device *pdev)
18461861
ret = scmi_protocol_acquire(handle, SCMI_PROTOCOL_BASE);
18471862
if (ret) {
18481863
dev_err(dev, "unable to communicate with SCMI\n");
1849-
return ret;
1864+
goto notification_exit;
18501865
}
18511866

18521867
mutex_lock(&scmi_list_mutex);
@@ -1885,6 +1900,12 @@ static int scmi_probe(struct platform_device *pdev)
18851900
}
18861901

18871902
return 0;
1903+
1904+
notification_exit:
1905+
scmi_notification_exit(&info->handle);
1906+
clear_txrx_setup:
1907+
scmi_cleanup_txrx_channels(info);
1908+
return ret;
18881909
}
18891910

18901911
void scmi_free_channel(struct scmi_chan_info *cinfo, struct idr *idr, int id)
@@ -1896,7 +1917,6 @@ static int scmi_remove(struct platform_device *pdev)
18961917
{
18971918
int ret = 0, id;
18981919
struct scmi_info *info = platform_get_drvdata(pdev);
1899-
struct idr *idr = &info->tx_idr;
19001920
struct device_node *child;
19011921

19021922
mutex_lock(&scmi_list_mutex);
@@ -1920,14 +1940,7 @@ static int scmi_remove(struct platform_device *pdev)
19201940
idr_destroy(&info->active_protocols);
19211941

19221942
/* Safe to free channels since no more users */
1923-
ret = idr_for_each(idr, info->desc->ops->chan_free, idr);
1924-
idr_destroy(&info->tx_idr);
1925-
1926-
idr = &info->rx_idr;
1927-
ret = idr_for_each(idr, info->desc->ops->chan_free, idr);
1928-
idr_destroy(&info->rx_idr);
1929-
1930-
return ret;
1943+
return scmi_cleanup_txrx_channels(info);
19311944
}
19321945

19331946
static ssize_t protocol_version_show(struct device *dev,

0 commit comments

Comments
 (0)