linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rpmsg: smd: do not use mananged resources for endpoints and channels
@ 2018-06-01 23:32 Srinivas Kandagatla
  2018-06-04  0:49 ` Bjorn Andersson
  0 siblings, 1 reply; 3+ messages in thread
From: Srinivas Kandagatla @ 2018-06-01 23:32 UTC (permalink / raw)
  To: ohad, bjorn.andersson
  Cc: linux-remoteproc, linux-arm-msm, bgoswami, linux-kernel,
	rohkumar, Srinivas Kandagatla, stable

All the managed resources would be freed by the time release function
is invoked. Handling such memory in qcom_smd_edge_release() would do
bad things.

Found this issue while testing Audio usecase where the dsp is started up
and shutdown in a loop.

This patch fixes this issue by using simple kzalloc for allocating
channel->name and channel which is then freed in qcom_smd_edge_release().

Without this patch restarting a remoteproc would crash the system.
Fixes: 53e2822e56c7 ("rpmsg: Introduce Qualcomm SMD backend")
Cc: <stable@vger.kernel.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 drivers/rpmsg/qcom_smd.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/drivers/rpmsg/qcom_smd.c b/drivers/rpmsg/qcom_smd.c
index 5ce9bf7b897d..49d3838dfc3d 100644
--- a/drivers/rpmsg/qcom_smd.c
+++ b/drivers/rpmsg/qcom_smd.c
@@ -1100,12 +1100,12 @@ static struct qcom_smd_channel *qcom_smd_create_channel(struct qcom_smd_edge *ed
 	void *info;
 	int ret;
 
-	channel = devm_kzalloc(&edge->dev, sizeof(*channel), GFP_KERNEL);
+	channel = kzalloc(sizeof(*channel), GFP_KERNEL);
 	if (!channel)
 		return ERR_PTR(-ENOMEM);
 
 	channel->edge = edge;
-	channel->name = devm_kstrdup(&edge->dev, name, GFP_KERNEL);
+	channel->name = kstrdup(name, GFP_KERNEL);
 	if (!channel->name)
 		return ERR_PTR(-ENOMEM);
 
@@ -1156,8 +1156,8 @@ static struct qcom_smd_channel *qcom_smd_create_channel(struct qcom_smd_edge *ed
 	return channel;
 
 free_name_and_channel:
-	devm_kfree(&edge->dev, channel->name);
-	devm_kfree(&edge->dev, channel);
+	kfree(channel->name);
+	kfree(channel);
 
 	return ERR_PTR(ret);
 }
@@ -1380,11 +1380,13 @@ static void qcom_smd_edge_release(struct device *dev)
 {
 	struct qcom_smd_channel *channel;
 	struct qcom_smd_edge *edge = to_smd_edge(dev);
+	struct list_head *this, *tmp;
 
-	list_for_each_entry(channel, &edge->channels, list) {
-		SET_RX_CHANNEL_INFO(channel, state, SMD_CHANNEL_CLOSED);
-		SET_RX_CHANNEL_INFO(channel, head, 0);
-		SET_RX_CHANNEL_INFO(channel, tail, 0);
+	list_for_each_safe(this, tmp, &edge->channels) {
+		channel = list_entry(this, struct qcom_smd_channel, list);
+		list_del(&channel->list);
+		kfree(channel->name);
+		kfree(channel);
 	}
 
 	kfree(edge);
-- 
2.16.2

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] rpmsg: smd: do not use mananged resources for endpoints and channels
  2018-06-01 23:32 [PATCH] rpmsg: smd: do not use mananged resources for endpoints and channels Srinivas Kandagatla
@ 2018-06-04  0:49 ` Bjorn Andersson
  2018-06-04  9:16   ` Srinivas Kandagatla
  0 siblings, 1 reply; 3+ messages in thread
From: Bjorn Andersson @ 2018-06-04  0:49 UTC (permalink / raw)
  To: Srinivas Kandagatla
  Cc: ohad, linux-remoteproc, linux-arm-msm, bgoswami, linux-kernel,
	rohkumar, stable

On Fri 01 Jun 16:32 PDT 2018, Srinivas Kandagatla wrote:
> @@ -1380,11 +1380,13 @@ static void qcom_smd_edge_release(struct device *dev)
>  {
>  	struct qcom_smd_channel *channel;
>  	struct qcom_smd_edge *edge = to_smd_edge(dev);
> +	struct list_head *this, *tmp;
>  
> -	list_for_each_entry(channel, &edge->channels, list) {
> -		SET_RX_CHANNEL_INFO(channel, state, SMD_CHANNEL_CLOSED);
> -		SET_RX_CHANNEL_INFO(channel, head, 0);
> -		SET_RX_CHANNEL_INFO(channel, tail, 0);
> +	list_for_each_safe(this, tmp, &edge->channels) {
> +		channel = list_entry(this, struct qcom_smd_channel, list);

Is there a reason not to use list_for_each_entry_safe()?

> +		list_del(&channel->list);
> +		kfree(channel->name);
> +		kfree(channel);

Regards,
Bjorn

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] rpmsg: smd: do not use mananged resources for endpoints and channels
  2018-06-04  0:49 ` Bjorn Andersson
@ 2018-06-04  9:16   ` Srinivas Kandagatla
  0 siblings, 0 replies; 3+ messages in thread
From: Srinivas Kandagatla @ 2018-06-04  9:16 UTC (permalink / raw)
  To: Bjorn Andersson
  Cc: ohad, linux-remoteproc, linux-arm-msm, bgoswami, linux-kernel,
	rohkumar, stable



On 04/06/18 01:49, Bjorn Andersson wrote:
> On Fri 01 Jun 16:32 PDT 2018, Srinivas Kandagatla wrote:
>> @@ -1380,11 +1380,13 @@ static void qcom_smd_edge_release(struct device *dev)
>>   {
>>   	struct qcom_smd_channel *channel;
>>   	struct qcom_smd_edge *edge = to_smd_edge(dev);
>> +	struct list_head *this, *tmp;
>>   
>> -	list_for_each_entry(channel, &edge->channels, list) {
>> -		SET_RX_CHANNEL_INFO(channel, state, SMD_CHANNEL_CLOSED);
>> -		SET_RX_CHANNEL_INFO(channel, head, 0);
>> -		SET_RX_CHANNEL_INFO(channel, tail, 0);
>> +	list_for_each_safe(this, tmp, &edge->channels) {
>> +		channel = list_entry(this, struct qcom_smd_channel, list);
> 
> Is there a reason not to use list_for_each_entry_safe()?
> 
No, I will respin the patch with this change.
thanks,
srini
>> +		list_del(&channel->list);
>> +		kfree(channel->name);
>> +		kfree(channel);
> 
> Regards,
> Bjorn
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-06-04  9:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-01 23:32 [PATCH] rpmsg: smd: do not use mananged resources for endpoints and channels Srinivas Kandagatla
2018-06-04  0:49 ` Bjorn Andersson
2018-06-04  9:16   ` Srinivas Kandagatla

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).