diff mbox series

[1/2] coresight: etm3x: Smatch: Fix potential NULL pointer dereference

Message ID 1560420386-4239-1-git-send-email-suzuki.poulose@arm.com (mailing list archive)
State Mainlined
Commit 020601622323d02e09cebe05e7976b3d4b44e05d
Headers show
Series [1/2] coresight: etm3x: Smatch: Fix potential NULL pointer dereference | expand

Commit Message

Suzuki K Poulose June 13, 2019, 10:06 a.m. UTC
Based on the following report from  Smatch tool, make sure we have a
valid drvdata before we dereference it to find the real dev.

The patch 21d26b905c05: "coresight: etm: Clean up device specific
data" from May 22, 2019, leads to the following Smatch complaint:

    ./drivers/hwtracing/coresight/coresight-etm3x.c:460 etm_get_trace_id()
    warn: variable dereferenced before check 'drvdata' (see line 458)

./drivers/hwtracing/coresight/coresight-etm3x.c
   457		int trace_id = -1;
   458		struct device *etm_dev = drvdata->csdev->dev.parent;
                                         ^^^^^^^^^
New dereference

   459
   460		if (!drvdata)
                    ^^^^^^^^
Checked too late.  Delete the check?

   461			goto out;
   462

Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
 drivers/hwtracing/coresight/coresight-etm3x.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Mathieu Poirier June 17, 2019, 7:28 p.m. UTC | #1
On Thu, 13 Jun 2019 at 04:06, Suzuki K Poulose <suzuki.poulose@arm.com> wrote:
>
> Based on the following report from  Smatch tool, make sure we have a
> valid drvdata before we dereference it to find the real dev.
>
> The patch 21d26b905c05: "coresight: etm: Clean up device specific
> data" from May 22, 2019, leads to the following Smatch complaint:
>
>     ./drivers/hwtracing/coresight/coresight-etm3x.c:460 etm_get_trace_id()
>     warn: variable dereferenced before check 'drvdata' (see line 458)
>
> ./drivers/hwtracing/coresight/coresight-etm3x.c
>    457          int trace_id = -1;
>    458          struct device *etm_dev = drvdata->csdev->dev.parent;
>                                          ^^^^^^^^^
> New dereference
>
>    459
>    460          if (!drvdata)
>                     ^^^^^^^^
> Checked too late.  Delete the check?
>
>    461                  goto out;
>    462
>
> Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> Cc: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> ---
>  drivers/hwtracing/coresight/coresight-etm3x.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/hwtracing/coresight/coresight-etm3x.c b/drivers/hwtracing/coresight/coresight-etm3x.c
> index bed7291..225c298 100644
> --- a/drivers/hwtracing/coresight/coresight-etm3x.c
> +++ b/drivers/hwtracing/coresight/coresight-etm3x.c
> @@ -455,11 +455,12 @@ int etm_get_trace_id(struct etm_drvdata *drvdata)
>  {
>         unsigned long flags;
>         int trace_id = -1;
> -       struct device *etm_dev = drvdata->csdev->dev.parent;
> +       struct device *etm_dev;
>
>         if (!drvdata)
>                 goto out;
>
> +       etm_dev = drvdata->csdev->dev.parent;
>         if (!local_read(&drvdata->mode))
>                 return drvdata->traceid;
>

I have applied both patches in this set.

Thanks,
Mathieu

> --
> 2.7.4
>
diff mbox series

Patch

diff --git a/drivers/hwtracing/coresight/coresight-etm3x.c b/drivers/hwtracing/coresight/coresight-etm3x.c
index bed7291..225c298 100644
--- a/drivers/hwtracing/coresight/coresight-etm3x.c
+++ b/drivers/hwtracing/coresight/coresight-etm3x.c
@@ -455,11 +455,12 @@  int etm_get_trace_id(struct etm_drvdata *drvdata)
 {
 	unsigned long flags;
 	int trace_id = -1;
-	struct device *etm_dev = drvdata->csdev->dev.parent;
+	struct device *etm_dev;
 
 	if (!drvdata)
 		goto out;
 
+	etm_dev = drvdata->csdev->dev.parent;
 	if (!local_read(&drvdata->mode))
 		return drvdata->traceid;