Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp535886ybm; Wed, 22 May 2019 07:29:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqy8kOz3vcUM8/74AltETNMmKby9Za7gLr0B79j/dlrX2GdEf8NgXeXmC7mjnEZ6Dui3l/zI X-Received: by 2002:a62:585:: with SMTP id 127mr75850014pff.231.1558535362437; Wed, 22 May 2019 07:29:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558535362; cv=none; d=google.com; s=arc-20160816; b=amqdWYqLvnKfKf2cF/fhmHcbGf1uuyOPT9uz8wHKCICOgqR2kE0c5cPmCsfBx0CJN3 MT2SirDtNRbV2X9VG3whjsV3u7DMsQoQh+Ag8YFrCBI/57Q2izrhcJyUMVhvGGO8GLba 1L8UcPp7yxpQsu7VpT5sBGapwr948esar/jkzxDgVLoaBi+t1jo6iYKtkmE1zeAUtkp9 5/K8Kuf9HYQoaLLArYAMu1bll0ytR/dPKLZV+rmfgllHSq2QXw94whJhaoxcqU+KWbky 2C8UyibRFmc0IiX+0gxyu8Qc1xKLIwPNn+OAhTQF+wNiUTX7CQX5ytuojUwnepXyyXf9 RW1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=/XqjSUIctScVwtrdHGmoH9oGyrTx98z1EQ8E8efQVh4=; b=XNmAi76TUm7SHQp+FXoZdiuiRRmGMuAK/4ypM7Os1cPxkRIimoxRjG2GCXlcRktgP/ uMguX5ovQA4FXT6bsmvUmB9ABeNYiUnMjR6MhVUlYNSzZiQHIMuPF6R/NPzRw0yYwAQa Mi1AStzNW2UfveUDPkPyTBQVLrgwx+8FrNTaN4hFeiBIgWY2uPf0WUhSZqZQevIq1rN9 718b4etlKVKsO4P6hZV0FX5fyiiJaayWvWzcia69D/VSg9GhYCyZB+i5i469JY+lqwFD 4e6li1845qcnn4LfOApYyc/nGRdSmt0o15jf93OwGM0KBHck8KLW1rY/H54Hqty2Qh9M Y2rQ== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f64si26310223plf.128.2019.05.22.07.29.07; Wed, 22 May 2019 07:29:22 -0700 (PDT) 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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729424AbfEVO15 (ORCPT + 99 others); Wed, 22 May 2019 10:27:57 -0400 Received: from inva021.nxp.com ([92.121.34.21]:41960 "EHLO inva021.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728761AbfEVO1z (ORCPT ); Wed, 22 May 2019 10:27:55 -0400 Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 8DAB9200090; Wed, 22 May 2019 16:27:52 +0200 (CEST) Received: from inva024.eu-rdc02.nxp.com (inva024.eu-rdc02.nxp.com [134.27.226.22]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 7FCAE20002F; Wed, 22 May 2019 16:27:52 +0200 (CEST) Received: from fsr-ub1864-101.ea.freescale.net (fsr-ub1864-101.ea.freescale.net [10.171.82.13]) by inva024.eu-rdc02.nxp.com (Postfix) with ESMTP id 096B1205ED; Wed, 22 May 2019 16:27:52 +0200 (CEST) From: laurentiu.tudor@nxp.com To: hch@lst.de, stern@rowland.harvard.edu, gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, marex@denx.de Cc: leoyang.li@nxp.com, linux-kernel@vger.kernel.org, robin.murphy@arm.com, noring@nocrew.org, JuergenUrban@gmx.de Subject: [PATCH v6 1/5] lib/genalloc.c: Add gen_pool_dma_zalloc() for zeroed DMA allocations Date: Wed, 22 May 2019 17:27:44 +0300 Message-Id: <20190522142748.10078-2-laurentiu.tudor@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190522142748.10078-1-laurentiu.tudor@nxp.com> References: <20190522142748.10078-1-laurentiu.tudor@nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Fredrik Noring gen_pool_dma_zalloc() is a zeroed memory variant of gen_pool_dma_alloc(). Document return values of both, and indicate NULL as a "%NULL" constant. Signed-off-by: Fredrik Noring Tested-by: Fredrik Noring --- include/linux/genalloc.h | 1 + lib/genalloc.c | 29 ++++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/include/linux/genalloc.h b/include/linux/genalloc.h index dd0a452373e7..6c62eeca754f 100644 --- a/include/linux/genalloc.h +++ b/include/linux/genalloc.h @@ -121,6 +121,7 @@ extern unsigned long gen_pool_alloc_algo(struct gen_pool *, size_t, genpool_algo_t algo, void *data); extern void *gen_pool_dma_alloc(struct gen_pool *pool, size_t size, dma_addr_t *dma); +void *gen_pool_dma_zalloc(struct gen_pool *pool, size_t size, dma_addr_t *dma); extern void gen_pool_free(struct gen_pool *, unsigned long, size_t); extern void gen_pool_for_each_chunk(struct gen_pool *, void (*)(struct gen_pool *, struct gen_pool_chunk *, void *), void *); diff --git a/lib/genalloc.c b/lib/genalloc.c index 7e85d1e37a6e..5db43476a19b 100644 --- a/lib/genalloc.c +++ b/lib/genalloc.c @@ -337,12 +337,14 @@ EXPORT_SYMBOL(gen_pool_alloc_algo); * gen_pool_dma_alloc - allocate special memory from the pool for DMA usage * @pool: pool to allocate from * @size: number of bytes to allocate from the pool - * @dma: dma-view physical address return value. Use NULL if unneeded. + * @dma: dma-view physical address return value. Use %NULL if unneeded. * * Allocate the requested number of bytes from the specified pool. * Uses the pool allocation function (with first-fit algorithm by default). * Can not be used in NMI handler on architectures without * NMI-safe cmpxchg implementation. + * + * Return: virtual address of the allocated memory, or %NULL on failure */ void *gen_pool_dma_alloc(struct gen_pool *pool, size_t size, dma_addr_t *dma) { @@ -362,6 +364,31 @@ void *gen_pool_dma_alloc(struct gen_pool *pool, size_t size, dma_addr_t *dma) } EXPORT_SYMBOL(gen_pool_dma_alloc); +/** + * gen_pool_dma_zalloc - allocate special zeroed memory from the pool for + * DMA usage + * @pool: pool to allocate from + * @size: number of bytes to allocate from the pool + * @dma: dma-view physical address return value. Use %NULL if unneeded. + * + * Allocate the requested number of zeroed bytes from the specified pool. + * Uses the pool allocation function (with first-fit algorithm by default). + * Can not be used in NMI handler on architectures without + * NMI-safe cmpxchg implementation. + * + * Return: virtual address of the allocated zeroed memory, or %NULL on failure + */ +void *gen_pool_dma_zalloc(struct gen_pool *pool, size_t size, dma_addr_t *dma) +{ + void *vaddr = gen_pool_dma_alloc(pool, size, dma); + + if (vaddr) + memset(vaddr, 0, size); + + return vaddr; +} +EXPORT_SYMBOL(gen_pool_dma_zalloc); + /** * gen_pool_free - free allocated special memory back to the pool * @pool: pool to free to -- 2.17.1