diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c index 8724bb349944..a544b81dee21 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c @@ -1249,6 +1249,22 @@ static int tmc_enable_etr_sink_sysfs(struct coresight_device *csdev) struct tmc_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); struct etr_buf *sysfs_buf = NULL, *new_buf = NULL, *free_buf = NULL; + spin_lock_irqsave(&drvdata->spinlock, flags); + if (drvdata->reading || drvdata->mode == CS_MODE_PERF) { + ret = -EBUSY; + goto unlock_out; + } + + /* + * In sysFS mode we can have multiple writers per sink. Since this + * sink is already enabled no memory is needed and the HW need not be + * touched, even if the buffer size has changed. + */ + if (drvdata->mode == CS_MODE_SYSFS) { + atomic_inc(csdev->refcnt); + goto unlock_out; + } + /* * If we are enabling the ETR from disabled state, we need to make * sure we have a buffer with the right size. The etr_buf is not reset @@ -1257,7 +1273,6 @@ static int tmc_enable_etr_sink_sysfs(struct coresight_device *csdev) * buffer, provided the size matches. Any allocation has to be done * with the lock released. */ - spin_lock_irqsave(&drvdata->spinlock, flags); if ((drvdata->out_mode == TMC_ETR_OUT_MODE_MEM) || (drvdata->out_mode == TMC_ETR_OUT_MODE_USB && drvdata->usb_data->usb_mode == @@ -1280,21 +1295,6 @@ static int tmc_enable_etr_sink_sysfs(struct coresight_device *csdev) } } - if (drvdata->reading || drvdata->mode == CS_MODE_PERF) { - ret = -EBUSY; - goto unlock_out; - } - - /* - * In sysFS mode we can have multiple writers per sink. Since this - * sink is already enabled no memory is needed and the HW need not be - * touched, even if the buffer size has changed. - */ - if (drvdata->mode == CS_MODE_SYSFS) { - atomic_inc(csdev->refcnt); - goto unlock_out; - } - /* * If we don't have a buffer or it doesn't match the requested size, * use the buffer allocated above. Otherwise reuse the existing buffer.