diff mbox series

[v8,17/24] coresight: cti: Fix remove sysfs link error

Message ID 20200807111153.7784-18-tingwei@codeaurora.org (mailing list archive)
State New, archived
Headers show
Series coresight: allow to build coresight as modules | expand

Commit Message

Tingwei Zhang Aug. 7, 2020, 11:11 a.m. UTC
From: Mike Leach <mike.leach@linaro.org>

CTI code to remove sysfs link to other devices on shutdown, incorrectly
tries to remove a single ended link when these are all double ended. This
implementation leaves elements in the link info structure undefined which
results in a crash in recent tests for driver module unload.

This patch corrects the link removal code.

Fixes: 73274abb6557 (coresight: cti: Add in sysfs links to other coresight devices)
Reported-by: Tingwei Zhang <tingwei@codeaurora.org>
Signed-off-by: Mike Leach <mike.leach@linaro.org>
---
 drivers/hwtracing/coresight/coresight-cti.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Comments

Mathieu Poirier Aug. 17, 2020, 4:15 p.m. UTC | #1
On Fri, Aug 07, 2020 at 07:11:46PM +0800, Tingwei Zhang wrote:
> From: Mike Leach <mike.leach@linaro.org>
> 
> CTI code to remove sysfs link to other devices on shutdown, incorrectly
> tries to remove a single ended link when these are all double ended. This
> implementation leaves elements in the link info structure undefined which
> results in a crash in recent tests for driver module unload.
> 
> This patch corrects the link removal code.
> 
> Fixes: 73274abb6557 (coresight: cti: Add in sysfs links to other coresight devices)

This should be:

Fixes: 73274abb6557 ("coresight: cti: Add in sysfs links to other coresight devices")

