Skip to content

Commit 4334c6e

Browse files
rmurphy-armgregkh
authored andcommitted
coresight: tpiu: Fix disabling timeouts
[ Upstream commit ccff2df ] Probing the TPIU driver under UBSan triggers an out-of-bounds shift warning in coresight_timeout(): ... [ 5.677530] UBSAN: Undefined behaviour in drivers/hwtracing/coresight/coresight.c:929:16 [ 5.685542] shift exponent 64 is too large for 64-bit type 'long unsigned int' ... On closer inspection things are exponentially out of whack because we're passing a bitmask where a bit number should be. Amusingly, it seems that both calls will find their expected values by sheer luck and appear to succeed: 1 << FFCR_FON_MAN ends up at bit 64 which whilst undefined evaluates as zero in practice, while 1 << FFSR_FT_STOPPED finds bit 2 (TCPresent) which apparently is usually tied high. Following the examples of other drivers, define separate FOO and FOO_BIT macros for masks vs. indices, and put things right. CC: Robert Walker <robert.walker@arm.com> CC: Mike Leach <mike.leach@linaro.org> CC: Mathieu Poirier <mathieu.poirier@linaro.org> Fixes: 11595db ("coresight: Fix disabling of CoreSight TPIU") Signed-off-by: Robin Murphy <robin.murphy@arm.com> Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Sasha Levin <alexander.levin@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 7a46541 commit 4334c6e

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

drivers/hwtracing/coresight/coresight-tpiu.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@
4747

4848
/** register definition **/
4949
/* FFSR - 0x300 */
50-
#define FFSR_FT_STOPPED BIT(1)
50+
#define FFSR_FT_STOPPED_BIT 1
5151
/* FFCR - 0x304 */
52+
#define FFCR_FON_MAN_BIT 6
5253
#define FFCR_FON_MAN BIT(6)
5354
#define FFCR_STOP_FI BIT(12)
5455

@@ -93,9 +94,9 @@ static void tpiu_disable_hw(struct tpiu_drvdata *drvdata)
9394
/* Generate manual flush */
9495
writel_relaxed(FFCR_STOP_FI | FFCR_FON_MAN, drvdata->base + TPIU_FFCR);
9596
/* Wait for flush to complete */
96-
coresight_timeout(drvdata->base, TPIU_FFCR, FFCR_FON_MAN, 0);
97+
coresight_timeout(drvdata->base, TPIU_FFCR, FFCR_FON_MAN_BIT, 0);
9798
/* Wait for formatter to stop */
98-
coresight_timeout(drvdata->base, TPIU_FFSR, FFSR_FT_STOPPED, 1);
99+
coresight_timeout(drvdata->base, TPIU_FFSR, FFSR_FT_STOPPED_BIT, 1);
99100

100101
CS_LOCK(drvdata->base);
101102
}

0 commit comments

Comments
 (0)