From patchwork Thu Nov 15 18:13:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 10684819 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A1BFB13BB for ; Thu, 15 Nov 2018 18:15:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 91CC82CE25 for ; Thu, 15 Nov 2018 18:15:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 861302CE56; Thu, 15 Nov 2018 18:15:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D5B052CE25 for ; Thu, 15 Nov 2018 18:15:51 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 574BB267B0F; Thu, 15 Nov 2018 19:15:37 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id A3033267B01; Thu, 15 Nov 2018 19:15:33 +0100 (CET) Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by alsa0.perex.cz (Postfix) with ESMTP id 08E1C267AFF for ; Thu, 15 Nov 2018 19:15:31 +0100 (CET) Received: by mail-wm1-f65.google.com with SMTP id f2-v6so18817961wme.3 for ; Thu, 15 Nov 2018 10:15:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NJe/Lh0u4I1EWKwZUx0PaLmr2WjeZlvlzz6DRN2R6yI=; b=DG9FoSMLSELm3P7rhJYiwePwmjMLFaU5/G43rzF/FDkJJGO6vcpfoAU1QpY+o7a5RI 1CuWRYu+/t/tgI2nV7GiM+gQHLPbctcV0/+XubhvHxueDJKQe/Sww0vGcQhKS+E88h9b kIQx2YDvMgQz8CYVlozSzI/0F3ScqsJy6NPXQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NJe/Lh0u4I1EWKwZUx0PaLmr2WjeZlvlzz6DRN2R6yI=; b=f36wM4D0BBLt8iqrzMRad9ltP0Mc1hO6J/yxCHFFxTKjHuEMSEXRKr3ibip3P4dGvL gNkXkHux/bIMNA+6fly/REFI/OlhPlzMgRceNzrTbwqbBFiq/MRXZC6cltlTuKvpXCkJ gewm3WyGuqHgZ2EryRBkrZedyEhebck7Z6inZ8O16bDSd74R3wdcIczmnbi3KEWI5FB+ Src2UTj9dLhLxbkfsgSddATXN6akeMm/6fH0OBML4wHdBTNBcHyB5aLDkCs7ATGVsdx8 g1Teyjzb9o8AbCN0iwsgDjjI3IO8tgdW7D4RnPcmdlDNW6f6pBF06ECD/2Fs2EZNVL2r +Isw== X-Gm-Message-State: AGRZ1gKifefwOYJQ8ue28Tuf4Vy8lBkVDjeJAQcz4tytT54xZgOgwccz u01ywKJUOEpl5j27DUchCV8s7Q== X-Google-Smtp-Source: AJdET5eyRB5WlO70ERbDOomAlPcZMFgA92yVqVXWR5YPfpxi/JHIW851TjPmkd/varO7HBj77BlFYw== X-Received: by 2002:a1c:248b:: with SMTP id k133-v6mr5864308wmk.148.1542305731343; Thu, 15 Nov 2018 10:15:31 -0800 (PST) Received: from localhost.localdomain (cpc90716-aztw32-2-0-cust92.18-1.cable.virginm.net. [86.26.100.93]) by smtp.gmail.com with ESMTPSA id r76-v6sm20934737wmb.21.2018.11.15.10.15.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 15 Nov 2018 10:15:30 -0800 (PST) From: Srinivas Kandagatla To: broonie@kernel.org, vkoul@kernel.org Date: Thu, 15 Nov 2018 18:13:21 +0000 Message-Id: <20181115181324.26784-3-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181115181324.26784-1-srinivas.kandagatla@linaro.org> References: <20181115181324.26784-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Cc: devicetree@vger.kernel.org, alsa-devel@alsa-project.org, bgoswami@codeaurora.org, tiwai@suse.com, linux-kernel@vger.kernel.org, lgirdwood@gmail.com, robh+dt@kernel.org, rohitkr@codeaurora.org, srini@kernel.org, Srinivas Kandagatla Subject: [alsa-devel] [PATCH v3 2/5] ALSA: compress: make use of runtime buffer for copy X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP Default copy function uses kmalloc to allocate buffers, lets check if the runtime buffers are setup before making this allocations. This can be useful if the buffers are dma buffers. Signed-off-by: Srinivas Kandagatla --- sound/core/compress_offload.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/sound/core/compress_offload.c b/sound/core/compress_offload.c index 26b5e245b074..a5b09e75e787 100644 --- a/sound/core/compress_offload.c +++ b/sound/core/compress_offload.c @@ -171,7 +171,8 @@ static int snd_compr_free(struct inode *inode, struct file *f) } data->stream.ops->free(&data->stream); - kfree(data->stream.runtime->buffer); + if (!data->stream.runtime->dma_buffer_p) + kfree(data->stream.runtime->buffer); kfree(data->stream.runtime); kfree(data); return 0; @@ -505,7 +506,7 @@ static int snd_compr_allocate_buffer(struct snd_compr_stream *stream, struct snd_compr_params *params) { unsigned int buffer_size; - void *buffer; + void *buffer = NULL; buffer_size = params->buffer.fragment_size * params->buffer.fragments; if (stream->ops->copy) { @@ -514,7 +515,18 @@ static int snd_compr_allocate_buffer(struct snd_compr_stream *stream, * the data from core */ } else { - buffer = kmalloc(buffer_size, GFP_KERNEL); + if (stream->runtime->dma_buffer_p) { + + if (buffer_size > stream->runtime->dma_buffer_p->bytes) + dev_err(&stream->device->dev, + "Not enough DMA buffer"); + else + buffer = stream->runtime->dma_buffer_p->area; + + } else { + buffer = kmalloc(buffer_size, GFP_KERNEL); + } + if (!buffer) return -ENOMEM; }