coresight: cti: Fix error handling in probe
authorDan Carpenter <dan.carpenter@oracle.com>
Wed, 1 Jul 2020 16:08:51 +0000 (10:08 -0600)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 1 Jul 2020 16:44:07 +0000 (18:44 +0200)
commit6740de9433556d5e3f94c4901dce120d27677be1
tree96826a227507192e29c1ddab3ee0c635c1b9bd64
parent853eab68afc80f59f36bbdeb715e5c88c501e680
coresight: cti: Fix error handling in probe

There were a couple problems with error handling in the probe function:
1)  If the "drvdata" allocation failed then it lead to a NULL
    dereference.
2)  On several error paths we decremented "nr_cti_cpu" before it was
    incremented which lead to a reference counting bug.

There were also some parts of the error handling which were not bugs but
were messy.  The error handling was confusing to read.  It printed some
unnecessary error messages.

The simplest way to fix these problems was to create a cti_pm_setup()
function that did all the power management setup in one go.  That way
when we call cti_pm_release() we don't have to deal with the
complications of a partially configured power management config.

I reversed the "if (drvdata->ctidev.cpu >= 0)" condition in
cti_pm_release() so that it mirros the new cti_pm_setup() function.

Fixes: 6a0953ce7de9 ("coresight: cti: Add CPU idle pm notifer to CTI devices")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Mike Leach <mike.leach@linaro.org>
Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Link: https://lore.kernel.org/r/20200701160852.2782823-2-mathieu.poirier@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/hwtracing/coresight/coresight-cti.c