From patchwork Tue Nov 5 07:55:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 11227109 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 705AB16B1 for ; Tue, 5 Nov 2019 07:55:28 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4E5B120717 for ; Tue, 5 Nov 2019 07:55:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4E5B120717 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E75A96E90A; Tue, 5 Nov 2019 07:55:25 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3567B6E90A for ; Tue, 5 Nov 2019 07:55:24 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 7555AABBD; Tue, 5 Nov 2019 07:55:22 +0000 (UTC) Date: Tue, 05 Nov 2019 08:55:21 +0100 Message-ID: From: Takashi Iwai To: Andrzej Hajda , Neil Armstrong Subject: Incorrect buffer handling in dw-hdmi bridge audio User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?utf-8?b?R29qxY0=?=) APEL/10.8 Emacs/25.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jernej Skrabec , alsa-devel@alsa-project.org, Laurent Pinchart , dri-devel@lists.freedesktop.org, Jonas Karlman Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Hi, while recently working on the ALSA memory allocator API cleanup, I noticed that dw-hdmi bridge driver seems doing weird about the buffer management. It pre-allocates the usual device buffers fully at the probe time, while each stream allocates the buffer via the vmalloc helpers and replaces with it at each open. I guess it's no expected behavior? It's basically a full waste of resources, and the vmalloc buffer isn't guaranteed to work well for mmap on every architecture. Below is the patch to address it. Can anyone check whether this still works? Since I have a cleanup series and this is involved, I'd like to take the fix through my tree once after it's confirmed (and get ACK if possible). Thanks! Takashi -- 8< -- From: Takashi Iwai Subject: [PATCH] drm/bridge: dw-hdmi: Fix the incorrect buffer allocations The driver sets up the buffer preallocation with SNDRV_DMA_TYPE_DEV, while it re-allocates and releases vmalloc pages. This is not only a lot of waste resources but also causes the mmap malfunction. Change / drop the vmalloc-related code and use the standard buffer allocation / release code instead. Signed-off-by: Takashi Iwai Signed-off-by: Takashi Iwai Signed-off-by: Takashi Iwai --- drivers/gpu/drm/bridge/synopsys/dw-hdmi-ahb-audio.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/bridge/synopsys/dw-hdmi-ahb-audio.c b/drivers/gpu/drm/bridge/synopsys/dw-hdmi-ahb-audio.c index 2b7539701b42..8fe7a6e8ff94 100644 --- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi-ahb-audio.c +++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi-ahb-audio.c @@ -384,15 +384,14 @@ static int dw_hdmi_close(struct snd_pcm_substream *substream) static int dw_hdmi_hw_free(struct snd_pcm_substream *substream) { - return snd_pcm_lib_free_vmalloc_buffer(substream); + return snd_pcm_lib_free_pages(substream); } static int dw_hdmi_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params) { /* Allocate the PCM runtime buffer, which is exposed to userspace. */ - return snd_pcm_lib_alloc_vmalloc_buffer(substream, - params_buffer_bytes(params)); + return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params)); } static int dw_hdmi_prepare(struct snd_pcm_substream *substream) @@ -511,7 +510,6 @@ static const struct snd_pcm_ops snd_dw_hdmi_ops = { .prepare = dw_hdmi_prepare, .trigger = dw_hdmi_trigger, .pointer = dw_hdmi_pointer, - .page = snd_pcm_lib_get_vmalloc_page, }; static int snd_dw_hdmi_probe(struct platform_device *pdev)