{
snd_pcm_hw_t *hw = pcm->private;
int fd = hw->fd;
+#if 0
assert(pcm->stream != SND_PCM_STREAM_PLAYBACK ||
snd_pcm_mmap_playback_hw_avail(pcm) > 0);
+#endif
if (ioctl(fd, SND_PCM_IOCTL_START) < 0) {
SYSERR("SND_PCM_IOCTL_START failed");
return -errno;
static int snd_pcm_hw_munmap_status(snd_pcm_t *pcm)
{
snd_pcm_hw_t *hw = pcm->private;
- if (munmap((void*)hw->mmap_status, sizeof(*hw->mmap_status)) < 0) {
+ if (munmap((void*)hw->mmap_status, PAGE_ALIGN(sizeof(*hw->mmap_status))) < 0) {
SYSERR("status munmap failed");
return -errno;
}
static int snd_pcm_hw_munmap_control(snd_pcm_t *pcm)
{
snd_pcm_hw_t *hw = pcm->private;
- if (munmap(hw->mmap_control, sizeof(*hw->mmap_control)) < 0) {
+ if (munmap(hw->mmap_control, PAGE_ALIGN(sizeof(*hw->mmap_control))) < 0) {
SYSERR("control munmap failed");
return -errno;
}
__again:
if (attempt++ > 3) {
- snd_ctl_close(ctl);
- return -EBUSY;
+ ret = -EBUSY;
+ goto _err;
}
ret = snd_ctl_pcm_prefer_subdevice(ctl, subdevice);
- if (ret < 0) {
- snd_ctl_close(ctl);
- return ret;
- }
+ if (ret < 0)
+ goto _err;
fmode = O_RDWR;
if (mode & SND_PCM_NONBLOCK)
fmode |= O_NONBLOCK;
fmode |= O_ASYNC;
if ((fd = open(filename, fmode)) < 0) {
SYSERR("open %s failed", filename);
- snd_ctl_close(ctl);
- return -errno;
+ ret = -errno;
+ goto _err;
}
if (ioctl(fd, SND_PCM_IOCTL_PVERSION, &ver) < 0) {
SYSERR("SND_PCM_IOCTL_PVERSION failed");
ret = -ENOMEM;
goto _err;
}
+ snd_ctl_close(ctl);
pcm->type = SND_PCM_TYPE_HW;
pcm->stream = stream;
pcm->mode = mode;
ret = snd_pcm_hw_mmap_status(pcm);
if (ret < 0) {
snd_pcm_close(pcm);
- snd_ctl_close(ctl);
return ret;
}
ret = snd_pcm_hw_mmap_control(pcm);
if (ret < 0) {
snd_pcm_close(pcm);
- snd_ctl_close(ctl);
return ret;
}
return 0;
free(hw);
if (pcm)
free(pcm);
- close(fd);
+ if (fd >= 0)
+ close(fd);
snd_ctl_close(ctl);
return ret;
}