From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2C7471EA65; Tue, 8 Apr 2025 12:51:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744116661; cv=none; b=d2kt4h5MQWyNoZGVRC3qPhA9LIC1rWnBnov8saoBUuJQzB4rmSt3zD1ico+Hn8ouPhUdB0EWHq809STDzEfDaX+mA/RNwf12VaaEiJvc9Wh7w7tyeUeDVT/+mEy53EXH2gv6McwQ+eGTXox0EzDA9+2i1gfg9Sj6i1a72T4lDns= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744116661; c=relaxed/simple; bh=W9dm+f8+rFA5eLqgNrJG0nHrYTePW9cMeO2zS3pQEyQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=b+5LAzbqmGWyx1LvpyrvamnMdhf3RRuc/Z86/I+eFvBUDhRpOkfAf/Upu906+FkpFYi3e6jVtQngEGmXBwddkOKs673vbDNbLZtr+gcUbXQOTuocGRetGmdaL7x8vDL/TwiJcSSFo1A9LpHpDr9/wwAd8qfV+f0c+gpYalbeucI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=vlgt67+p; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="vlgt67+p" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B2CA9C4CEE5; Tue, 8 Apr 2025 12:51:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1744116661; bh=W9dm+f8+rFA5eLqgNrJG0nHrYTePW9cMeO2zS3pQEyQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vlgt67+pcXWBUIsNAEAh240VZE+pN4OdhEOFSdaBcJ3dVcBp3b9JS7BrIjIoXAz8L FKe0E7UIQ7A5hxXGwhSNUDyBkwMjMH96FH7FU4DY8MN1DjGUaaJoGmDMvRwZ26+BhE tOtXC3lJmXOVz20VkkfBP4mNtKBn2DslC249QL0Q= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Niklas Neronin , Mathias Nyman , Sasha Levin Subject: [PATCH 6.12 183/423] usb: xhci: correct debug message page size calculation Date: Tue, 8 Apr 2025 12:48:29 +0200 Message-ID: <20250408104850.005757533@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250408104845.675475678@linuxfoundation.org> References: <20250408104845.675475678@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Niklas Neronin [ Upstream commit 55741c723318905e6d5161bf1e12749020b161e3 ] The ffs() function returns the index of the first set bit, starting from 1. If no bits are set, it returns zero. This behavior causes an off-by-one page size in the debug message, as the page size calculation [1] is zero-based, while ffs() is one-based. Fix this by subtracting one from the result of ffs(). Note that since variable 'val' is unsigned, subtracting one from zero will result in the maximum unsigned integer value. Consequently, the condition 'if (val < 16)' will still function correctly. [1], Page size: (2^(n+12)), where 'n' is the set page size bit. Fixes: 81720ec5320c ("usb: host: xhci: use ffs() in xhci_mem_init()") Signed-off-by: Niklas Neronin Signed-off-by: Mathias Nyman Link: https://lore.kernel.org/r/20250306144954.3507700-9-mathias.nyman@linux.intel.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/usb/host/xhci-mem.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index 32c8693b438b0..8c26275696df9 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -2397,10 +2397,10 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) page_size = readl(&xhci->op_regs->page_size); xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Supported page size register = 0x%x", page_size); - i = ffs(page_size); - if (i < 16) + val = ffs(page_size) - 1; + if (val < 16) xhci_dbg_trace(xhci, trace_xhci_dbg_init, - "Supported page size of %iK", (1 << (i+12)) / 1024); + "Supported page size of %iK", (1 << (val + 12)) / 1024); else xhci_warn(xhci, "WARN: no supported page size\n"); /* Use 4K pages, since that's common and the minimum the HC supports */ -- 2.39.5