Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp6141201ybi; Wed, 29 May 2019 03:31:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqyIAZOGwN/gc+GAaolXBxtmiiGpX3N1pmVr0gIJDKgymNQf9EZPfivETN65pYbTw5tUg7qp X-Received: by 2002:aa7:9e9a:: with SMTP id p26mr116194617pfq.176.1559125911899; Wed, 29 May 2019 03:31:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559125911; cv=none; d=google.com; s=arc-20160816; b=YAp0SkOc4eiZG5UnjXkBNAGe4OpTs7qZIod4BRbhsfMauyHZUfws+JeQIDqyEWL+oT aVIn2taNb6rrFO0VByM+Gq6eZexB73gVejeNAn/PUafGTn1DjzvJwk5M1VSkGBNBTZR5 npEiN/0s5EoNsH8yuSDUcrFsSt8Y8LxOwaNKKIa4spPaJtUCIoWoLLvRS9f3iTMD2hqC NQ4zX5CaYhqBNQX/kngeRZy81BBXX0/sGxOqsARxaqJzgmTo/n/zfRYDcRpXw8s/lBnZ MYhrQDOH3LPJykxKG0Vn+r3C0cO2AYBFCfLmM2ig+Co5qh2Wq4cIzhwBQxYxvC0mreLa NtMw== 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=IDgmhWh3S+QEyVt1dNJquuL4nAR7p2+S/YQWCYzLus+fWB+BMSIEZXenVIhfr0vMDn +dgzpU2anqWowdSZeLCJChT+WqmdkgUzYAcVLL3W0H0qcB9sJtuGTyDbhYr4kvSrSsCD lukF3iTP6NRHDLjaeTd9CkBy6J6ZO8EhdMH/ZAWt+csKgiWzGB2xPcSO3Jo3hLRfzbMk ByQhehtAwErXLqCGIyv39vD1kWK9NC497mN8+s6L+gO18H1bqoLzbnkex8AP4MnBGWM6 nK3Dz2ZwMpN3qY09slfxf5EVpKdk9NtxVGxRCJt34sjdCKNKp5qUShHe61WUmwxruWAD Okiw== 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 cm2si24409792plb.377.2019.05.29.03.31.35; Wed, 29 May 2019 03:31:51 -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 S1726807AbfE2K2y (ORCPT + 99 others); Wed, 29 May 2019 06:28:54 -0400 Received: from inva021.nxp.com ([92.121.34.21]:51812 "EHLO inva021.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726753AbfE2K2x (ORCPT ); Wed, 29 May 2019 06:28:53 -0400 Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 252A92003EF; Wed, 29 May 2019 12:28:51 +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 17B5A2003E7; Wed, 29 May 2019 12:28:51 +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 94F32205E4; Wed, 29 May 2019 12:28:50 +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 v7 1/5] lib/genalloc.c: Add gen_pool_dma_zalloc() for zeroed DMA allocations Date: Wed, 29 May 2019 13:28:39 +0300 Message-Id: <20190529102843.13174-2-laurentiu.tudor@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190529102843.13174-1-laurentiu.tudor@nxp.com> References: <20190529102843.13174-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