coresight: Use local coresight_desc instances
authorSuzuki K Poulose <suzuki.poulose@arm.com>
Thu, 25 Aug 2016 21:19:05 +0000 (15:19 -0600)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 31 Aug 2016 11:05:43 +0000 (13:05 +0200)
Each coresight device prepares a description for coresight_register()
in struct coresight_desc. Once we register the device, the description is
useless and can be freed. The coresight_desc is small enough (48bytes on
64bit)i to be allocated on the stack. Hence use an automatic variable to
avoid a needless dynamic allocation and wasting the memory(which will only
be free'd when the device is destroyed).

Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Pratik Patel <pratikp@codeaurora.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>
drivers/hwtracing/coresight/coresight-etb10.c
drivers/hwtracing/coresight/coresight-etm3x.c
drivers/hwtracing/coresight/coresight-etm4x.c
drivers/hwtracing/coresight/coresight-funnel.c
drivers/hwtracing/coresight/coresight-replicator-qcom.c
drivers/hwtracing/coresight/coresight-replicator.c
drivers/hwtracing/coresight/coresight-stm.c
drivers/hwtracing/coresight/coresight-tmc.c
drivers/hwtracing/coresight/coresight-tpiu.c

index 3b483e3f00eeb87a58675479b073274723e5c459..8a4927ca9181c334881616e16dd5a8f761c5a904 100644 (file)
@@ -636,7 +636,7 @@ static int etb_probe(struct amba_device *adev, const struct amba_id *id)
        struct coresight_platform_data *pdata = NULL;
        struct etb_drvdata *drvdata;
        struct resource *res = &adev->res;
-       struct coresight_desc *desc;
+       struct coresight_desc desc = { 0 };
        struct device_node *np = adev->dev.of_node;
 
        if (np) {
@@ -682,17 +682,13 @@ static int etb_probe(struct amba_device *adev, const struct amba_id *id)
                return -ENOMEM;
        }
 
-       desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL);
-       if (!desc)
-               return -ENOMEM;
-
-       desc->type = CORESIGHT_DEV_TYPE_SINK;
-       desc->subtype.sink_subtype = CORESIGHT_DEV_SUBTYPE_SINK_BUFFER;
-       desc->ops = &etb_cs_ops;
-       desc->pdata = pdata;
-       desc->dev = dev;
-       desc->groups = coresight_etb_groups;
-       drvdata->csdev = coresight_register(desc);
+       desc.type = CORESIGHT_DEV_TYPE_SINK;
+       desc.subtype.sink_subtype = CORESIGHT_DEV_SUBTYPE_SINK_BUFFER;
+       desc.ops = &etb_cs_ops;
+       desc.pdata = pdata;
+       desc.dev = dev;
+       desc.groups = coresight_etb_groups;
+       drvdata->csdev = coresight_register(&desc);
        if (IS_ERR(drvdata->csdev))
                return PTR_ERR(drvdata->csdev);
 
index b4f380a9da5c5f362bdf78a864fcb62484342f71..326afe49251ab57d52ba2b5f4c81604fca861f63 100644 (file)
@@ -756,13 +756,9 @@ static int etm_probe(struct amba_device *adev, const struct amba_id *id)
        struct coresight_platform_data *pdata = NULL;
        struct etm_drvdata *drvdata;
        struct resource *res = &adev->res;
-       struct coresight_desc *desc;
+       struct coresight_desc desc = { 0 };
        struct device_node *np = adev->dev.of_node;
 
-       desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL);
-       if (!desc)
-               return -ENOMEM;
-
        drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
        if (!drvdata)
                return -ENOMEM;
@@ -825,13 +821,13 @@ static int etm_probe(struct amba_device *adev, const struct amba_id *id)
        etm_init_trace_id(drvdata);
        etm_set_default(&drvdata->config);
 
-       desc->type = CORESIGHT_DEV_TYPE_SOURCE;
-       desc->subtype.source_subtype = CORESIGHT_DEV_SUBTYPE_SOURCE_PROC;
-       desc->ops = &etm_cs_ops;
-       desc->pdata = pdata;
-       desc->dev = dev;
-       desc->groups = coresight_etm_groups;
-       drvdata->csdev = coresight_register(desc);
+       desc.type = CORESIGHT_DEV_TYPE_SOURCE;
+       desc.subtype.source_subtype = CORESIGHT_DEV_SUBTYPE_SOURCE_PROC;
+       desc.ops = &etm_cs_ops;
+       desc.pdata = pdata;
+       desc.dev = dev;
+       desc.groups = coresight_etm_groups;
+       drvdata->csdev = coresight_register(&desc);
        if (IS_ERR(drvdata->csdev)) {
                ret = PTR_ERR(drvdata->csdev);
                goto err_arch_supported;
index 3b16f8a9e44d885b8562f310aa87fa6a4d68e49a..d8721fb8da9903d1b7a448f23782d89880e1ce3b 100644 (file)
@@ -711,13 +711,9 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id)
        struct coresight_platform_data *pdata = NULL;
        struct etmv4_drvdata *drvdata;
        struct resource *res = &adev->res;
