From patchwork Mon Feb 6 16:10:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13130293 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5B845C05027 for ; Mon, 6 Feb 2023 16:10:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231433AbjBFQKS (ORCPT ); Mon, 6 Feb 2023 11:10:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229733AbjBFQKR (ORCPT ); Mon, 6 Feb 2023 11:10:17 -0500 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D4AC44B4; Mon, 6 Feb 2023 08:10:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675699816; x=1707235816; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ucD+M51+UJA6YNazEMYHsIe2cYjXbeVwqV2yq8GaAVs=; b=U8GTUMHpLf9UheiT4mGGim4hFfI7gxeS1dxOyY0qH+iD6iKQCeZFwuSP oXHiT5lJhvPgD0lHzv9cNn1il2wLMYSTPbldX4fJtCpXdDCdYm5yYIR9G NOoqwMhpEWSSonXnDSTtBS8S1cIhZDaL86PNEReSvu0wY+RYqUoYFfX4G NVmNhO5OZ8fo+KwinjzqdVqdFHhSLQjF86VJqnoQ4vxUw4EvYePLUy1Kh qlgQ200NnKsoCbIVJzeviBXpgRIyXYNtKlYGVqyZNDKemeubcJoiz09Yu WDma+LIzghbGVWZITHI9fgJg78o0d5dXwhDu82dEgq3PHUHsFw97OxSmX A==; X-IronPort-AV: E=McAfee;i="6500,9779,10613"; a="327876993" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="327876993" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Feb 2023 08:10:16 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10613"; a="644084653" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="644084653" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga006.jf.intel.com with ESMTP; 06 Feb 2023 08:10:14 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 47D4A1DD; Mon, 6 Feb 2023 18:10:52 +0200 (EET) From: Andy Shevchenko To: Mathias Nyman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Mathias Nyman , Greg Kroah-Hartman , Andy Shevchenko Subject: [PATCH v1 1/7] xhci: mem: Carefully calculate size for memory allocations Date: Mon, 6 Feb 2023 18:10:43 +0200 Message-Id: <20230206161049.13972-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230206161049.13972-1-andriy.shevchenko@linux.intel.com> References: <20230206161049.13972-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Carefully calculate size for memory allocations, i.e. with help of size_mul() macro from overflow.h. Signed-off-by: Andy Shevchenko --- drivers/usb/host/xhci-mem.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index d0a9467aa5fc..c385513ad00b 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -9,6 +9,7 @@ */ #include +#include #include #include #include @@ -568,7 +569,7 @@ static struct xhci_stream_ctx *xhci_alloc_stream_ctx(struct xhci_hcd *xhci, gfp_t mem_flags) { struct device *dev = xhci_to_hcd(xhci)->self.sysdev; - size_t size = sizeof(struct xhci_stream_ctx) * num_stream_ctxs; + size_t size = size_mul(sizeof(struct xhci_stream_ctx), num_stream_ctxs); if (size > MEDIUM_STREAM_ARRAY_SIZE) return dma_alloc_coherent(dev, size, @@ -1660,7 +1661,7 @@ static int scratchpad_alloc(struct xhci_hcd *xhci, gfp_t flags) goto fail_sp; xhci->scratchpad->sp_array = dma_alloc_coherent(dev, - num_sp * sizeof(u64), + size_mul(sizeof(u64), num_sp), &xhci->scratchpad->sp_dma, flags); if (!xhci->scratchpad->sp_array) goto fail_sp2; @@ -1799,7 +1800,7 @@ int xhci_alloc_erst(struct xhci_hcd *xhci, struct xhci_segment *seg; struct xhci_erst_entry *entry; - size = sizeof(struct xhci_erst_entry) * evt_ring->num_segs; + size = size_mul(sizeof(struct xhci_erst_entry), evt_ring->num_segs); erst->entries = dma_alloc_coherent(xhci_to_hcd(xhci)->self.sysdev, size, &erst->erst_dma_addr, flags); if (!erst->entries) @@ -1830,7 +1831,7 @@ xhci_free_interrupter(struct xhci_hcd *xhci, struct xhci_interrupter *ir) if (!ir) return; - erst_size = sizeof(struct xhci_erst_entry) * (ir->erst.num_entries); + erst_size = sizeof(struct xhci_erst_entry) * ir->erst.num_entries; if (ir->erst.entries) dma_free_coherent(dev, erst_size, ir->erst.entries, From patchwork Mon Feb 6 16:10:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13130294 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E99F1C636D3 for ; Mon, 6 Feb 2023 16:10:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231560AbjBFQKT (ORCPT ); Mon, 6 Feb 2023 11:10:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229982AbjBFQKR (ORCPT ); Mon, 6 Feb 2023 11:10:17 -0500 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E706C6580; Mon, 6 Feb 2023 08:10:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675699816; x=1707235816; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xh+eFvZUt3OEbPV7o5Euz7hBLKZySMxgRjkO8wgC73k=; b=ZFoqVZMYBk3WY82EG6QSZgV6GNjtGNlO2Tn2A7ARrnQfGvLe5/6pXivq 9WAq/RrrUMP3lDn7oZCaqyDlzAkqXgFJuH2UGt6rRLrouE+ci0yxTjv2G L+0hSF+bh/28MgnL9QpL+xGrJ3XeO4erDHMPAY2Nkddqaye7SkSUcjqqe vJVsz3xEI/LPcZL2uxmez1QdSd8X3xrLdTdI6Xo0o4NXyyRLOZfdZbheW 0yniA1FNA8g4SZGDPFhK1Ud6ZRlg17pijgjGgT4GKFvSLfeH2G5kcQYwa kKqTX4/FxwgoOAF/9x5g8mGRum5tYWTFnofwhQaiug3vZ/0ER0B9jc0OH Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10613"; a="327876997" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="327876997" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Feb 2023 08:10:16 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10613"; a="644084656" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="644084656" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga006.jf.intel.com with ESMTP; 06 Feb 2023 08:10:14 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 59BA927B; Mon, 6 Feb 2023 18:10:52 +0200 (EET) From: Andy Shevchenko To: Mathias Nyman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Mathias Nyman , Greg Kroah-Hartman , Andy Shevchenko Subject: [PATCH v1 2/7] xhci: mem: Use __GFP_ZERO instead of explicit memset() call Date: Mon, 6 Feb 2023 18:10:44 +0200 Message-Id: <20230206161049.13972-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230206161049.13972-1-andriy.shevchenko@linux.intel.com> References: <20230206161049.13972-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Use __GFP_ZERO instead of explicit memset() call in xhci_alloc_stream_ctx(). Signed-off-by: Andy Shevchenko --- drivers/usb/host/xhci-mem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index c385513ad00b..768adcb544a7 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -571,6 +571,8 @@ static struct xhci_stream_ctx *xhci_alloc_stream_ctx(struct xhci_hcd *xhci, struct device *dev = xhci_to_hcd(xhci)->self.sysdev; size_t size = size_mul(sizeof(struct xhci_stream_ctx), num_stream_ctxs); + mem_flags |= __GFP_ZERO; + if (size > MEDIUM_STREAM_ARRAY_SIZE) return dma_alloc_coherent(dev, size, dma, mem_flags); @@ -643,8 +645,6 @@ struct xhci_stream_info *xhci_alloc_stream_info(struct xhci_hcd *xhci, mem_flags); if (!stream_info->stream_ctx_array) goto cleanup_ring_array; - memset(stream_info->stream_ctx_array, 0, - sizeof(struct xhci_stream_ctx)*num_stream_ctxs); /* Allocate everything needed to free the stream rings later */ stream_info->free_streams_command = From patchwork Mon Feb 6 16:10:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13130295 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D62F7C636D4 for ; Mon, 6 Feb 2023 16:10:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231584AbjBFQKU (ORCPT ); Mon, 6 Feb 2023 11:10:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230344AbjBFQKS (ORCPT ); Mon, 6 Feb 2023 11:10:18 -0500 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75D2D6599; Mon, 6 Feb 2023 08:10:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675699817; x=1707235817; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KNO3nmWlf3AsLk6AzRjxlRpI2rddvoMug2nqLE6A5y4=; b=FQm9KNb/jQ8LMIYXHzqSPllrsJ+3/8Mkt4wYHI7XaplAvLPXzuRVypfE LK0iMqWdvqCRCrh3BE88W26STM1M/b50WSDdbTAE1gMGk/QhzYe8qlaGw 6ZOcJh4xLYOXWS6Rz9eUFw+Hk6uJ+xWclm5kuNkpoGx6rhFRKf9kQpCHp l/IF0656htQCMBXuJOe9uwPUN+DuAV+LHMj/o55fUjuSES+CQZbiGURy/ BK93VAYO5O4g7XIlEjglB/Hb+0UFvVTwZ+/F2VWL7zvDrD+897eHHUDe5 iO3d5ekmx1jzDKou2T43Z2twR7XUJaXbuxF2EtxXtveG88bC9JwWpFuLV w==; X-IronPort-AV: E=McAfee;i="6500,9779,10613"; a="327876999" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="327876999" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Feb 2023 08:10:16 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10613"; a="644084658" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="644084658" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga006.jf.intel.com with ESMTP; 06 Feb 2023 08:10:14 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 5EE47241; Mon, 6 Feb 2023 18:10:52 +0200 (EET) From: Andy Shevchenko To: Mathias Nyman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Mathias Nyman , Greg Kroah-Hartman , Andy Shevchenko Subject: [PATCH v1 3/7] xhci: mem: Get rid of redundant 'else' Date: Mon, 6 Feb 2023 18:10:45 +0200 Message-Id: <20230206161049.13972-4-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230206161049.13972-1-andriy.shevchenko@linux.intel.com> References: <20230206161049.13972-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org In the snippets like the following if (...) return / goto / break / continue ...; else ... the 'else' is redundant. Get rid of it. While at it, make if chain sorted from testing bigger values to smaller. Signed-off-by: Andy Shevchenko --- drivers/usb/host/xhci-mem.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index 768adcb544a7..34f5ba19471e 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -574,14 +574,11 @@ static struct xhci_stream_ctx *xhci_alloc_stream_ctx(struct xhci_hcd *xhci, mem_flags |= __GFP_ZERO; if (size > MEDIUM_STREAM_ARRAY_SIZE) - return dma_alloc_coherent(dev, size, - dma, mem_flags); - else if (size <= SMALL_STREAM_ARRAY_SIZE) - return dma_pool_alloc(xhci->small_streams_pool, - mem_flags, dma); + return dma_alloc_coherent(dev, size, dma, mem_flags); + if (size > SMALL_STREAM_ARRAY_SIZE) + return dma_pool_alloc(xhci->medium_streams_pool, mem_flags, dma); else - return dma_pool_alloc(xhci->medium_streams_pool, - mem_flags, dma); + return dma_pool_alloc(xhci->small_streams_pool, mem_flags, dma); } struct xhci_ring *xhci_dma_to_transfer_ring( @@ -1401,8 +1398,9 @@ static u32 xhci_get_max_esit_payload(struct usb_device *udev, if ((udev->speed >= USB_SPEED_SUPER_PLUS) && USB_SS_SSP_ISOC_COMP(ep->ss_ep_comp.bmAttributes)) return le32_to_cpu(ep->ssp_isoc_ep_comp.dwBytesPerInterval); + /* SuperSpeed or SuperSpeedPlus Isoc ep with less than 48k per esit */ - else if (udev->speed >= USB_SPEED_SUPER) + if (udev->speed >= USB_SPEED_SUPER) return le16_to_cpu(ep->ss_ep_comp.wBytesPerInterval); max_packet = usb_endpoint_maxp(&ep->desc); From patchwork Mon Feb 6 16:10:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13130298 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DBE5DC05027 for ; Mon, 6 Feb 2023 16:12:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231716AbjBFQMF (ORCPT ); Mon, 6 Feb 2023 11:12:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231508AbjBFQMD (ORCPT ); Mon, 6 Feb 2023 11:12:03 -0500 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53E442ED49; Mon, 6 Feb 2023 08:11:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675699903; x=1707235903; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6q1oqYzgNWSfxZgRT2J9mn+oyf7jlZ2Pq+SmMt+Wz70=; b=LvHTGWOT+4lYvlS+qtojUqASyyoz5+tUmpXI6j9xKqHTIERzYK9ueRCE Es+uN44OYiYLCV5FrINQjhqGYKZ0Z9+Ywr7jz9ZEUZX9RfSCYQXTWy24L R+o2qtfQRb1fDZ5DpF5m86DYya9NduQQXF5G4FZnixHfNzLMAxknfcPs1 8jRGS0flZ8ijFk0MtP5xQXPBxRFQSaLSZU1RT6zx+B8PtODcGOhZfAKWE ClDKcnQ5fKLgcpUBiUjpRR5a0YN6OugHIsT27fJ6tlmOCrQguhdhEuTRq JwCbox1aQwKBftOt/7hDGvaBrgBNWYvCvocZHdWpQI8UiogcseUiyKuOt w==; X-IronPort-AV: E=McAfee;i="6500,9779,10613"; a="308887658" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="308887658" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Feb 2023 08:10:16 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10613"; a="616485720" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="616485720" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga003.jf.intel.com with ESMTP; 06 Feb 2023 08:10:14 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 71DD934D; Mon, 6 Feb 2023 18:10:52 +0200 (EET) From: Andy Shevchenko To: Mathias Nyman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Mathias Nyman , Greg Kroah-Hartman , Andy Shevchenko Subject: [PATCH v1 4/7] xhci: mem: Drop useless return:s Date: Mon, 6 Feb 2023 18:10:46 +0200 Message-Id: <20230206161049.13972-5-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230206161049.13972-1-andriy.shevchenko@linux.intel.com> References: <20230206161049.13972-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org When function returns void and we have if-else-if chain, there is no need to explicitly call return. Drop them and indent lines better. While at it, make if chain sorted from testing bigger values to smaller. Signed-off-by: Andy Shevchenko --- drivers/usb/host/xhci-mem.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index 34f5ba19471e..5c873e62c4d3 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -544,14 +544,11 @@ static void xhci_free_stream_ctx(struct xhci_hcd *xhci, size_t size = sizeof(struct xhci_stream_ctx) * num_stream_ctxs; if (size > MEDIUM_STREAM_ARRAY_SIZE) - dma_free_coherent(dev, size, - stream_ctx, dma); - else if (size <= SMALL_STREAM_ARRAY_SIZE) - return dma_pool_free(xhci->small_streams_pool, - stream_ctx, dma); + dma_free_coherent(dev, size, stream_ctx, dma); + else if (size > SMALL_STREAM_ARRAY_SIZE) + dma_pool_free(xhci->medium_streams_pool, stream_ctx, dma); else - return dma_pool_free(xhci->medium_streams_pool, - stream_ctx, dma); + dma_pool_free(xhci->small_streams_pool, stream_ctx, dma); } /* From patchwork Mon Feb 6 16:10:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13130300 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B3821C636D3 for ; Mon, 6 Feb 2023 16:12:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231734AbjBFQMg (ORCPT ); Mon, 6 Feb 2023 11:12:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231724AbjBFQMd (ORCPT ); Mon, 6 Feb 2023 11:12:33 -0500 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 283CC17CE9; Mon, 6 Feb 2023 08:12:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675699924; x=1707235924; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5JACWvw3uGfxpdVuryzlIEd+jJzEoO70sDh6Ir94Mzs=; b=M1eNxiNTFebCLlyVmxcG3qD1dTCPlnRTeTxzD+JAnHGYzuzGZsnHzCGA u5zjyl7JEEikl7PQnNh/0R8ArebkOrUABSs/nMA6FfR8Uuq2SB3b5cMPc c7abhg7nXwtYWz664VOXb9BzdZ/0x8TMvINzRi6FMxBsxYe2CUoD2/gY7 5EzKRhgGNeVQvoEdYpWaj5coNNqIAeXCkJqug/iZ4xob4E5N1HMFNNuvZ Ieyggb/w3iENU5myN6Ftec5AqWSyxq+K/Dfeagi7uO97nJYJwqAw6h2Y3 D9bFLv/oO5/AMETVSTrS+yiACV3vYXjnCp5OAsYTfuFUA64AGxdLsak5c w==; X-IronPort-AV: E=McAfee;i="6500,9779,10613"; a="308887673" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="308887673" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Feb 2023 08:10:19 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10613"; a="698884073" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="698884073" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga001.jf.intel.com with ESMTP; 06 Feb 2023 08:10:17 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 77B8A303; Mon, 6 Feb 2023 18:10:52 +0200 (EET) From: Andy Shevchenko To: Mathias Nyman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Mathias Nyman , Greg Kroah-Hartman , Andy Shevchenko Subject: [PATCH v1 5/7] xhci: mem: Use while (i--) pattern to clean up Date: Mon, 6 Feb 2023 18:10:47 +0200 Message-Id: <20230206161049.13972-6-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230206161049.13972-1-andriy.shevchenko@linux.intel.com> References: <20230206161049.13972-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Use more natural while (i--) patter to clean up allocated resources. Signed-off-by: Andy Shevchenko --- drivers/usb/host/xhci-mem.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index 5c873e62c4d3..a3351b11efa5 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -1681,11 +1681,10 @@ static int scratchpad_alloc(struct xhci_hcd *xhci, gfp_t flags) return 0; fail_sp4: - for (i = i - 1; i >= 0; i--) { + while (i--) dma_free_coherent(dev, xhci->page_size, xhci->scratchpad->sp_buffers[i], xhci->scratchpad->sp_array[i]); - } kfree(xhci->scratchpad->sp_buffers); From patchwork Mon Feb 6 16:10:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13130297 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B984EC636D3 for ; Mon, 6 Feb 2023 16:10:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231663AbjBFQK2 (ORCPT ); Mon, 6 Feb 2023 11:10:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231613AbjBFQKX (ORCPT ); Mon, 6 Feb 2023 11:10:23 -0500 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BB4C6580; Mon, 6 Feb 2023 08:10:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675699819; x=1707235819; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IklJ4DtmNmBUFeLIjZ4SvmC24kVHGrfFxz9cUAXCZtQ=; b=A7BU4P7fnp/fqaU4I15WFMuWYa6svKkAEAF9wWi/o/tLmyrzgx0Tu8au 5DxGn89pPYpXHN/12Naqn49jzdSUnyMjmYIqemGmpwcg183Tgr9XzWZ1L cXw3AV8ai3YO9FXA/8X3xlwwv0rcVLC4mc2kxZcrtSPuB4XuTceTxDebe D+TpNOT4HDXlIG7A2FxW4PNi+qE1rXhpw9GRjMgUn/pUWyh8d8+jc5im4 rU8OEp5Nanpd67Q5cXLntKr/V5LtJYYZzSMH6h37nLOgbjQZNgeC7sDEE 6bAFbXHtlj6qM3HcDfVLtKdlaijXbz51/dlN/RhZek7L0ctzGY+rr40f5 Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10613"; a="327877015" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="327877015" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Feb 2023 08:10:18 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10613"; a="644084672" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="644084672" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga006.jf.intel.com with ESMTP; 06 Feb 2023 08:10:16 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 87267413; Mon, 6 Feb 2023 18:10:52 +0200 (EET) From: Andy Shevchenko To: Mathias Nyman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Mathias Nyman , Greg Kroah-Hartman , Andy Shevchenko Subject: [PATCH v1 6/7] xhci: mem: Replace explicit castings with appropriate specifiers Date: Mon, 6 Feb 2023 18:10:48 +0200 Message-Id: <20230206161049.13972-7-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230206161049.13972-1-andriy.shevchenko@linux.intel.com> References: <20230206161049.13972-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org There is no need to have explicit castings when we have specific pointer extensions Replace the explicit castings with appropriate specifiers. Signed-off-by: Andy Shevchenko --- drivers/usb/host/xhci-mem.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index a3351b11efa5..fef74e7c20fc 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -668,8 +668,7 @@ struct xhci_stream_info *xhci_alloc_stream_info(struct xhci_hcd *xhci, cur_ring->cycle_state; stream_info->stream_ctx_array[cur_stream].stream_ring = cpu_to_le64(addr); - xhci_dbg(xhci, "Setting stream %d ring ptr to 0x%08llx\n", - cur_stream, (unsigned long long) addr); + xhci_dbg(xhci, "Setting stream %d ring ptr to 0x%08llx\n", cur_stream, addr); ret = xhci_update_stream_mapping(cur_ring, mem_flags); if (ret) { @@ -979,16 +978,14 @@ int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id, if (!dev->out_ctx) goto fail; - xhci_dbg(xhci, "Slot %d output ctx = 0x%llx (dma)\n", slot_id, - (unsigned long long)dev->out_ctx->dma); + xhci_dbg(xhci, "Slot %d output ctx = 0x%pad (dma)\n", slot_id, &dev->out_ctx->dma); /* Allocate the (input) device context for address device command */ dev->in_ctx = xhci_alloc_container_ctx(xhci, XHCI_CTX_TYPE_INPUT, flags); if (!dev->in_ctx) goto fail; - xhci_dbg(xhci, "Slot %d input ctx = 0x%llx (dma)\n", slot_id, - (unsigned long long)dev->in_ctx->dma); + xhci_dbg(xhci, "Slot %d input ctx = 0x%pad (dma)\n", slot_id, &dev->in_ctx->dma); /* Initialize the cancellation and bandwidth list for each ep */ for (i = 0; i < 31; i++) { @@ -2353,8 +2350,8 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) goto fail; xhci->dcbaa->dma = dma; xhci_dbg_trace(xhci, trace_xhci_dbg_init, - "// Device context base array address = 0x%llx (DMA), %p (virt)", - (unsigned long long)xhci->dcbaa->dma, xhci->dcbaa); + "// Device context base array address = 0x%pad (DMA), %p (virt)", + &xhci->dcbaa->dma, xhci->dcbaa); xhci_write_64(xhci, dma, &xhci->op_regs->dcbaa_ptr); /* @@ -2395,8 +2392,8 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) goto fail; xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Allocated command ring at %p", xhci->cmd_ring); - xhci_dbg_trace(xhci, trace_xhci_dbg_init, "First segment DMA is 0x%llx", - (unsigned long long)xhci->cmd_ring->first_seg->dma); + xhci_dbg_trace(xhci, trace_xhci_dbg_init, "First segment DMA is 0x%pad", + &xhci->cmd_ring->first_seg->dma); /* Set the address in the Command Ring Control register */ val_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); From patchwork Mon Feb 6 16:10:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13130296 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D1EBAC6379F for ; Mon, 6 Feb 2023 16:10:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231674AbjBFQK3 (ORCPT ); Mon, 6 Feb 2023 11:10:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231618AbjBFQKX (ORCPT ); Mon, 6 Feb 2023 11:10:23 -0500 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B019B125B6; Mon, 6 Feb 2023 08:10:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675699819; x=1707235819; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hJFH/WlOhkFgGSBJXUCYwVXj90asZQUB6q0OWxQtULM=; b=K/lX8rOrXlC6p4LlBFDVXzGvCduIiCbMpMvwLjJBsGqR/1Ai/e6CvhIW LYKjDR4k1rstAQPE2IMiPkEOmy+coqmOpEKlHW/b5ZazX8X8ecn6eXe3F t+YvD4au37FjnqbaXi0Cm/wvR9g+muacrOKB7KiasdWwzKD68+bQ9v/wk C9Hb5fe4WewVFiVFFjm764W5NXlEcRzc0xu5DICR4Ewesp/xu2577hKpk KcLVFy5HXs6UARWNktt4U6b0UUulHxjk9IffeNdDqSus2x/LJxAlKouZV essv32YoVBRwuYJUSNOTLxYWi1mExWBfXUD/ugpmNWJpkuqSyQNbD3C7u w==; X-IronPort-AV: E=McAfee;i="6500,9779,10613"; a="327877020" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="327877020" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Feb 2023 08:10:19 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10613"; a="644084675" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="644084675" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga006.jf.intel.com with ESMTP; 06 Feb 2023 08:10:17 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 910C937D; Mon, 6 Feb 2023 18:10:52 +0200 (EET) From: Andy Shevchenko To: Mathias Nyman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Mathias Nyman , Greg Kroah-Hartman , Andy Shevchenko Subject: [PATCH v1 7/7] xhci: mem: Join string literals back Date: Mon, 6 Feb 2023 18:10:49 +0200 Message-Id: <20230206161049.13972-8-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230206161049.13972-1-andriy.shevchenko@linux.intel.com> References: <20230206161049.13972-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org For easy grepping on debug purposes join string literals back in the messages. No functional change. Signed-off-by: Andy Shevchenko --- drivers/usb/host/xhci-mem.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index fef74e7c20fc..9bdf2ed85772 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -609,8 +609,7 @@ struct xhci_stream_info *xhci_alloc_stream_info(struct xhci_hcd *xhci, int ret; struct device *dev = xhci_to_hcd(xhci)->self.sysdev; - xhci_dbg(xhci, "Allocating %u streams and %u " - "stream context array entries.\n", + xhci_dbg(xhci, "Allocating %u streams and %u stream context array entries.\n", num_streams, num_stream_ctxs); if (xhci->cmd_ring_reserved_trbs == MAX_RSVD_CMD_TRBS) { xhci_dbg(xhci, "Command ring has no reserved TRBs available\n"); @@ -1952,8 +1951,7 @@ static void xhci_set_hc_event_deq(struct xhci_hcd *xhci, struct xhci_interrupter deq = xhci_trb_virt_to_dma(ir->event_ring->deq_seg, ir->event_ring->dequeue); if (!deq) - xhci_warn(xhci, "WARN something wrong with SW event ring " - "dequeue ptr.\n"); + xhci_warn(xhci, "WARN something wrong with SW event ring dequeue ptr.\n"); /* Update HC event ring dequeue pointer */ temp = xhci_read_64(xhci, &ir->ir_set->erst_dequeue); temp &= ERST_PTR_MASK; @@ -1962,8 +1960,7 @@ static void xhci_set_hc_event_deq(struct xhci_hcd *xhci, struct xhci_interrupter */ temp &= ~ERST_EHB; xhci_dbg_trace(xhci, trace_xhci_dbg_init, - "// Write event ring dequeue pointer, " - "preserving EHB bit"); + "// Write event ring dequeue pointer, preserving EHB bit"); xhci_write_64(xhci, ((u64) deq & (u64) ~ERST_PTR_MASK) | temp, &ir->ir_set->erst_dequeue); } @@ -1996,8 +1993,7 @@ static void xhci_add_in_port(struct xhci_hcd *xhci, unsigned int num_ports, } else if (major_revision <= 0x02) { rhub = &xhci->usb2_rhub; } else { - xhci_warn(xhci, "Ignoring unknown port speed, " - "Ext Cap %p, revision = 0x%x\n", + xhci_warn(xhci, "Ignoring unknown port speed, Ext Cap %p, revision = 0x%x\n", addr, major_revision); /* Ignoring port protocol we can't understand. FIXME */ return; @@ -2012,9 +2008,8 @@ static void xhci_add_in_port(struct xhci_hcd *xhci, unsigned int num_ports, port_offset = XHCI_EXT_PORT_OFF(temp); port_count = XHCI_EXT_PORT_COUNT(temp); xhci_dbg_trace(xhci, trace_xhci_dbg_init, - "Ext Cap %p, port offset = %u, " - "count = %u, revision = 0x%x", - addr, port_offset, port_count, major_revision); + "Ext Cap %p, port offset = %u, count = %u, revision = 0x%x", + addr, port_offset, port_count, major_revision); /* Port count includes the current port offset */ if (port_offset == 0 || (port_offset + port_count - 1) > num_ports) /* WTF? "Valid values are ‘1’ to MaxPorts" */ @@ -2071,10 +2066,8 @@ static void xhci_add_in_port(struct xhci_hcd *xhci, unsigned int num_ports, struct xhci_port *hw_port = &xhci->hw_ports[i]; /* Duplicate entry. Ignore the port if the revisions differ. */ if (hw_port->rhub) { - xhci_warn(xhci, "Duplicate port entry, Ext Cap %p," - " port %u\n", addr, i); - xhci_warn(xhci, "Port was marked as USB %u, " - "duplicated as USB %u\n", + xhci_warn(xhci, "Duplicate port entry, Ext Cap %p, port %u\n", addr, i); + xhci_warn(xhci, "Port was marked as USB %u, duplicated as USB %u\n", hw_port->rhub->maj_rev, major_revision); /* Only adjust the roothub port counts if we haven't * found a similar duplicate. @@ -2413,8 +2406,8 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) val = readl(&xhci->cap_regs->db_off); val &= DBOFF_MASK; xhci_dbg_trace(xhci, trace_xhci_dbg_init, - "// Doorbell array is located at offset 0x%x" - " from cap regs base addr", val); + "// Doorbell array is located at offset 0x%x from cap regs base addr", + val); xhci->dba = (void __iomem *) xhci->cap_regs + val; /* Set ir_set to interrupt register set 0 */