Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2918605pxb; Sat, 25 Sep 2021 23:18:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygiQLfqUjhxq/B3XGIn5PDENFGgMxlf2dWQOU+RDJMJq9n0Wdq+X924qlZ6nGHnLWDb/zo X-Received: by 2002:a50:9d0f:: with SMTP id v15mr15683514ede.275.1632637088877; Sat, 25 Sep 2021 23:18:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632637088; cv=none; d=google.com; s=arc-20160816; b=ZepqQZMdISJ7YyowkEEYl/wj/laBQAl9UqnL0Xd3jN/j8ZDdlYpXJKGm867ve9AmRP Whk0h6lDt+t7MSigd+Q+BiFCWKwrMR4psF+ysYTot4WqByPowdNnKMhSwfTm+vf0+C+z n897zcgya/+sVEqgpgR91y30ejiVUfwtdACaBmJ3IP2mwCBvU1pidtRMJcTR3K/ZfKZr 7q226vQ+AbqH7jLZMsfQFAtJ/vUg9JVGsuF7k6q1QP1nHhOCxh0cfbZ9sD3R7L1dPCvp 9uQMw1wZ7spV/W50A1wJFB13ADHM4q5v7cqCGj9qBI2Keph80zD6iZq+cIaZuaWK/q7J gf8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=qjPgPs1IuW/MS5o0vMsIfERk+axr8KHpn4qzzk7MVDI=; b=OSb5hd3Z3KvQ1c2xK4Gr+pAV4bv4NBfIBK/2xD+0eCN2ZB7nSWP16rDq6RW1vsGPl5 nKnU5BQzS9EOWG9lzS+UJvqM63PZZr5vYNEZEt30xJ/wrPRYpKyg8eGbEdeWKKEBfrH5 CjAXCwOSh5dRmFcVlOGsBwzKam/Hog5oVJ2O2Ke+Ays+VCtegTylBHkjJr1GC4ACzDtk V50fbAIhaez0+XqxXljsSBBUcNSbkdWbi/BfzkTMd2TjOxxAt5+qbhgHvxI6sylpWaX+ KnsOGSJTpgUm+9vBjOFUXOdDSufIFw1BBkoho93yeUc95JPDBTzBP9ulppjBI7iHV95z ygHQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a9si13965219edb.327.2021.09.25.23.17.45; Sat, 25 Sep 2021 23:18:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231171AbhIZGNP (ORCPT + 99 others); Sun, 26 Sep 2021 02:13:15 -0400 Received: from mx22.baidu.com ([220.181.50.185]:49068 "EHLO baidu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231146AbhIZGNJ (ORCPT ); Sun, 26 Sep 2021 02:13:09 -0400 Received: from BC-Mail-Ex09.internal.baidu.com (unknown [172.31.51.49]) by Forcepoint Email with ESMTPS id 23073A7C24971CC6AF0C; Sun, 26 Sep 2021 14:11:31 +0800 (CST) Received: from BJHW-MAIL-EX27.internal.baidu.com (10.127.64.42) by BC-Mail-Ex09.internal.baidu.com (172.31.51.49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2242.12; Sun, 26 Sep 2021 14:11:31 +0800 Received: from LAPTOP-UKSR4ENP.internal.baidu.com (172.31.63.8) by BJHW-MAIL-EX27.internal.baidu.com (10.127.64.42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.14; Sun, 26 Sep 2021 14:11:30 +0800 From: Cai Huoqing To: CC: Mustafa Ismail , Shiraz Saleem , Doug Ledford , "Jason Gunthorpe" , , Subject: [PATCH] RDMA/irdma: Use dma_alloc_coherent() instead of kmalloc/dma_map_single() Date: Sun, 26 Sep 2021 14:11:23 +0800 Message-ID: <20210926061124.335-1-caihuoqing@baidu.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [172.31.63.8] X-ClientProxiedBy: BC-Mail-Ex15.internal.baidu.com (172.31.51.55) To BJHW-MAIL-EX27.internal.baidu.com (10.127.64.42) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Replacing kmalloc/kfree/dma_map_single/dma_unmap_single() with dma_alloc_coherent/dma_free_coherent() helps to reduce code size, and simplify the code, and coherent DMA will not clear the cache every time. Signed-off-by: Cai Huoqing --- drivers/infiniband/hw/irdma/puda.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/drivers/infiniband/hw/irdma/puda.c b/drivers/infiniband/hw/irdma/puda.c index 58e7d875643b..feafe21b12c6 100644 --- a/drivers/infiniband/hw/irdma/puda.c +++ b/drivers/infiniband/hw/irdma/puda.c @@ -151,24 +151,15 @@ static struct irdma_puda_buf *irdma_puda_alloc_buf(struct irdma_sc_dev *dev, buf = buf_mem.va; buf->mem.size = len; - buf->mem.va = kzalloc(buf->mem.size, GFP_KERNEL); + buf->mem.va = dma_alloc_coherent(dev->hw->device, len, + &buf->mem.pa, GFP_KERNEL); if (!buf->mem.va) - goto free_virt; - buf->mem.pa = dma_map_single(dev->hw->device, buf->mem.va, - buf->mem.size, DMA_BIDIRECTIONAL); - if (dma_mapping_error(dev->hw->device, buf->mem.pa)) { - kfree(buf->mem.va); - goto free_virt; - } + return NULL; buf->buf_mem.va = buf_mem.va; buf->buf_mem.size = buf_mem.size; return buf; - -free_virt: - kfree(buf_mem.va); - return NULL; } /** @@ -179,9 +170,7 @@ static struct irdma_puda_buf *irdma_puda_alloc_buf(struct irdma_sc_dev *dev, static void irdma_puda_dele_buf(struct irdma_sc_dev *dev, struct irdma_puda_buf *buf) { - dma_unmap_single(dev->hw->device, buf->mem.pa, buf->mem.size, - DMA_BIDIRECTIONAL); - kfree(buf->mem.va); + dma_free_coherent(dev->hw->device, buf->mem.size, buf->mem.va, buf->mem.pa); kfree(buf->buf_mem.va); } -- 2.25.1