-       struct coresight_desc *desc;
+       struct coresight_desc desc = { 0 };
        struct device_node *np = adev->dev.of_node;
 
-       desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL);
-       if (!desc)
-               return -ENOMEM;
-
        drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
        if (!drvdata)
                return -ENOMEM;
@@ -772,13 +768,13 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id)
        etm4_init_trace_id(drvdata);
        etm4_set_default(&drvdata->config);
 
-       desc->type = CORESIGHT_DEV_TYPE_SOURCE;
-       desc->subtype.source_subtype = CORESIGHT_DEV_SUBTYPE_SOURCE_PROC;
-       desc->ops = &etm4_cs_ops;
-       desc->pdata = pdata;
-       desc->dev = dev;
-       desc->groups = coresight_etmv4_groups;
-       drvdata->csdev = coresight_register(desc);
+       desc.type = CORESIGHT_DEV_TYPE_SOURCE;
+       desc.subtype.source_subtype = CORESIGHT_DEV_SUBTYPE_SOURCE_PROC;
+       desc.ops = &etm4_cs_ops;
+       desc.pdata = pdata;
+       desc.dev = dev;
+       desc.groups = coresight_etmv4_groups;
+       drvdata->csdev = coresight_register(&desc);
        if (IS_ERR(drvdata->csdev)) {
                ret = PTR_ERR(drvdata->csdev);
                goto err_arch_supported;
index 05df789056ccfc823a103d3bc070bef1eaf46d85..860fe6ef563244295557f3b2364af4a0803fbabc 100644 (file)
@@ -176,7 +176,7 @@ static int funnel_probe(struct amba_device *adev, const struct amba_id *id)
        struct coresight_platform_data *pdata = NULL;
        struct funnel_drvdata *drvdata;
        struct resource *res = &adev->res;
-       struct coresight_desc *desc;
+       struct coresight_desc desc = { 0 };
        struct device_node *np = adev->dev.of_node;
 
        if (np) {
@@ -207,17 +207,13 @@ static int funnel_probe(struct amba_device *adev, const struct amba_id *id)
        drvdata->base = base;
        pm_runtime_put(&adev->dev);
 
-       desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL);
-       if (!desc)
-               return -ENOMEM;
-
-       desc->type = CORESIGHT_DEV_TYPE_LINK;
-       desc->subtype.link_subtype = CORESIGHT_DEV_SUBTYPE_LINK_MERG;
-       desc->ops = &funnel_cs_ops;
-       desc->pdata = pdata;
-       desc->dev = dev;
-       desc->groups = coresight_funnel_groups;
-       drvdata->csdev = coresight_register(desc);
+       desc.type = CORESIGHT_DEV_TYPE_LINK;
+       desc.subtype.link_subtype = CORESIGHT_DEV_SUBTYPE_LINK_MERG;
+       desc.ops = &funnel_cs_ops;
+       desc.pdata = pdata;
+       desc.dev = dev;
+       desc.groups = coresight_funnel_groups;
+       drvdata->csdev = coresight_register(&desc);
        if (IS_ERR(drvdata->csdev))
                return PTR_ERR(drvdata->csdev);
 
index 700f710e4bfa6cc4449d04b2842eaf377f3b9368..0a3d15f0b009b3f5fa97a861854dd66bb46e62bd 100644 (file)
@@ -102,7 +102,7 @@ static int replicator_probe(struct amba_device *adev, const struct amba_id *id)
        struct resource *res = &adev->res;
        struct coresight_platform_data *pdata = NULL;
        struct replicator_state *drvdata;
-       struct coresight_desc *desc;
+       struct coresight_desc desc = { 0 };
        struct device_node *np = adev->dev.of_node;
        void __iomem *base;
 
@@ -134,16 +134,12 @@ static int replicator_probe(struct amba_device *adev, const struct amba_id *id)
        dev_set_drvdata(dev, drvdata);
        pm_runtime_put(&adev->dev);
 
-       desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL);
-       if (!desc)
-               return -ENOMEM;
-
-       desc->type = CORESIGHT_DEV_TYPE_LINK;
-       desc->subtype.link_subtype = CORESIGHT_DEV_SUBTYPE_LINK_SPLIT;
-       desc->ops = &replicator_cs_ops;
-       desc->pdata = adev->dev.platform_data;
-       desc->dev = &adev->dev;
-       drvdata->csdev = coresight_register(desc);
+       desc.type = CORESIGHT_DEV_TYPE_LINK;
+       desc.subtype.link_subtype = CORESIGHT_DEV_SUBTYPE_LINK_SPLIT;
+       desc.ops = &replicator_cs_ops;
+       desc.pdata = adev->dev.platform_data;
+       desc.dev = &adev->dev;
+       drvdata->csdev = coresight_register(&desc);
        if (IS_ERR(drvdata->csdev))
                return PTR_ERR(drvdata->csdev);
 
