FROMGIT: 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/1628111999-21595-1-git-send-email-rishabhb@codeaurora.org
Tested-by: Cristian Marussi <cristian.marussi@arm.com>
Reviewed-by: Cristian Marussi <cristian.marussi@arm.com>
Signed-off-by: Rishabh Bhatnagar <rishabhb@codeaurora.org>
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
Bug: 196063834
(cherry picked from commit 1e7cbfaa66
git://git.kernel.org/pub/scm/linux/kernel/git/sudeep.holla/linux.git/ for-next/scmi)
Signed-off-by: Rishabh Bhatnagar <quic_rishabhb@quicinc.com>
Change-Id: I3502b0905dd5e21e6189c125f182fd1fb29eaba8
This commit is contained in:
committed by
Will Deacon
parent
c72ca115a2
commit
e9844a46c9
@@ -1385,6 +1385,21 @@ void scmi_unrequest_protocol_device(const struct scmi_device_id *id_table)
|
||||
mutex_unlock(&scmi_requested_devices_mtx);
|
||||
}
|
||||
|
||||
static int scmi_cleanup_txrx_channels(struct scmi_info *info)
|
||||
{
|
||||
int ret;
|
||||
struct idr *idr = &info->tx_idr;
|
||||
|
||||
ret = idr_for_each(idr, info->desc->ops->chan_free, idr);
|
||||
idr_destroy(&info->tx_idr);
|
||||
|
||||
idr = &info->rx_idr;
|
||||
ret = idr_for_each(idr, info->desc->ops->chan_free, idr);
|
||||
idr_destroy(&info->rx_idr);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int scmi_probe(struct platform_device *pdev)
|
||||
{
|
||||
int ret;
|
||||
@@ -1426,7 +1441,7 @@ static int scmi_probe(struct platform_device *pdev)
|
||||
|
||||
ret = scmi_xfer_info_init(info);
|
||||
if (ret)
|
||||
return ret;
|
||||
goto clear_txrx_setup;
|
||||
|
||||
if (scmi_notification_init(handle))
|
||||
dev_err(dev, "SCMI Notifications NOT available.\n");
|
||||
@@ -1439,7 +1454,7 @@ static int scmi_probe(struct platform_device *pdev)
|
||||
ret = scmi_acquire_protocol(handle, SCMI_PROTOCOL_BASE);
|
||||
if (ret) {
|
||||
dev_err(dev, "unable to communicate with SCMI\n");
|
||||
return ret;
|
||||
goto notification_exit;
|
||||
}
|
||||
|
||||
mutex_lock(&scmi_list_mutex);
|
||||
@@ -1478,6 +1493,12 @@ static int scmi_probe(struct platform_device *pdev)
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
notification_exit:
|
||||
scmi_notification_exit(&info->handle);
|
||||
clear_txrx_setup:
|
||||
scmi_cleanup_txrx_channels(info);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void scmi_free_channel(struct scmi_chan_info *cinfo, struct idr *idr, int id)
|
||||
@@ -1489,7 +1510,6 @@ static int scmi_remove(struct platform_device *pdev)
|
||||
{
|
||||
int ret = 0, id;
|
||||
struct scmi_info *info = platform_get_drvdata(pdev);
|
||||
struct idr *idr = &info->tx_idr;
|
||||
struct device_node *child;
|
||||
|
||||
mutex_lock(&scmi_list_mutex);
|
||||
@@ -1513,14 +1533,7 @@ static int scmi_remove(struct platform_device *pdev)
|
||||
idr_destroy(&info->active_protocols);
|
||||
|
||||
/* Safe to free channels since no more users */
|
||||
ret = idr_for_each(idr, info->desc->ops->chan_free, idr);
|
||||
idr_destroy(&info->tx_idr);
|
||||
|
||||
idr = &info->rx_idr;
|
||||
ret = idr_for_each(idr, info->desc->ops->chan_free, idr);
|
||||
idr_destroy(&info->rx_idr);
|
||||
|
||||
return ret;
|
||||
return scmi_cleanup_txrx_channels(info);
|
||||
}
|
||||
|
||||
static ssize_t protocol_version_show(struct device *dev,
|
||||
|
||||
Reference in New Issue
Block a user