From patchwork Tue Jul 17 21:19:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 10530761 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id F0CB46020A for ; Tue, 17 Jul 2018 21:21:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E3CE929293 for ; Tue, 17 Jul 2018 21:21:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D5CC7292A7; Tue, 17 Jul 2018 21:21:28 +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.1 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE,RDNS_NONE autolearn=no version=3.3.1 Received: from alsa0.perex.cz (unknown [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 30CE629293 for ; Tue, 17 Jul 2018 21:21:28 +0000 (UTC) Received: from alsa.alsa-project.org (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 70E3E26786A; Tue, 17 Jul 2018 23:20:37 +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 61DC026782E; Tue, 17 Jul 2018 23:19:58 +0200 (CEST) Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) by alsa0.perex.cz (Postfix) with ESMTP id A8ED226783C for ; Tue, 17 Jul 2018 23:19:51 +0200 (CEST) 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 33DCCADDF for ; Tue, 17 Jul 2018 21:19:51 +0000 (UTC) From: Takashi Iwai To: alsa-devel@alsa-project.org Date: Tue, 17 Jul 2018 23:19:49 +0200 Message-Id: <20180717211949.689-5-tiwai@suse.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180717211949.689-1-tiwai@suse.de> References: <20180717211949.689-1-tiwai@suse.de> Subject: [alsa-devel] [PATCH 4/4] ALSA: rawmidi: Use kvmalloc() for buffers 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: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP The size of in-kernel rawmidi buffers may be big up to 1MB, and it can be specified freely by user-space; which implies that user-space may trigger kmalloc() errors frequently. This patch replaces the buffer allocation via kvmalloc() for dealing with bigger buffers gracefully. Signed-off-by: Takashi Iwai --- sound/core/rawmidi.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sound/core/rawmidi.c b/sound/core/rawmidi.c index cc944a3637a2..c4e3f4e71c6b 100644 --- a/sound/core/rawmidi.c +++ b/sound/core/rawmidi.c @@ -128,7 +128,7 @@ static int snd_rawmidi_runtime_create(struct snd_rawmidi_substream *substream) runtime->avail = 0; else runtime->avail = runtime->buffer_size; - runtime->buffer = kmalloc(runtime->buffer_size, GFP_KERNEL); + runtime->buffer = kvmalloc(runtime->buffer_size, GFP_KERNEL); if (!runtime->buffer) { kfree(runtime); return -ENOMEM; @@ -142,7 +142,7 @@ static int snd_rawmidi_runtime_free(struct snd_rawmidi_substream *substream) { struct snd_rawmidi_runtime *runtime = substream->runtime; - kfree(runtime->buffer); + kvfree(runtime->buffer); kfree(runtime); substream->runtime = NULL; return 0; @@ -654,7 +654,7 @@ static int resize_runtime_buffer(struct snd_rawmidi_runtime *runtime, if (params->avail_min < 1 || params->avail_min > params->buffer_size) return -EINVAL; if (params->buffer_size != runtime->buffer_size) { - newbuf = kmalloc(params->buffer_size, GFP_KERNEL); + newbuf = kvmalloc(params->buffer_size, GFP_KERNEL); if (!newbuf) return -ENOMEM; spin_lock_irq(&runtime->lock); @@ -663,7 +663,7 @@ static int resize_runtime_buffer(struct snd_rawmidi_runtime *runtime, runtime->buffer_size = params->buffer_size; __reset_runtime_ptrs(runtime, is_input); spin_unlock_irq(&runtime->lock); - kfree(oldbuf); + kvfree(oldbuf); } runtime->avail_min = params->avail_min; return 0;