Skip to content

Commit 8356894

Browse files
coresight: tmc: re-implementing tmc_read_prepare/unprepare() functions
In their current implementation the tmc_read_prepare/unprepare() are a lump of if/else that is difficult to read. This patch is alleviating that by using a switch statement. The latter also allows for a better control on the error path. Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org> Reviewed-by: Suzuki K Poulose <suzuki.poulose@arm.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> (cherry picked from commit b1789b793eb4627928f55a6acea8da7c25e5c6b4)
1 parent 66c6e11 commit 8356894

1 file changed

Lines changed: 36 additions & 20 deletions

File tree

drivers/hwtracing/coresight/coresight-tmc.c

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -431,33 +431,39 @@ static const struct coresight_ops tmc_etf_cs_ops = {
431431

432432
static int tmc_read_prepare(struct tmc_drvdata *drvdata)
433433
{
434-
int ret;
434+
int ret = 0;
435435
unsigned long flags;
436436
enum tmc_mode mode;
437437

438438
spin_lock_irqsave(&drvdata->spinlock, flags);
439439
if (!drvdata->enable)
440440
goto out;
441441

442-
if (drvdata->config_type == TMC_CONFIG_TYPE_ETB) {
442+
switch (drvdata->config_type) {
443+
case TMC_CONFIG_TYPE_ETB:
443444
tmc_etb_disable_hw(drvdata);
444-
} else if (drvdata->config_type == TMC_CONFIG_TYPE_ETR) {
445-
tmc_etr_disable_hw(drvdata);
446-
} else {
445+
break;
446+
case TMC_CONFIG_TYPE_ETF:
447+
/* There is no point in reading a TMC in HW FIFO mode */
447448
mode = readl_relaxed(drvdata->base + TMC_MODE);
448-
if (mode == TMC_MODE_CIRCULAR_BUFFER) {
449-
tmc_etb_disable_hw(drvdata);
450-
} else {
451-
ret = -ENODEV;
449+
if (mode != TMC_MODE_CIRCULAR_BUFFER) {
450+
ret = -EINVAL;
452451
goto err;
453452
}
453+
454+
tmc_etb_disable_hw(drvdata);
455+
break;
456+
case TMC_CONFIG_TYPE_ETR:
457+
tmc_etr_disable_hw(drvdata);
458+
break;
459+
default:
460+
ret = -EINVAL;
461+
goto err;
454462
}
463+
455464
out:
456465
drvdata->reading = true;
457-
spin_unlock_irqrestore(&drvdata->spinlock, flags);
458-
459466
dev_info(drvdata->dev, "TMC read start\n");
460-
return 0;
461467
err:
462468
spin_unlock_irqrestore(&drvdata->spinlock, flags);
463469
return ret;
@@ -472,20 +478,30 @@ static void tmc_read_unprepare(struct tmc_drvdata *drvdata)
472478
if (!drvdata->enable)
473479
goto out;
474480

475-
if (drvdata->config_type == TMC_CONFIG_TYPE_ETB) {
481+
switch (drvdata->config_type) {
482+
case TMC_CONFIG_TYPE_ETB:
476483
tmc_etb_enable_hw(drvdata);
477-
} else if (drvdata->config_type == TMC_CONFIG_TYPE_ETR) {
478-
tmc_etr_enable_hw(drvdata);
479-
} else {
484+
break;
485+
case TMC_CONFIG_TYPE_ETF:
486+
/* Make sure we don't re-enable a TMC in HW FIFO mode */
480487
mode = readl_relaxed(drvdata->base + TMC_MODE);
481-
if (mode == TMC_MODE_CIRCULAR_BUFFER)
482-
tmc_etb_enable_hw(drvdata);
488+
if (mode != TMC_MODE_CIRCULAR_BUFFER)
489+
goto err;
490+
491+
tmc_etb_enable_hw(drvdata);
492+
break;
493+
case TMC_CONFIG_TYPE_ETR:
494+
tmc_etr_disable_hw(drvdata);
495+
break;
496+
default:
497+
goto err;
483498
}
499+
484500
out:
485501
drvdata->reading = false;
486-
spin_unlock_irqrestore(&drvdata->spinlock, flags);
487-
488502
dev_info(drvdata->dev, "TMC read end\n");
503+
err:
504+
spin_unlock_irqrestore(&drvdata->spinlock, flags);
489505
}
490506

491507
static int tmc_open(struct inode *inode, struct file *file)

0 commit comments

Comments
 (0)