From patchwork Mon Feb 4 11:28:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaroslav Kysela X-Patchwork-Id: 10795451 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 02E931823 for ; Mon, 4 Feb 2019 11:36:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E61C12AAD8 for ; Mon, 4 Feb 2019 11:36:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D872C2B0D3; Mon, 4 Feb 2019 11:36:21 +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 97A972AAD8 for ; Mon, 4 Feb 2019 11:36:20 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 969E7267549; Mon, 4 Feb 2019 12:29:11 +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 DF1B8267559; Mon, 4 Feb 2019 12:29:09 +0100 (CET) Received: from mail1.perex.cz (mail1.perex.cz [77.48.224.245]) by alsa0.perex.cz (Postfix) with ESMTP id E8574267557 for ; Mon, 4 Feb 2019 12:29:03 +0100 (CET) Received: from mail1.perex.cz (localhost [127.0.0.1]) by smtp1.perex.cz (Perex's E-mail Delivery System) with ESMTP id C8163A0055; Mon, 4 Feb 2019 12:29:03 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.perex.cz C8163A0055 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=perex.cz; s=default; t=1549279743; bh=rKzz+Gg31uncVarjK31MHT56fQzqtaWUVA7GKoyKOmk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=3qNCOJpsvm5iNRQORwpXfFF3wJmAnpydgEc2Yx7+MXgmPqesLwK7YGDcgZV2beiJW 736ZMAPiAJNvo6dxgeccNSq/EEwwtQPZ5rVUdgiLKZjmhJGm3zzsq4hpMy7SDOCu7d juq5nEWg+E7cWKqaWrbl0ZI0BAfUjBjJOP1MDYhc= Received: from p50.perex-int.cz (unknown [192.168.100.94]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: perex) by mail1.perex.cz (Perex's E-mail Delivery System) with ESMTPSA; Mon, 4 Feb 2019 12:28:55 +0100 (CET) From: Jaroslav Kysela To: ALSA development Date: Mon, 4 Feb 2019 12:28:33 +0100 Message-Id: <20190204112834.27083-3-perex@perex.cz> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20190204112834.27083-1-perex@perex.cz> References: <20190204112834.27083-1-perex@perex.cz> Cc: Baolin Wang , Takashi Iwai , Phil Burk , Zach Riggle , Mark Brown , Leo Yan Subject: [alsa-devel] [PATCH 2/3] ALSA: pcm: merge pcm_..._mmap_allowed fcns to the snd_pcm_mmap_... fcns 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 There is no benefit to have this code separate. The result code is even smaller and simplier for the review. No functional change. diffstat: 23 insertions(+), 34 deletions(-) Signed-off-by: Jaroslav Kysela --- sound/core/pcm_native.c | 56 +++++++++++++++++++------------------------------ 1 file changed, 22 insertions(+), 34 deletions(-) diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index bb14658e4482..ffc6b32973ba 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -3295,6 +3295,16 @@ static int snd_pcm_mmap_status(struct snd_pcm_substream *substream, struct file struct vm_area_struct *area) { long size; + struct snd_pcm_file *pcm_file = file->private_data; + if (pcm_file->no_compat_mmap) + return -ENXIO; + /* See snd_pcm_mmap_control() below. + * Since older alsa-lib requires both status and control mmaps to be + * coupled, we have to disable the status mmap for old alsa-lib, too. + */ + if (pcm_file->user_pversion < SNDRV_PROTOCOL_VERSION(2, 0, 14) && + (pcm_file->substream->runtime->hw.info & SNDRV_PCM_INFO_SYNC_APPLPTR)) + return -ENXIO; if (!(area->vm_flags & VM_READ)) return -EINVAL; size = area->vm_end - area->vm_start; @@ -3331,6 +3341,15 @@ static int snd_pcm_mmap_control(struct snd_pcm_substream *substream, struct file struct vm_area_struct *area) { long size; + struct snd_pcm_file *pcm_file = file->private_data; + if (pcm_file->no_compat_mmap) + return -ENXIO; + /* Disallow the control mmap when SYNC_APPLPTR flag is set; + * it enforces the user-space to fall back to snd_pcm_sync_ptr(), + * thus it effectively assures the manual update of appl_ptr. + */ + if (pcm_file->substream->runtime->hw.info & SNDRV_PCM_INFO_SYNC_APPLPTR) + return -ENXIO; if (!(area->vm_flags & VM_READ)) return -EINVAL; size = area->vm_end - area->vm_start; @@ -3342,50 +3361,23 @@ static int snd_pcm_mmap_control(struct snd_pcm_substream *substream, struct file return 0; } -static bool pcm_status_mmap_allowed(struct snd_pcm_file *pcm_file) -{ - if (pcm_file->no_compat_mmap) - return false; - /* See pcm_control_mmap_allowed() below. - * Since older alsa-lib requires both status and control mmaps to be - * coupled, we have to disable the status mmap for old alsa-lib, too. - */ - if (pcm_file->user_pversion < SNDRV_PROTOCOL_VERSION(2, 0, 14) && - (pcm_file->substream->runtime->hw.info & SNDRV_PCM_INFO_SYNC_APPLPTR)) - return false; - return true; -} - -static bool pcm_control_mmap_allowed(struct snd_pcm_file *pcm_file) -{ - if (pcm_file->no_compat_mmap) - return false; - /* Disallow the control mmap when SYNC_APPLPTR flag is set; - * it enforces the user-space to fall back to snd_pcm_sync_ptr(), - * thus it effectively assures the manual update of appl_ptr. - */ - if (pcm_file->substream->runtime->hw.info & SNDRV_PCM_INFO_SYNC_APPLPTR) - return false; - return true; -} - #else /* ! coherent mmap */ + /* * don't support mmap for status and control records. */ -#define pcm_status_mmap_allowed(pcm_file) false -#define pcm_control_mmap_allowed(pcm_file) false - static int snd_pcm_mmap_status(struct snd_pcm_substream *substream, struct file *file, struct vm_area_struct *area) { return -ENXIO; } + static int snd_pcm_mmap_control(struct snd_pcm_substream *substream, struct file *file, struct vm_area_struct *area) { return -ENXIO; } + #endif /* coherent mmap */ static inline struct page * @@ -3559,12 +3551,8 @@ static int snd_pcm_mmap(struct file *file, struct vm_area_struct *area) offset = area->vm_pgoff << PAGE_SHIFT; switch (offset) { case SNDRV_PCM_MMAP_OFFSET_STATUS: - if (!pcm_status_mmap_allowed(pcm_file)) - return -ENXIO; return snd_pcm_mmap_status(substream, file, area); case SNDRV_PCM_MMAP_OFFSET_CONTROL: - if (!pcm_control_mmap_allowed(pcm_file)) - return -ENXIO; return snd_pcm_mmap_control(substream, file, area); default: return snd_pcm_mmap_data(substream, file, area);