Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp5977239ybc; Wed, 27 Nov 2019 12:45:36 -0800 (PST) X-Google-Smtp-Source: APXvYqw3iQkIjFcSIUbuNwjqplZvhcRM0K68/LzN1RF3AXVXTCFUSKMPiPZaMJvulmTUaWmCwPcZ X-Received: by 2002:a50:e68c:: with SMTP id z12mr35416664edm.53.1574887536749; Wed, 27 Nov 2019 12:45:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574887536; cv=none; d=google.com; s=arc-20160816; b=xLsOwHWv3QO1JFe3MKpsSsJtRZkiZWEdYwgq9+v6ggoYlVSbYMOdxpxSqBdNXSVxcz vQ4cARnMs6O9Yh7mGaHYfEcbUc8rlh+BcVCd3Y+pyej1l52IeeOlloIzJeqFoDmgkAgW dC1YfaEqSXTJ/o8ItCPsbbdIW3t+aUIotbN5w1gdd08tCaqOrNT9wZow81yq/XpKikZU 8z4iPou8jwfL5gT2vk2CKFCpZQSMmLhGqLGikusjqtW3DAYxE0FdbEdH4Yf5qeK4pSlN 7cmMraszfRVwRUwUlcg+Cao4Nszu2mN6YivSxBjbWrDg55bFEPooCp5ff2AO4a7anxDA iH/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=DwVQ3lHulwRSFUvAvn7nxT0KIa3QkZLSvy2L1yxOoCU=; b=HVCErxPsRFSER/7DwXdEYPy+gcGn3QBeh91d9LCiBLAe9ubg2RBzHglG7gK5gwqyGa 3PYQIjE/f7yodY/P4F8IpvhzlThRUo3iVG1PAMctvqqVmqX7V5s9GhV7dltUarFp8GYv A0HR0F9VJy4EsB6HB8VhnA3qghkyaDTUJdo2PEUdRdtZ8aDatl+GEQraEWtratQHFtu8 3R0zGRbRwQ5LwxyS9K5bA+v7ltPqlH/FHd+zgydLaTTSEvDYcVpW6m2B5di3qLiYhFZn fxUp2hEkrKtb5sTz8Bqx+mn0fNyS9qIDn5SiXTlAjrASuWn3lxm/Vr7G4RENIP0hjUvO 0tmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="pzLE+WW/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id lw2si10277959ejb.440.2019.11.27.12.45.12; Wed, 27 Nov 2019 12:45:36 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="pzLE+WW/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729097AbfK0Ukv (ORCPT + 99 others); Wed, 27 Nov 2019 15:40:51 -0500 Received: from mail.kernel.org ([198.145.29.99]:45588 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729090AbfK0Ukt (ORCPT ); Wed, 27 Nov 2019 15:40:49 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E321821772; Wed, 27 Nov 2019 20:40:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574887248; bh=pIrHMhpaaasDi/axB0LADqktz+OiSBs0YHoiRDHDFOM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pzLE+WW/Uz65/fe9xeBwacsVgP6pmw6QoKwhAjGuJnpFCjVHzMVUIdiv2KVF4knEl AmbFuFXxT95UeQ9hWCzvXGCNkyxD+NeJrEJqPhb4Atrh5p2KiqGkqyF0HJUMZa9Rae 3CE8X1EPYi8LqyfGBToCslIXlzhL03KMpoO3mRoA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Carl Huang , Brian Norris , Kalle Valo , Sasha Levin Subject: [PATCH 4.9 020/151] ath10k: allocate small size dma memory in ath10k_pci_diag_write_mem Date: Wed, 27 Nov 2019 21:30:03 +0100 Message-Id: <20191127203012.724097908@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191127203000.773542911@linuxfoundation.org> References: <20191127203000.773542911@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Carl Huang [ Upstream commit 0738b4998c6d1caf9ca2447b946709a7278c70f1 ] ath10k_pci_diag_write_mem may allocate big size of the dma memory based on the parameter nbytes. Take firmware diag download as example, the biggest size is about 500K. In some systems, the allocation is likely to fail because it can't acquire such a large contiguous dma memory. The fix is to allocate a small size dma memory. In the loop, driver copies the data to the allocated dma memory and writes to the destination until all the data is written. Tested with QCA6174 PCI with firmware-6.bin_WLAN.RM.4.4.1-00119-QCARMSWP-1, this also affects QCA9377 PCI. Signed-off-by: Carl Huang Reviewed-by: Brian Norris Signed-off-by: Kalle Valo Signed-off-by: Sasha Levin --- drivers/net/wireless/ath/ath10k/pci.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/drivers/net/wireless/ath/ath10k/pci.c b/drivers/net/wireless/ath/ath10k/pci.c index b7bac14d1487b..d84a362a084ac 100644 --- a/drivers/net/wireless/ath/ath10k/pci.c +++ b/drivers/net/wireless/ath/ath10k/pci.c @@ -1039,10 +1039,9 @@ int ath10k_pci_diag_write_mem(struct ath10k *ar, u32 address, struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); int ret = 0; u32 *buf; - unsigned int completed_nbytes, orig_nbytes, remaining_bytes; + unsigned int completed_nbytes, alloc_nbytes, remaining_bytes; struct ath10k_ce_pipe *ce_diag; void *data_buf = NULL; - u32 ce_data; /* Host buffer address in CE space */ dma_addr_t ce_data_base = 0; int i; @@ -1056,9 +1055,10 @@ int ath10k_pci_diag_write_mem(struct ath10k *ar, u32 address, * 1) 4-byte alignment * 2) Buffer in DMA-able space */ - orig_nbytes = nbytes; + alloc_nbytes = min_t(unsigned int, nbytes, DIAG_TRANSFER_LIMIT); + data_buf = (unsigned char *)dma_alloc_coherent(ar->dev, - orig_nbytes, + alloc_nbytes, &ce_data_base, GFP_ATOMIC); if (!data_buf) { @@ -1066,9 +1066,6 @@ int ath10k_pci_diag_write_mem(struct ath10k *ar, u32 address, goto done; } - /* Copy caller's data to allocated DMA buf */ - memcpy(data_buf, data, orig_nbytes); - /* * The address supplied by the caller is in the * Target CPU virtual address space. @@ -1081,12 +1078,14 @@ int ath10k_pci_diag_write_mem(struct ath10k *ar, u32 address, */ address = ath10k_pci_targ_cpu_to_ce_addr(ar, address); - remaining_bytes = orig_nbytes; - ce_data = ce_data_base; + remaining_bytes = nbytes; while (remaining_bytes) { /* FIXME: check cast */ nbytes = min_t(int, remaining_bytes, DIAG_TRANSFER_LIMIT); + /* Copy caller's data to allocated DMA buf */ + memcpy(data_buf, data, nbytes); + /* Set up to receive directly into Target(!) address */ ret = __ath10k_ce_rx_post_buf(ce_diag, &address, address); if (ret != 0) @@ -1096,7 +1095,7 @@ int ath10k_pci_diag_write_mem(struct ath10k *ar, u32 address, * Request CE to send caller-supplied data that * was copied to bounce buffer to Target(!) address. */ - ret = ath10k_ce_send_nolock(ce_diag, NULL, (u32)ce_data, + ret = ath10k_ce_send_nolock(ce_diag, NULL, ce_data_base, nbytes, 0, 0); if (ret != 0) goto done; @@ -1137,12 +1136,12 @@ int ath10k_pci_diag_write_mem(struct ath10k *ar, u32 address, remaining_bytes -= nbytes; address += nbytes; - ce_data += nbytes; + data += nbytes; } done: if (data_buf) { - dma_free_coherent(ar->dev, orig_nbytes, data_buf, + dma_free_coherent(ar->dev, alloc_nbytes, data_buf, ce_data_base); } -- 2.20.1