Skip to content

Commit ba6b61f

Browse files
Leo-YanSuzuki K Poulose
authored andcommitted
coresight: Refactor driver data allocation
The driver data no longer needs to be allocated separately in the static and dynamic probes. Moved the allocation into the low-level functions to avoid code duplication. Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com> Reviewed-by: Yeoreum Yun <yeoreum.yun@arm.com> Tested-by: James Clark <james.clark@linaro.org> Signed-off-by: Leo Yan <leo.yan@arm.com> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com> Link: https://lore.kernel.org/r/20250731-arm_cs_fix_clock_v4-v6-8-1dfe10bb3f6f@arm.com
1 parent fbe7514 commit ba6b61f

3 files changed

Lines changed: 21 additions & 40 deletions

File tree

drivers/hwtracing/coresight/coresight-catu.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -515,11 +515,17 @@ static int __catu_probe(struct device *dev, struct resource *res)
515515
{
516516
int ret = 0;
517517
u32 dma_mask;
518-
struct catu_drvdata *drvdata = dev_get_drvdata(dev);
518+
struct catu_drvdata *drvdata;
519519
struct coresight_desc catu_desc;
520520
struct coresight_platform_data *pdata = NULL;
521521
void __iomem *base;
522522

523+
drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
524+
if (!drvdata)
525+
return -ENOMEM;
526+
527+
dev_set_drvdata(dev, drvdata);
528+
523529
ret = coresight_get_enable_clocks(dev, &drvdata->pclk, &drvdata->atclk);
524530
if (ret)
525531
return ret;
@@ -580,14 +586,8 @@ static int __catu_probe(struct device *dev, struct resource *res)
580586

581587
static int catu_probe(struct amba_device *adev, const struct amba_id *id)
582588
{
583-
struct catu_drvdata *drvdata;
584589
int ret;
585590

586-
drvdata = devm_kzalloc(&adev->dev, sizeof(*drvdata), GFP_KERNEL);
587-
if (!drvdata)
588-
return -ENOMEM;
589-
590-
amba_set_drvdata(adev, drvdata);
591591
ret = __catu_probe(&adev->dev, &adev->res);
592592
if (!ret)
593593
pm_runtime_put(&adev->dev);
@@ -627,18 +627,12 @@ static struct amba_driver catu_driver = {
627627
static int catu_platform_probe(struct platform_device *pdev)
628628
{
629629
struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
630-
struct catu_drvdata *drvdata;
631630
int ret = 0;
632631

633-
drvdata = devm_kzalloc(&pdev->dev, sizeof(*drvdata), GFP_KERNEL);
634-
if (!drvdata)
635-
return -ENOMEM;
636-
637632
pm_runtime_get_noresume(&pdev->dev);
638633
pm_runtime_set_active(&pdev->dev);
639634
pm_runtime_enable(&pdev->dev);
640635

641-
dev_set_drvdata(&pdev->dev, drvdata);
642636
ret = __catu_probe(&pdev->dev, res);
643637
pm_runtime_put(&pdev->dev);
644638
if (ret)

drivers/hwtracing/coresight/coresight-cpu-debug.c

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -562,10 +562,16 @@ static void debug_func_exit(void)
562562

563563
static int __debug_probe(struct device *dev, struct resource *res)
564564
{
565-
struct debug_drvdata *drvdata = dev_get_drvdata(dev);
565+
struct debug_drvdata *drvdata;
566566
void __iomem *base;
567567
int ret;
568568

569+
drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
570+
if (!drvdata)
571+
return -ENOMEM;
572+
573+
dev_set_drvdata(dev, drvdata);
574+
569575
ret = coresight_get_enable_clocks(dev, &drvdata->pclk, NULL);
570576
if (ret)
571577
return ret;
@@ -629,13 +635,6 @@ static int __debug_probe(struct device *dev, struct resource *res)
629635

630636
static int debug_probe(struct amba_device *adev, const struct amba_id *id)
631637
{
632-
struct debug_drvdata *drvdata;
633-
634-
drvdata = devm_kzalloc(&adev->dev, sizeof(*drvdata), GFP_KERNEL);
635-
if (!drvdata)
636-
return -ENOMEM;
637-
638-
amba_set_drvdata(adev, drvdata);
639638
return __debug_probe(&adev->dev, &adev->res);
640639
}
641640

@@ -694,14 +693,8 @@ static struct amba_driver debug_driver = {
694693
static int debug_platform_probe(struct platform_device *pdev)
695694
{
696695
struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
697-
struct debug_drvdata *drvdata;
698696
int ret = 0;
699697

700-
drvdata = devm_kzalloc(&pdev->dev, sizeof(*drvdata), GFP_KERNEL);
701-
if (!drvdata)
702-
return -ENOMEM;
703-
704-
dev_set_drvdata(&pdev->dev, drvdata);
705698
pm_runtime_get_noresume(&pdev->dev);
706699
pm_runtime_set_active(&pdev->dev);
707700
pm_runtime_enable(&pdev->dev);

drivers/hwtracing/coresight/coresight-tmc-core.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -775,10 +775,16 @@ static int __tmc_probe(struct device *dev, struct resource *res)
775775
u32 devid;
776776
void __iomem *base;
777777
struct coresight_platform_data *pdata = NULL;
778-
struct tmc_drvdata *drvdata = dev_get_drvdata(dev);
778+
struct tmc_drvdata *drvdata;
779779
struct coresight_desc desc = { 0 };
780780
struct coresight_dev_list *dev_list = NULL;
781781

782+
drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
783+
if (!drvdata)
784+
return -ENOMEM;
785+
786+
dev_set_drvdata(dev, drvdata);
787+
782788
ret = coresight_get_enable_clocks(dev, &drvdata->pclk, &drvdata->atclk);
783789
if (ret)
784790
return ret;
@@ -888,14 +894,8 @@ static int __tmc_probe(struct device *dev, struct resource *res)
888894

889895
static int tmc_probe(struct amba_device *adev, const struct amba_id *id)
890896
{
891-
struct tmc_drvdata *drvdata;
892897
int ret;
893898

894-
drvdata = devm_kzalloc(&adev->dev, sizeof(*drvdata), GFP_KERNEL);
895-
if (!drvdata)
896-
return -ENOMEM;
897-
898-
amba_set_drvdata(adev, drvdata);
899899
ret = __tmc_probe(&adev->dev, &adev->res);
900900
if (!ret)
901901
pm_runtime_put(&adev->dev);
@@ -972,14 +972,8 @@ static struct amba_driver tmc_driver = {
972972
static int tmc_platform_probe(struct platform_device *pdev)
973973
{
974974
struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
975-
struct tmc_drvdata *drvdata;
976975
int ret = 0;
977976

978-
drvdata = devm_kzalloc(&pdev->dev, sizeof(*drvdata), GFP_KERNEL);
979-
if (!drvdata)
980-
return -ENOMEM;
981-
982-
dev_set_drvdata(&pdev->dev, drvdata);
983977
pm_runtime_get_noresume(&pdev->dev);
984978
pm_runtime_set_active(&pdev->dev);
985979
pm_runtime_enable(&pdev->dev);

0 commit comments

Comments
 (0)