diff options
author | Suzuki K Poulose <suzuki.poulose@arm.com> | 2016-08-25 17:18:56 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2016-08-31 07:05:42 -0400 |
commit | 068c0a542f6edce90f7d8a9b35a849d990001018 (patch) | |
tree | 9f23c54f2fc784593a2f17e053151c199169a481 /drivers/hwtracing | |
parent | 3afd0634a2aca32466617b3bc1075c127f75d776 (diff) |
coresight: Fix csdev connections initialisation
This is a cleanup patch.
coresight_device->conns holds an array to point to the devices
connected to the OUT ports of a component. Sinks, e.g ETR, do not
have an OUT port (nr_outport = 0), as it streams the trace to
memory via AXI.
At coresight_register() we do :
conns = kcalloc(csdev->nr_outport, sizeof(*conns), GFP_KERNEL);
if (!conns) {
ret = -ENOMEM;
goto err_kzalloc_conns;
}
For ETR, since the total size requested for kcalloc is zero, the return
value is, ZERO_SIZE_PTR ( != NULL). Hence, csdev->conns = ZERO_SIZE_PTR
which cannot be verified later to contain a valid pointer. The code which
accesses the csdev->conns is bounded by the csdev->nr_outport check,
hence we don't try to dereference the ZERO_SIZE_PTR. This patch cleans
up the csdev->conns initialisation to make sure we initialise it
properly(i.e, either NULL or valid conns array).
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/hwtracing')
-rw-r--r-- | drivers/hwtracing/coresight/coresight.c | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c index ceeaaea41ed6..bb20ee9747e1 100644 --- a/drivers/hwtracing/coresight/coresight.c +++ b/drivers/hwtracing/coresight/coresight.c | |||
@@ -894,7 +894,7 @@ struct coresight_device *coresight_register(struct coresight_desc *desc) | |||
894 | int nr_refcnts = 1; | 894 | int nr_refcnts = 1; |
895 | atomic_t *refcnts = NULL; | 895 | atomic_t *refcnts = NULL; |
896 | struct coresight_device *csdev; | 896 | struct coresight_device *csdev; |
897 | struct coresight_connection *conns; | 897 | struct coresight_connection *conns = NULL; |
898 | 898 | ||
899 | csdev = kzalloc(sizeof(*csdev), GFP_KERNEL); | 899 | csdev = kzalloc(sizeof(*csdev), GFP_KERNEL); |
900 | if (!csdev) { | 900 | if (!csdev) { |
@@ -922,16 +922,20 @@ struct coresight_device *coresight_register(struct coresight_desc *desc) | |||
922 | 922 | ||
923 | csdev->nr_inport = desc->pdata->nr_inport; | 923 | csdev->nr_inport = desc->pdata->nr_inport; |
924 | csdev->nr_outport = desc->pdata->nr_outport; | 924 | csdev->nr_outport = desc->pdata->nr_outport; |
925 | conns = kcalloc(csdev->nr_outport, sizeof(*conns), GFP_KERNEL); | ||
926 | if (!conns) { | ||
927 | ret = -ENOMEM; | ||
928 | goto err_kzalloc_conns; | ||
929 | } | ||
930 | 925 | ||
931 | for (i = 0; i < csdev->nr_outport; i++) { | 926 | /* Initialise connections if there is at least one outport */ |
932 | conns[i].outport = desc->pdata->outports[i]; | 927 | if (csdev->nr_outport) { |
933 | conns[i].child_name = desc->pdata->child_names[i]; | 928 | conns = kcalloc(csdev->nr_outport, sizeof(*conns), GFP_KERNEL); |
934 | conns[i].child_port = desc->pdata->child_ports[i]; | 929 | if (!conns) { |
930 | ret = -ENOMEM; | ||
931 | goto err_kzalloc_conns; | ||
932 | } | ||
933 | |||
934 | for (i = 0; i < csdev->nr_outport; i++) { | ||
935 | conns[i].outport = desc->pdata->outports[i]; | ||
936 | conns[i].child_name = desc->pdata->child_names[i]; | ||
937 | conns[i].child_port = desc->pdata->child_ports[i]; | ||
938 | } | ||
935 | } | 939 | } |
936 | 940 | ||
937 | csdev->conns = conns; | 941 | csdev->conns = conns; |