Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp997577ybm; Tue, 21 May 2019 07:09:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqw1XXAbKnYZxagWkFxp+RHw8Urt64dK5rO02sqsJZh85MwZ5eyNSLOLdBZBDgey3YwpBAvg X-Received: by 2002:a63:eb50:: with SMTP id b16mr7567212pgk.150.1558447788292; Tue, 21 May 2019 07:09:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558447788; cv=none; d=google.com; s=arc-20160816; b=T5cTGmmagINXKPNY/vAXP0bumoIsVdLh4oz4Rgi36fUGN90JBTHc/gCVtO+pPTLAQr 12v0Jqe3APGNIYIxi+3XUxwIk62nWCuNMu4fNbETNhEpbYBtroXMCVNgXntrUcxv763p 4XUrH1yA56N04FsSnPKd767b490CohjTbGFjJjyCmokIWyYgXf7Dt3ohc9eXaNX+7t2y iQr8ICKtYE2Ybcu05QsXdhTZMIRh4V/PiLxLCdZE/ld5w0RPhCpfusE5YoifdyJY+mKY P6MVbyFfR5OuGvAR0L+UoOMu66KbE55IFU6dMFBnb7elQbYkRLrricsn3DUQH5ONbggM AE3Q== 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=zapojQ5pHqySOQei50RMaDNkWNSEQcgqigSPLeT2++I=; b=KMCjJEFyy8qeo2rrvQf8h8iJdpnma2QbcIkyQmB3XdksVFL5VNjGa+boNcthU8IpWT iJ8L6/Gqp+PT1b4NEexIGb5o8evFR0exDSSgMZnTsnUGFZ5T3GKhLXllld7RBHvPvElr AYyGOAFLXOiri6uZ3u+3xOHaEMuoYRdjVZipmhly7hFqxjSLx3JJaQdHTLiVZ7t0DdXU CNhbUjCL/ZtYPSsUyHkSGwbTJDYCveLcBLLLEyVBOtGv6mH0DXGLOhn/VxZ02VBgX4qz 7mIG30T7UF0gDBE32juYnlYeQEnHKw4y3ohgUZ5TCvjdyi0A+MZX1NVEhYKCjrXGi+Da Vu7Q== 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 z184si21538834pgb.409.2019.05.21.07.09.29; Tue, 21 May 2019 07:09:48 -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 S1728317AbfEUOH6 (ORCPT + 99 others); Tue, 21 May 2019 10:07:58 -0400 Received: from inva020.nxp.com ([92.121.34.13]:47238 "EHLO inva020.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727044AbfEUOH5 (ORCPT ); Tue, 21 May 2019 10:07:57 -0400 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id C737B1A0062; Tue, 21 May 2019 16:07:54 +0200 (CEST) Received: from inva024.eu-rdc02.nxp.com (inva024.eu-rdc02.nxp.com [134.27.226.22]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id BA9AA1A003B; Tue, 21 May 2019 16:07:54 +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 4091A20612; Tue, 21 May 2019 16:07:54 +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 v5 1/5] lib/genalloc.c: Add gen_pool_dma_zalloc() for zeroed DMA allocations Date: Tue, 21 May 2019 17:07:44 +0300 Message-Id: <20190521140748.20012-2-laurentiu.tudor@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190521140748.20012-1-laurentiu.tudor@nxp.com> References: <20190521140748.20012-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 --- 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