Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp8362195imu; Thu, 15 Nov 2018 10:17:40 -0800 (PST) X-Google-Smtp-Source: AJdET5chTABcVWFxlaH7AGYjomzW6KUIHaK0H0t6eqkJmC0EtJaiwgamiL/dE75qPd/0GmPXUYwD X-Received: by 2002:a63:a41:: with SMTP id z1mr6769657pgk.117.1542305860189; Thu, 15 Nov 2018 10:17:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542305860; cv=none; d=google.com; s=arc-20160816; b=JhezSxvd+80bAu+wclafVtCQ6fCpFKTKZ4lJzj5vFDHca4nerhXB2zySAmldsl6wO8 ZCioZessp48OhG7nTE1r6uun1+calTORzFK9Jqb6B05z1NEnR5ETRPefDEtM+VhzuV9K Ksyt9vAm0H5WgF2bVu0yaTHWqjJz+q6UyQc2aZ/Kyleo3lwWxymlR2P4N7hj7kLnm5CG ujlLfZNI2YKBSHhR2tjCkGJtwxfSrBuPo1PbjoN1EF/+652b2S6r73s3vgowfYem+7QP S42hK0yRKNpOTg1IhhUIQ8A61w2gFJbsoLbDobL2G2iS5LlgUTxsX06TGBjEiAOA6iE4 Z35w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=NJe/Lh0u4I1EWKwZUx0PaLmr2WjeZlvlzz6DRN2R6yI=; b=q4uoJx+s62dXakIK4fGfbTfoWd4CrNP2JC/29k70LUWmTaQQlqR5D/XuzfipZU/YyM yfQm5p4nrFlucMu5xI80b1Jl+mQLaown4UqKCJCu05szM0JNV+k61R7Hi0IJLY+LmXAl 9UXmUMfWMtpkPKEPptJmjBbCql66yoNQ/NwDPxx9BoemODOG9xg3ETIw+cbAaSMGlI6C tiuNF8X/z21Cal3C0lz9MM9bZxWAAE3WVIzggDAS6+EFmAofo8xai0TeOLfVnXMt4/Gi RuhMEnQSpIA6y0N77oRNSUB6ocEYxgvqYUtImMYXrqAsFDV86hWzBT5BjRUCooqmUb/I AKcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DG9FoSML; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a5-v6si24534441plh.157.2018.11.15.10.17.24; Thu, 15 Nov 2018 10:17:40 -0800 (PST) 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; dkim=pass header.i=@linaro.org header.s=google header.b=DG9FoSML; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388885AbeKPEY0 (ORCPT + 99 others); Thu, 15 Nov 2018 23:24:26 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:36323 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388454AbeKPEYZ (ORCPT ); Thu, 15 Nov 2018 23:24:25 -0500 Received: by mail-wm1-f65.google.com with SMTP id s11so9558928wmh.1 for ; Thu, 15 Nov 2018 10:15:32 -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=nAO9mrddEcDTV8+vsx6FY91rI/hY5Y12qJe4J785pdVoivHs9a2i6by3xTh4dJgrRx lGVInlRpG+ISg2KwWS+EbnjXFZTriMzWnU3reehT0VBWXRzchTD4VqEt0SOc3nPudEYD D2PfG5T1vB0ajRQOu+xx8vdWCsZDFbn1Udj7lJ+B5PWuIkdhWzKN3jhBHajDWGbvFTd3 qLguk/WQl9QB536O/ni5oVwhLO4i/439uhed2IfZYsnKdSxbqQL2ZjdUZyyntmSY55mm ZK3dAnp6qyZA0j9dfGv7N0OAp1tfKHh8+MJG8geW8JGOINTltfnAqWhbyXd5r9h3ZBOn QwEA== X-Gm-Message-State: AGRZ1gKMCOcE/bZ9yOsuHDvOVAlrfW0Nw1483wHaEH0Y4Qg9jupqzV3c xrWx2ereBo2yxUb8Hm2FO/EAww== 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 Cc: alsa-devel@alsa-project.org, robh+dt@kernel.org, linux-kernel@vger.kernel.org, bgoswami@codeaurora.org, rohitkr@codeaurora.org, lgirdwood@gmail.com, tiwai@suse.com, devicetree@vger.kernel.org, srini@kernel.org, Srinivas Kandagatla Subject: [PATCH v3 2/5] ALSA: compress: make use of runtime buffer for copy 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 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; } -- 2.19.1