alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: alsa-devel@alsa-project.org
Subject: [PATCH 08/11] ALSA: usx2y: Fix shmem initialization
Date: Mon, 17 May 2021 15:15:42 +0200	[thread overview]
Message-ID: <20210517131545.27252-9-tiwai@suse.de> (raw)
In-Reply-To: <20210517131545.27252-1-tiwai@suse.de>

Currently us428ctls_shmem pages are allocated dynamically upon the
mmap call, but this is quite racy.  Since the shared memory itself is
mandatory for the mmap, let's allocate it at the beginning of the card
initialization.  Also, fix the initialization of the wait queue, too.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/usb/usx2y/usX2Yhwdep.c | 18 +++++++++---------
 sound/usb/usx2y/usbusx2y.c   |  1 +
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/sound/usb/usx2y/usX2Yhwdep.c b/sound/usb/usx2y/usX2Yhwdep.c
index ec7e3beed4f9..c29da0341bc5 100644
--- a/sound/usb/usx2y/usX2Yhwdep.c
+++ b/sound/usb/usx2y/usX2Yhwdep.c
@@ -60,14 +60,6 @@ static int snd_us428ctls_mmap(struct snd_hwdep *hw, struct file *filp, struct vm
 		return -EINVAL;
 	}
 
-	if (!us428->us428ctls_sharedmem) {
-		init_waitqueue_head(&us428->us428ctls_wait_queue_head);
-		us428->us428ctls_sharedmem = alloc_pages_exact(US428_SHAREDMEM_PAGES, GFP_KERNEL);
-		if (!us428->us428ctls_sharedmem)
-			return -ENOMEM;
-		memset(us428->us428ctls_sharedmem, -1, US428_SHAREDMEM_PAGES);
-		us428->us428ctls_sharedmem->ctl_snapshot_last = -2;
-	}
 	area->vm_ops = &us428ctls_vm_ops;
 	area->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP;
 	area->vm_private_data = hw->private_data;
@@ -232,18 +224,26 @@ int usx2y_hwdep_new(struct snd_card *card, struct usb_device *device)
 {
 	int err;
 	struct snd_hwdep *hw;
+	struct usx2ydev	*us428 = usx2y(card);
 
 	err = snd_hwdep_new(card, SND_USX2Y_LOADER_ID, 0, &hw);
 	if (err < 0)
 		return err;
 
 	hw->iface = SNDRV_HWDEP_IFACE_USX2Y;
-	hw->private_data = usx2y(card);
+	hw->private_data = us428;
 	hw->ops.dsp_status = snd_usx2y_hwdep_dsp_status;
 	hw->ops.dsp_load = snd_usx2y_hwdep_dsp_load;
 	hw->ops.mmap = snd_us428ctls_mmap;
 	hw->ops.poll = snd_us428ctls_poll;
 	hw->exclusive = 1;
 	sprintf(hw->name, "/dev/bus/usb/%03d/%03d", device->bus->busnum, device->devnum);
+
+	us428->us428ctls_sharedmem = alloc_pages_exact(US428_SHAREDMEM_PAGES, GFP_KERNEL);
+	if (!us428->us428ctls_sharedmem)
+		return -ENOMEM;
+	memset(us428->us428ctls_sharedmem, -1, US428_SHAREDMEM_PAGES);
+	us428->us428ctls_sharedmem->ctl_snapshot_last = -2;
+
 	return 0;
 }
diff --git a/sound/usb/usx2y/usbusx2y.c b/sound/usb/usx2y/usbusx2y.c
index d2e1cf163521..09ead00e395e 100644
--- a/sound/usb/usx2y/usbusx2y.c
+++ b/sound/usb/usx2y/usbusx2y.c
@@ -375,6 +375,7 @@ static int usx2y_create_card(struct usb_device *device,
 	card->private_free = snd_usx2y_card_private_free;
 	usx2y(card)->dev = device;
 	init_waitqueue_head(&usx2y(card)->prepare_wait_queue);
+	init_waitqueue_head(&usx2y(card)->us428ctls_wait_queue_head);
 	mutex_init(&usx2y(card)->pcm_mutex);
 	INIT_LIST_HEAD(&usx2y(card)->midi_list);
 	strcpy(card->driver, "USB "NAME_ALLCAPS"");
-- 
2.26.2


  parent reply	other threads:[~2021-05-17 13:20 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-17 13:15 [PATCH 00/11] ALSA: usx2y: Fixes and cleanups Takashi Iwai
2021-05-17 13:15 ` [PATCH 01/11] ALSA: usx2y: Avoid camelCase Takashi Iwai
2021-05-17 13:15 ` [PATCH 02/11] ALSA: usx2y: Fix spaces Takashi Iwai
2021-05-17 13:15 ` [PATCH 03/11] ALSA: usx2y: Coding style fixes Takashi Iwai
2021-05-17 13:15 ` [PATCH 04/11] ALSA: usx2y: Fix potential leaks of uninitialized memory Takashi Iwai
2021-05-17 13:15 ` [PATCH 05/11] ALSA: usx2y: Avoid self-killing Takashi Iwai
2021-05-17 13:15 ` [PATCH 06/11] ALSA: usx2y: Fix potential memory leaks Takashi Iwai
2021-05-17 13:15 ` [PATCH 07/11] ALSA: usxy2: Fix potential doubly allocations Takashi Iwai
2021-05-17 13:15 ` Takashi Iwai [this message]
2021-05-17 13:15 ` [PATCH 09/11] ALSA: usx2y: Don't call free_pages_exact() with NULL address Takashi Iwai
2021-05-17 13:15 ` [PATCH 10/11] ALSA: usx2y: Cleanup probe and disconnect callbacks Takashi Iwai
2021-05-17 13:15 ` [PATCH 11/11] ALSA: usx2y: Nuke pcm_list Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210517131545.27252-9-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).