> Reported-by: Tingwei Zhang <tingwei@codeaurora.org>
> Signed-off-by: Mike Leach <mike.leach@linaro.org>
> ---
>  drivers/hwtracing/coresight/coresight-cti.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/hwtracing/coresight/coresight-cti.c b/drivers/hwtracing/coresight/coresight-cti.c
> index 1f470c47ba70..1c34db7d1b1b 100644
> --- a/drivers/hwtracing/coresight/coresight-cti.c
> +++ b/drivers/hwtracing/coresight/coresight-cti.c
> @@ -511,12 +511,15 @@ static bool cti_add_sysfs_link(struct cti_drvdata *drvdata,
>  	return !link_err;
>  }
>  
> -static void cti_remove_sysfs_link(struct cti_trig_con *tc)
> +static void cti_remove_sysfs_link(struct cti_drvdata *drvdata,
> +				  struct cti_trig_con *tc)
>  {
>  	struct coresight_sysfs_link link_info;
>  
> +	link_info.orig = drvdata->csdev;
>  	link_info.orig_name = tc->con_dev_name;
>  	link_info.target = tc->con_dev;
> +	link_info.target_name = dev_name(&drvdata->csdev->dev);
>  	coresight_remove_sysfs_link(&link_info);
>  }
>  
> @@ -606,7 +609,7 @@ void cti_remove_assoc_from_csdev(struct coresight_device *csdev)
>  		ctidev = &ctidrv->ctidev;
>  		list_for_each_entry(tc, &ctidev->trig_cons, node) {
>  			if (tc->con_dev == csdev->ect_dev) {
> -				cti_remove_sysfs_link(tc);
> +				cti_remove_sysfs_link(ctidrv, tc);
>  				tc->con_dev = NULL;
>  				break;
>  			}
> @@ -658,7 +661,7 @@ static void cti_remove_conn_xrefs(struct cti_drvdata *drvdata)
>  		if (tc->con_dev) {
>  			coresight_set_assoc_ectdev_mutex(tc->con_dev,
>  							 NULL);
> -			cti_remove_sysfs_link(tc);
> +			cti_remove_sysfs_link(drvdata, tc);

With the above:

Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>

>  			tc->con_dev = NULL;
>  		}
>  	}
> -- 
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> a Linux Foundation Collaborative Project
>
Tingwei Zhang Aug. 17, 2020, 10:48 p.m. UTC | #2
On Tue, Aug 18, 2020 at 12:15:31AM +0800, Mathieu Poirier wrote:
> On Fri, Aug 07, 2020 at 07:11:46PM +0800, Tingwei Zhang wrote:
> > From: Mike Leach <mike.leach@linaro.org>
> > 
> > CTI code to remove sysfs link to other devices on shutdown, incorrectly
> > tries to remove a single ended link when these are all double ended.
> This
> > implementation leaves elements in the link info structure undefined
> which
> > results in a crash in recent tests for driver module unload.
> > 
> > This patch corrects the link removal code.
> > 
> > Fixes: 73274abb6557 (coresight: cti: Add in sysfs links to other
> coresight devices)
> 
> This should be:
> 
> Fixes: 73274abb6557 ("coresight: cti: Add in sysfs links to other
> coresight devices")
> 

Sure. I'll put this into v9.

Thanks,
Tingwei
> > Reported-by: Tingwei Zhang <tingwei@codeaurora.org>
> > Signed-off-by: Mike Leach <mike.leach@linaro.org>
> > ---
> >  drivers/hwtracing/coresight/coresight-cti.c | 9 ++++++---
> >  1 file changed, 6 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/hwtracing/coresight/coresight-cti.c
> b/drivers/hwtracing/coresight/coresight-cti.c
> > index 1f470c47ba70..1c34db7d1b1b 100644
> > --- a/drivers/hwtracing/coresight/coresight-cti.c
> > +++ b/drivers/hwtracing/coresight/coresight-cti.c
> > @@ -511,12 +511,15 @@ static bool cti_add_sysfs_link(struct cti_drvdata
> *drvdata,
> >  	return !link_err;
> >  }
> >  
> > -static void cti_remove_sysfs_link(struct cti_trig_con *tc)
> > +static void cti_remove_sysfs_link(struct cti_drvdata *drvdata,
> > +				  struct cti_trig_con *tc)
> >  {
> >  	struct coresight_sysfs_link link_info;
> >  
> > +	link_info.orig = drvdata->csdev;
> >  	link_info.orig_name = tc->con_dev_name;
> >  	link_info.target = tc->con_dev;
> > +	link_info.target_name = dev_name(&drvdata->csdev->dev);
> >  	coresight_remove_sysfs_link(&link_info);
> >  }
> >  
> > @@ -606,7 +609,7 @@ void cti_remove_assoc_from_csdev(struct
> coresight_device *csdev)
> >  		ctidev = &ctidrv->ctidev;
> >  		list_for_each_entry(tc, &ctidev->trig_cons, node) {
> >  			if (tc->con_dev == csdev->ect_dev) {
> > -				cti_remove_sysfs_link(tc);
> > +				cti_remove_sysfs_link(ctidrv, tc);
> >  				tc->con_dev = NULL;
> >  				break;
> >  			}
> > @@ -658,7 +661,7 @@ static void cti_remove_conn_xrefs(struct cti_drvdata
> *drvdata)
> >  		if (tc->con_dev) {
> >  			coresight_set_assoc_ectdev_mutex(tc->con_dev,
> >  							 NULL);
> > -			cti_remove_sysfs_link(tc);
> > +			cti_remove_sysfs_link(drvdata, tc);
> 
> With the above:
> 
> Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>
> 
> >  			tc->con_dev = NULL;
> >  		}
> >  	}
> > -- 
> > The Qualcomm Innovation Center, Inc. is a member of the Code Aurora
> Forum,
> > a Linux Foundation Collaborative Project
> >
diff mbox series

Patch

diff --git a/drivers/hwtracing/coresight/coresight-cti.c b/drivers/hwtracing/coresight/coresight-cti.c
index 1f470c47ba70..1c34db7d1b1b 100644
--- a/drivers/hwtracing/coresight/coresight-cti.c
+++ b/drivers/hwtracing/coresight/coresight-cti.c
@@ -511,12 +511,15 @@  static bool cti_add_sysfs_link(struct cti_drvdata *drvdata,
 	return !link_err;
 }
 
-static void cti_remove_sysfs_link(struct cti_trig_con *tc)
+static void cti_remove_sysfs_link(struct cti_drvdata *drvdata,
+				  struct cti_trig_con *tc)
 {
 	struct coresight_sysfs_link link_info;
 
+	link_info.orig = drvdata->csdev;
 	link_info.orig_name = tc->con_dev_name;
 	link_info.target = tc->con_dev;
+	link_info.target_name = dev_name(&drvdata->csdev->dev);
 	coresight_remove_sysfs_link(&link_info);
 }
 
@@ -606,7 +609,7 @@  void cti_remove_assoc_from_csdev(struct coresight_device *csdev)
 		ctidev = &ctidrv->ctidev;
 		list_for_each_entry(tc, &ctidev->trig_cons, node) {
 			if (tc->con_dev == csdev->ect_dev) {
-				cti_remove_sysfs_link(tc);
+				cti_remove_sysfs_link(ctidrv, tc);
 				tc->con_dev = NULL;
 				break;
 			}
@@ -658,7 +661,7 @@  static void cti_remove_conn_xrefs(struct cti_drvdata *drvdata)
 		if (tc->con_dev) {
 			coresight_set_assoc_ectdev_mutex(tc->con_dev,
 							 NULL);
-			cti_remove_sysfs_link(tc);
+			cti_remove_sysfs_link(drvdata, tc);
 			tc->con_dev = NULL;
 		}
 	}