diff mbox series

coresight: Don't allocate pdata->conns when there is no output port

Message ID 1599550288-41724-1-git-send-email-liuqi115@huawei.com (mailing list archive)
State New, archived
Headers show
Series coresight: Don't allocate pdata->conns when there is no output port | expand

Commit Message

liuqi (BA) Sept. 8, 2020, 7:31 a.m. UTC
When there is no output port, coresight_alloc_conns() still do the following
copy connection information to pdata->conns, and this may cause kernel panic.
Let's fix it.

Signed-off-by: Qi Liu <liuqi115@huawei.com>
---
 drivers/hwtracing/coresight/coresight-platform.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

--
2.8.1

Comments

Mathieu Poirier Sept. 11, 2020, 5:59 p.m. UTC | #1
Hi Liu,

On Tue, Sep 08, 2020 at 03:31:28PM +0800, Qi Liu wrote:
> When there is no output port, coresight_alloc_conns() still do the following
> copy connection information to pdata->conns, and this may cause kernel panic.
> Let's fix it.

Function coresight_alloc_conns() doesn't copy connection information.  Moreover
sink devices don't have an output port and this code has been stable for years
now.  As such I am suspecting that something else is going wrong...

Can you give more details about the coresight topology you are working with?  An
output of the kernel panic you are seeing would also be much appreciated.

Thanks,
Mathieu

> 
> Signed-off-by: Qi Liu <liuqi115@huawei.com>
> ---
>  drivers/hwtracing/coresight/coresight-platform.c | 13 +++++++------
>  1 file changed, 7 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/hwtracing/coresight/coresight-platform.c b/drivers/hwtracing/coresight/coresight-platform.c
> index bfd4423..cdc8824 100644
> --- a/drivers/hwtracing/coresight/coresight-platform.c
> +++ b/drivers/hwtracing/coresight/coresight-platform.c
> @@ -26,12 +26,13 @@
>  static int coresight_alloc_conns(struct device *dev,
>  				 struct coresight_platform_data *pdata)
>  {
> -	if (pdata->nr_outport) {
> -		pdata->conns = devm_kcalloc(dev, pdata->nr_outport,
> -					    sizeof(*pdata->conns), GFP_KERNEL);
> -		if (!pdata->conns)
> -			return -ENOMEM;
> -	}
> +	if (!pdata->nr_outport)
> +		return -ENOMEM;
> +
> +	pdata->conns = devm_kcalloc(dev, pdata->nr_outport,
> +				    sizeof(*pdata->conns), GFP_KERNEL);
> +	if (!pdata->conns)
> +		return -ENOMEM;
> 
>  	return 0;
>  }
> --
> 2.8.1
>
diff mbox series

Patch

diff --git a/drivers/hwtracing/coresight/coresight-platform.c b/drivers/hwtracing/coresight/coresight-platform.c
index bfd4423..cdc8824 100644
--- a/drivers/hwtracing/coresight/coresight-platform.c
+++ b/drivers/hwtracing/coresight/coresight-platform.c
@@ -26,12 +26,13 @@ 
 static int coresight_alloc_conns(struct device *dev,
 				 struct coresight_platform_data *pdata)
 {
-	if (pdata->nr_outport) {
-		pdata->conns = devm_kcalloc(dev, pdata->nr_outport,
-					    sizeof(*pdata->conns), GFP_KERNEL);
-		if (!pdata->conns)
-			return -ENOMEM;
-	}
+	if (!pdata->nr_outport)
+		return -ENOMEM;
+
+	pdata->conns = devm_kcalloc(dev, pdata->nr_outport,
+				    sizeof(*pdata->conns), GFP_KERNEL);
+	if (!pdata->conns)
+		return -ENOMEM;

 	return 0;
 }