From e98d3f8c7449b83113136e7c7ef6f5e283761e29 Mon Sep 17 00:00:00 2001 From: Yuanfang Zhang Date: Fri, 26 Feb 2021 17:25:34 +0800 Subject: [PATCH] byte-cntr: ensure usbch to be ready Ensure usbch is ready before usb bypass start to avoid usbch is NULL in usb_read_work_fn(). Change-Id: I0b932f1713a2d49424860728e79e3684122b4e40 Signed-off-by: Yuanfang Zhang --- .../hwtracing/coresight/coresight-byte-cntr.c | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/drivers/hwtracing/coresight/coresight-byte-cntr.c b/drivers/hwtracing/coresight/coresight-byte-cntr.c index cebea0e8b143..18a44f24384d 100644 --- a/drivers/hwtracing/coresight/coresight-byte-cntr.c +++ b/drivers/hwtracing/coresight/coresight-byte-cntr.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: GPL-2.0-only -/* Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. +/* Copyright (c) 2017-2021, The Linux Foundation. All rights reserved. * * Description: CoreSight Trace Memory Controller driver */ @@ -207,6 +207,24 @@ static int usb_bypass_start(struct byte_cntr *byte_cntr_data) return -EINVAL; } + /*Ensure usbch is ready*/ + if (!tmcdrvdata->usbch) { + int i; + + for (i = TIMEOUT_US; i > 0; i--) { + if (tmcdrvdata->usbch) + break; + + if (i - 1) + udelay(1); + else { + dev_err(&tmcdrvdata->csdev->dev, + "timeout while waiting usbch to be ready\n"); + mutex_unlock(&byte_cntr_data->usb_bypass_lock); + return -EAGAIN; + } + } + } atomic_set(&byte_cntr_data->usb_free_buf, USB_BUF_NUM); offset = tmc_sg_get_rwp_offset(tmcdrvdata);