From patchwork Wed Sep 26 10:23:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 10615667 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 659F215A6 for ; Wed, 26 Sep 2018 10:26:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5E59F2A7A4 for ; Wed, 26 Sep 2018 10:26:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5225F2A7B8; Wed, 26 Sep 2018 10:26:19 +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 0D6082A7B7 for ; Wed, 26 Sep 2018 10:26:18 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 555D62678D2; Wed, 26 Sep 2018 12:26:05 +0200 (CEST) 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 3329B2678BD; Wed, 26 Sep 2018 12:26:00 +0200 (CEST) Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by alsa0.perex.cz (Postfix) with ESMTP id 9F5D4267730 for ; Wed, 26 Sep 2018 12:25:58 +0200 (CEST) Received: by mail-wm1-f65.google.com with SMTP id s12-v6so1694395wmc.0 for ; Wed, 26 Sep 2018 03:25:58 -0700 (PDT) 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=TN2IJYdHgtT3BemFu8Zp1UT/5yhsLzCn9bEmOt6lOpI=; b=XWqQE2IlUVNjMtveRD6CAvGlRmZ/OpsYOg/IqRzN+4gUlbqaODkme2cXgvvgtNOYIb rl+o44RLqc6nYU44jqWDMUAZiaRLOXpzX92CALCquPVR/MXXkAN9Y15ZL7VSx8tCvFjG e2BwbnieNa3JuEMRFoFkEULU0C+4TENskguac= 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=TN2IJYdHgtT3BemFu8Zp1UT/5yhsLzCn9bEmOt6lOpI=; b=MUKpziyE3+4diZ7xVfa2IiLrS9r3NDCI0T4ALFhAkqWTMLcCItu42+GwFBG/PqqiAF rK6OAacydjf0S2y1q34CXrKu0Dki59PVSuO6vULVAJtkuDQd43cVKQwDdcXEv9GpK1Oc gFPWhn5Rpq215kfahCr5l9AF7i+Nx3qCQE3xARxy5gZFLQDYLMreaBinblSSWZRLPIGy 5wOW9BC4jAu9E32EcgAiUMB74OFzqjIY0dvpXB27OLz0k0RlOhmQGh61iPOaylpegMKX 7O282fL8Vo9XXMFkGQXlv18ynVp1hhFhAcLGTJCyGU9emBO5Hf3p3cosfonkzkAfHnlN PL9A== X-Gm-Message-State: ABuFfojZsOqRElEqxt69r1KgOiydsibtGu0TYL8MHG0USzSvHtAdOtR/ pkEsHR5/13aywZL2HiXgPWwQ6g== X-Google-Smtp-Source: ACcGV61IQc4UNYNuueAkF8cfA2HqxkNRLoh9Mv5p5MjB4ce+iIXd2DxO11NlR7+zr5Tndi8WW/ROUA== X-Received: by 2002:a1c:c145:: with SMTP id r66-v6mr3813360wmf.131.1537957558038; Wed, 26 Sep 2018 03:25:58 -0700 (PDT) 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 b12sm4442648wrx.11.2018.09.26.03.25.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 26 Sep 2018 03:25:57 -0700 (PDT) From: Srinivas Kandagatla To: broonie@kernel.org, alsa-devel@alsa-project.org, robh+dt@kernel.org Date: Wed, 26 Sep 2018 11:23:46 +0100 Message-Id: <20180926102349.23481-3-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180926102349.23481-1-srinivas.kandagatla@linaro.org> References: <20180926102349.23481-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Cc: mark.rutland@arm.com, devicetree@vger.kernel.org, bgoswami@codeaurora.org, lgirdwood@gmail.com, tiwai@suse.com, linux-kernel@vger.kernel.org, vkoul@kernel.org, rohitkr@codeaurora.org, Srinivas Kandagatla Subject: [alsa-devel] [PATCH v2 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; }