index c6982e312e156892eda2126ad061d23a73522939..3756e71cb8f56d604097d6ddfdfac9e9bbf3aebf 100644 (file)
@@ -69,7 +69,7 @@ static int replicator_probe(struct platform_device *pdev)
        struct device *dev = &pdev->dev;
        struct coresight_platform_data *pdata = NULL;
        struct replicator_drvdata *drvdata;
-       struct coresight_desc *desc;
+       struct coresight_desc desc = { 0 };
        struct device_node *np = pdev->dev.of_node;
 
        if (np) {
@@ -95,18 +95,12 @@ static int replicator_probe(struct platform_device *pdev)
        pm_runtime_enable(&pdev->dev);
        platform_set_drvdata(pdev, drvdata);
 
-       desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL);
-       if (!desc) {
-               ret = -ENOMEM;
-               goto out_disable_pm;
-       }
-
-       desc->type = CORESIGHT_DEV_TYPE_LINK;
-       desc->subtype.link_subtype = CORESIGHT_DEV_SUBTYPE_LINK_SPLIT;
-       desc->ops = &replicator_cs_ops;
-       desc->pdata = pdev->dev.platform_data;
-       desc->dev = &pdev->dev;
-       drvdata->csdev = coresight_register(desc);
+       desc.type = CORESIGHT_DEV_TYPE_LINK;
+       desc.subtype.link_subtype = CORESIGHT_DEV_SUBTYPE_LINK_SPLIT;
+       desc.ops = &replicator_cs_ops;
+       desc.pdata = pdev->dev.platform_data;
+       desc.dev = &pdev->dev;
+       drvdata->csdev = coresight_register(&desc);
        if (IS_ERR(drvdata->csdev)) {
                ret = PTR_ERR(drvdata->csdev);
                goto out_disable_pm;
index 482c8bb27f87b3ce5e8c9e72f717ff825ee1acb4..819629aed2f7d2a362e9437fd9de9b471154b108 100644 (file)
@@ -799,7 +799,7 @@ static int stm_probe(struct amba_device *adev, const struct amba_id *id)
        struct resource *res = &adev->res;
        struct resource ch_res;
        size_t res_size, bitmap_size;
-       struct coresight_desc *desc;
+       struct coresight_desc desc = { 0 };
        struct device_node *np = adev->dev.of_node;
 
        if (np) {
@@ -865,19 +865,13 @@ static int stm_probe(struct amba_device *adev, const struct amba_id *id)
                return -EPROBE_DEFER;
        }
 
-       desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL);
-       if (!desc) {
-               ret = -ENOMEM;
-               goto stm_unregister;
-       }
-
-       desc->type = CORESIGHT_DEV_TYPE_SOURCE;
-       desc->subtype.source_subtype = CORESIGHT_DEV_SUBTYPE_SOURCE_SOFTWARE;
-       desc->ops = &stm_cs_ops;
-       desc->pdata = pdata;
-       desc->dev = dev;
-       desc->groups = coresight_stm_groups;
-       drvdata->csdev = coresight_register(desc);
+       desc.type = CORESIGHT_DEV_TYPE_SOURCE;
+       desc.subtype.source_subtype = CORESIGHT_DEV_SUBTYPE_SOURCE_SOFTWARE;
+       desc.ops = &stm_cs_ops;
+       desc.pdata = pdata;
+       desc.dev = dev;
+       desc.groups = coresight_stm_groups;
+       drvdata->csdev = coresight_register(&desc);
        if (IS_ERR(drvdata->csdev)) {
                ret = PTR_ERR(drvdata->csdev);
                goto stm_unregister;
index 84052c72462ca3cbd37979897e2425179f7f03cd..4cbcaf93c9d999082d779db1bec499298bdc1061 100644 (file)
@@ -302,7 +302,7 @@ static int tmc_probe(struct amba_device *adev, const struct amba_id *id)
        struct coresight_platform_data *pdata = NULL;
        struct tmc_drvdata *drvdata;
        struct resource *res = &adev->res;
-       struct coresight_desc *desc;
+       struct coresight_desc desc = { 0 };
        struct device_node *np = adev->dev.of_node;
 
        if (np) {
@@ -319,10 +319,6 @@ static int tmc_probe(struct amba_device *adev, const struct amba_id *id)
        if (!drvdata)
                goto out;
 
-       desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL);
-       if (!desc)
-               goto out;
-
        drvdata->dev = &adev->dev;
        dev_set_drvdata(dev, drvdata);
 
@@ -354,24 +350,25 @@ static int tmc_probe(struct amba_device *adev, const struct amba_id *id)
 
        pm_runtime_put(&adev->dev);
 
-       desc->pdata = pdata;
-       desc->dev = dev;
-       desc->subtype.sink_subtype = CORESIGHT_DEV_SUBTYPE_SINK_BUFFER;
-       desc->groups = coresight_tmc_groups;
+       desc.pdata = pdata;
+       desc.dev = dev;
+       desc.groups = coresight_tmc_groups;
 
        if (drvdata->config_type == TMC_CONFIG_TYPE_ETB) {
-               desc->type = CORESIGHT_DEV_TYPE_SINK;
-               desc->ops = &tmc_etb_cs_ops;
+               desc.type = CORESIGHT_DEV_TYPE_SINK;
+               desc.subtype.sink_subtype = CORESIGHT_DEV_SUBTYPE_SINK_BUFFER;
+               desc.ops = &tmc_etb_cs_ops;
        } else if (drvdata->config_type == TMC_CONFIG_TYPE_ETR) {
-               desc->type = CORESIGHT_DEV_TYPE_SINK;
-               desc->ops = &tmc_etr_cs_ops;
+               desc.type = CORESIGHT_DEV_TYPE_SINK;
+               desc.subtype.sink_subtype = CORESIGHT_DEV_SUBTYPE_SINK_BUFFER;
+               desc.ops = &tmc_etr_cs_ops;
        } else {
-               desc->type = CORESIGHT_DEV_TYPE_LINKSINK;
-               desc->subtype.link_subtype = CORESIGHT_DEV_SUBTYPE_LINK_FIFO;
-               desc->ops = &tmc_etf_cs_ops;
+               desc.type = CORESIGHT_DEV_TYPE_LINKSINK;
+               desc.subtype.link_subtype = CORESIGHT_DEV_SUBTYPE_LINK_FIFO;
+               desc.ops = &tmc_etf_cs_ops;
        }
 
-       drvdata->csdev = coresight_register(desc);
+       drvdata->csdev = coresight_register(&desc);
        if (IS_ERR(drvdata->csdev)) {
                ret = PTR_ERR(drvdata->csdev);
                goto out;
index 4e471e2e9d896df24399c9e02cdd06a463ac27be..0673baf0f2f5b93bbe9c14c2a7c9a7d390f338b7 100644 (file)
@@ -119,7 +119,7 @@ static int tpiu_probe(struct amba_device *adev, const struct amba_id *id)
        struct coresight_platform_data *pdata = NULL;
        struct tpiu_drvdata *drvdata;
        struct resource *res = &adev->res;
-       struct coresight_desc *desc;
+       struct coresight_desc desc = { 0 };
        struct device_node *np = adev->dev.of_node;
 
        if (np) {
@@ -154,16 +154,12 @@ static int tpiu_probe(struct amba_device *adev, const struct amba_id *id)
 
        pm_runtime_put(&adev->dev);
 
-       desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL);
-       if (!desc)
-               return -ENOMEM;
-
-       desc->type = CORESIGHT_DEV_TYPE_SINK;
-       desc->subtype.sink_subtype = CORESIGHT_DEV_SUBTYPE_SINK_PORT;
-       desc->ops = &tpiu_cs_ops;
-       desc->pdata = pdata;
-       desc->dev = dev;
-       drvdata->csdev = coresight_register(desc);
+       desc.type = CORESIGHT_DEV_TYPE_SINK;
+       desc.subtype.sink_subtype = CORESIGHT_DEV_SUBTYPE_SINK_PORT;
+       desc.ops = &tpiu_cs_ops;
+       desc.pdata = pdata;
+       desc.dev = dev;
+       drvdata->csdev = coresight_register(&desc);
        if (IS_ERR(drvdata->csdev))
                return PTR_ERR(drvdata->csdev);