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 9BA9026982F; Tue, 8 Apr 2025 12:35:55 +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=1744115755; cv=none; b=r6pHGEU/UmubIB0hDfgaEYM6b5p5+xVX8DkD2g3Ps5KbPjadvkTdW1hTRrtG71uydPsOY4u7qRs79zrnC4JRdM9LsdNpNzXlMTIAWNEwvQBQf+GTOVKqSHh7DkQvqe9d082ooym1GynQ0d/dPedt/ljyZH9NMqL0xbItHq4k/rs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744115755; c=relaxed/simple; bh=Wu2lyMYOeFGiAyAE4iwTZzIyI6ZbMmXUH/iRsW1vMfQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Or8i7cd6OuWyxV7UuY5WJaWw9r4Liwy5QXa9zFAyYRhrIHF9S00HfVPEEaa1R2dVSDfJ8wu7jEYHJfhxf9UGBwmTOQw4nmZsf66inyqFotcru/0lDHFi+7c+QhIiYUxIa/yFQaoLts9DT3kvU/uWvNS7Z7nJLSCW3YEN1UnLnr4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=qpUS9Pnk; 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="qpUS9Pnk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EE2BFC4CEE7; Tue, 8 Apr 2025 12:35:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1744115755; bh=Wu2lyMYOeFGiAyAE4iwTZzIyI6ZbMmXUH/iRsW1vMfQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qpUS9PnkO8iAHczytNEAGjkf0AZZOa8o+jVNSfiY9c1XaAdMyQwtchwpdjEikPHa/ vKTaGl8FgNQGItCWvGcllMZpqwiqLWzfMiq/ee/0iuAy142PXycC5IFcYG/BC8ITsm TEEN+pSFvs5GsBgBqIipmzJBZakRtAwETTEj9wkI= 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.1 092/204] usb: xhci: correct debug message page size calculation Date: Tue, 8 Apr 2025 12:50:22 +0200 Message-ID: <20250408104823.043275343@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250408104820.266892317@linuxfoundation.org> References: <20250408104820.266892317@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-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 27c924ddb68e6..09e7eabdb73f4 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -2342,10 +2342,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