Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp114925pxm; Fri, 25 Feb 2022 05:05:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJxb5nuDAYU0GDV1Hg73XnK18fOgg/MGpN2sL9RRQpbXUAy69S4J750Qz9Nr+f+b77bnpV4R X-Received: by 2002:a17:90a:bb8d:b0:1bc:72a9:a07d with SMTP id v13-20020a17090abb8d00b001bc72a9a07dmr3085304pjr.9.1645794329829; Fri, 25 Feb 2022 05:05:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645794329; cv=none; d=google.com; s=arc-20160816; b=lzrGmxj30LxV/rkd9pantQSLZr4CK1lwAmwUPJj9enko7lwPLB7355gOeyiZFVb3Te /BumVIjCV0ka4gLCfvTdOB1g0QcCGBHaiqJ1NiquPyxz2AwIpSn6R6ZRLZxxWZ84uPia qppDskmCp7IVtA0iyIQWkxjag4fr1RC6JUe7DHHS/P9KaFQ2mbrDJ1qcC1msxvV8RRDg HlPH9CgPYWRvJQJ59omX4ZWIqHInMnPZzU1OT4sjr7k0zMn5eZHvekhAx67lsAlW9WcV CTgBJe02BAsQMxJUlht85HmSK/ycbo/DFf95f/o4n3n79b6HshY1gNCYm5jUr55CL7ok 6v0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=XlWD1zYq8HTY9gMjgK3kUW6FJGewA3uatL504kIgRyA=; b=sbgZO6gNsDKqJ6doAn6oMG8EMBRd86LE1AcFSpl7mj5taMaXxZf8vjpDNJNyuLNqKh AxQWD9Hmjb86O9PVVQVF20O90J193nQNO8kxrI8JU2KPR8iH6rvWNoAKoteQrx9LY41r QCus8+roECyY2K6bUIN38qsYE4Ze9wyDHSoH2IFDpTbLNChEZcjJREtMNtsKr19wuW8J zdxBLTXlbT64tR2hNX1MG/7YSbV9RbSe+zmL8zJYeG6ZaYj7CvEZif+7BRBRWQvG9Dbo 0Rv8kjfd+LhYOJJxDlCpeFt+iLJeAytspLBla8i0MIDRTnCxyT0KdltQyCB1y1Mohj27 mFcw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bitwise.fi Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u16-20020a17090adb5000b001bba6587827si1926353pjx.70.2022.02.25.05.04.50; Fri, 25 Feb 2022 05:05:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bitwise.fi Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239491AbiBYK1U (ORCPT + 99 others); Fri, 25 Feb 2022 05:27:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231214AbiBYK1O (ORCPT ); Fri, 25 Feb 2022 05:27:14 -0500 Received: from mail.bitwise.fi (mail.bitwise.fi [109.204.228.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEC32384; Fri, 25 Feb 2022 02:26:37 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by mail.bitwise.fi (Postfix) with ESMTP id 8358946002C; Fri, 25 Feb 2022 12:26:33 +0200 (EET) X-Virus-Scanned: Debian amavisd-new at Received: from mail.bitwise.fi ([127.0.0.1]) by localhost (mustetatti.dmz.bitwise.fi [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id aPS1rS0NMg1h; Fri, 25 Feb 2022 12:26:31 +0200 (EET) Received: from localhost.net (fw1.dmz.bitwise.fi [192.168.69.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: anssiha) by mail.bitwise.fi (Postfix) with ESMTPSA id 6D87C46001C; Fri, 25 Feb 2022 12:26:31 +0200 (EET) From: Anssi Hannula To: Mathias Nyman Cc: Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2 v2] xhci: fix garbage USBSTS being logged in some cases Date: Fri, 25 Feb 2022 12:26:02 +0200 Message-Id: <20220225102602.3829106-1-anssi.hannula@bitwise.fi> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org xhci_decode_usbsts() is expected to return a zero-terminated string by its only caller, xhci_stop_endpoint_command_watchdog(), which directly logs the return value: xhci_warn(xhci, "USBSTS:%s\n", xhci_decode_usbsts(str, usbsts)); However, if no recognized bits are set in usbsts, the function will return without having called any sprintf() and therefore return an untouched non-zero-terminated caller-provided buffer, causing garbage to be output to log. Fix that by always including the raw value in the output. Note that before 4843b4b5ec64 ("xhci: fix even more unsafe memory usage in xhci tracing") the result effect in the failure case was different as a static buffer was used here, but the code still worked incorrectly. Fixes: 9c1aa36efdae ("xhci: Show host status when watchdog triggers and host is assumed dead.") Signed-off-by: Anssi Hannula --- Mathias Nyman wrote: > Maybe this could be the first thing printed out, something like (untested): [...] Heh, that's actually pretty close to what I had at one point, not sure why I didn't go with it. I agree it looks better. Changed and tested on real HW: [ 11.998832] xhci-hcd xhci-hcd.1.auto: xHCI host not responding to stop endpoint command. [ 12.006925] xhci-hcd xhci-hcd.1.auto: USBSTS: 0x00000000 v2: Improve print format on Mathias Nyman's suggestion. drivers/usb/host/xhci.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 8a0026ee9524..dd24c09927bd 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -2622,8 +2622,11 @@ static inline const char *xhci_decode_usbsts(char *str, u32 usbsts) { int ret = 0; + ret = sprintf(str, " 0x%08x", usbsts); + if (usbsts == ~(u32)0) - return " 0xffffffff"; + return str; + if (usbsts & STS_HALT) ret += sprintf(str + ret, " HCHalted"); if (usbsts & STS_FATAL) -- 2.34.1