Fix some potential NULL pointer dereferences.

This is supposed to fix some Coverity Prevent errors (Ariff didn't
looked at the CID's (ENOTIME), I just told him that there are some problems
in function dsp_ioctl()).

CID:		215-218
Found with:	Coverity Prevent(tm)
Submitted by:	ariff
MFC after:	5 days
This commit is contained in:
Alexander Leidinger 2006-01-29 16:48:41 +00:00
parent 44255c5519
commit c8c4c87d6a

View File

@ -470,13 +470,18 @@ dsp_ioctl(struct cdev *i_dev, u_long cmd, caddr_t arg, int mode, struct thread *
* we start with the new ioctl interface. * we start with the new ioctl interface.
*/ */
case AIONWRITE: /* how many bytes can write ? */ case AIONWRITE: /* how many bytes can write ? */
CHN_LOCK(wrch); if (wrch) {
CHN_LOCK(wrch);
/* /*
if (wrch && wrch->bufhard.dl) if (wrch && wrch->bufhard.dl)
while (chn_wrfeed(wrch) == 0); while (chn_wrfeed(wrch) == 0);
*/ */
*arg_i = wrch? sndbuf_getfree(wrch->bufsoft) : 0; *arg_i = sndbuf_getfree(wrch->bufsoft);
CHN_UNLOCK(wrch); CHN_UNLOCK(wrch);
} else {
*arg_i = 0;
ret = EINVAL;
}
break; break;
case AIOSSIZE: /* set the current blocksize */ case AIOSSIZE: /* set the current blocksize */
@ -623,8 +628,10 @@ dsp_ioctl(struct cdev *i_dev, u_long cmd, caddr_t arg, int mode, struct thread *
*/ */
*arg_i = sndbuf_getready(rdch->bufsoft); *arg_i = sndbuf_getready(rdch->bufsoft);
CHN_UNLOCK(rdch); CHN_UNLOCK(rdch);
} else } else {
*arg_i = 0; *arg_i = 0;
ret = EINVAL;
}
break; break;
case FIOASYNC: /*set/clear async i/o */ case FIOASYNC: /*set/clear async i/o */
@ -658,9 +665,14 @@ dsp_ioctl(struct cdev *i_dev, u_long cmd, caddr_t arg, int mode, struct thread *
case THE_REAL_SNDCTL_DSP_GETBLKSIZE: case THE_REAL_SNDCTL_DSP_GETBLKSIZE:
case SNDCTL_DSP_GETBLKSIZE: case SNDCTL_DSP_GETBLKSIZE:
chn = wrch ? wrch : rdch; chn = wrch ? wrch : rdch;
CHN_LOCK(chn); if (chn) {
*arg_i = sndbuf_getblksz(chn->bufsoft); CHN_LOCK(chn);
CHN_UNLOCK(chn); *arg_i = sndbuf_getblksz(chn->bufsoft);
CHN_UNLOCK(chn);
} else {
*arg_i = 0;
ret = EINVAL;
}
break ; break ;
case SNDCTL_DSP_SETBLKSIZE: case SNDCTL_DSP_SETBLKSIZE:
@ -724,9 +736,14 @@ dsp_ioctl(struct cdev *i_dev, u_long cmd, caddr_t arg, int mode, struct thread *
case SOUND_PCM_READ_RATE: case SOUND_PCM_READ_RATE:
chn = wrch ? wrch : rdch; chn = wrch ? wrch : rdch;
CHN_LOCK(chn); if (chn) {
*arg_i = chn->speed; CHN_LOCK(chn);
CHN_UNLOCK(chn); *arg_i = chn->speed;
CHN_UNLOCK(chn);
} else {
*arg_i = 0;
ret = EINVAL;
}
break; break;
case SNDCTL_DSP_STEREO: case SNDCTL_DSP_STEREO:
@ -777,16 +794,26 @@ dsp_ioctl(struct cdev *i_dev, u_long cmd, caddr_t arg, int mode, struct thread *
case SOUND_PCM_READ_CHANNELS: case SOUND_PCM_READ_CHANNELS:
chn = wrch ? wrch : rdch; chn = wrch ? wrch : rdch;
CHN_LOCK(chn); if (chn) {
*arg_i = (chn->format & AFMT_STEREO) ? 2 : 1; CHN_LOCK(chn);
CHN_UNLOCK(chn); *arg_i = (chn->format & AFMT_STEREO) ? 2 : 1;
CHN_UNLOCK(chn);
} else {
*arg_i = 0;
ret = EINVAL;
}
break; break;
case SNDCTL_DSP_GETFMTS: /* returns a mask of supported fmts */ case SNDCTL_DSP_GETFMTS: /* returns a mask of supported fmts */
chn = wrch ? wrch : rdch; chn = wrch ? wrch : rdch;
CHN_LOCK(chn); if (chn) {
*arg_i = chn_getformats(chn); CHN_LOCK(chn);
CHN_UNLOCK(chn); *arg_i = chn_getformats(chn);
CHN_UNLOCK(chn);
} else {
*arg_i = 0;
ret = EINVAL;
}
break ; break ;
case SNDCTL_DSP_SETFMT: /* sets _one_ format */ case SNDCTL_DSP_SETFMT: /* sets _one_ format */
@ -942,18 +969,23 @@ dsp_ioctl(struct cdev *i_dev, u_long cmd, caddr_t arg, int mode, struct thread *
case SOUND_PCM_READ_BITS: case SOUND_PCM_READ_BITS:
chn = wrch ? wrch : rdch; chn = wrch ? wrch : rdch;
CHN_LOCK(chn); if (chn) {
if (chn->format & AFMT_8BIT) CHN_LOCK(chn);
*arg_i = 8; if (chn->format & AFMT_8BIT)
else if (chn->format & AFMT_16BIT) *arg_i = 8;
*arg_i = 16; else if (chn->format & AFMT_16BIT)
else if (chn->format & AFMT_24BIT) *arg_i = 16;
*arg_i = 24; else if (chn->format & AFMT_24BIT)
else if (chn->format & AFMT_32BIT) *arg_i = 24;
*arg_i = 32; else if (chn->format & AFMT_32BIT)
else *arg_i = 32;
else
ret = EINVAL;
CHN_UNLOCK(chn);
} else {
*arg_i = 0;
ret = EINVAL; ret = EINVAL;
CHN_UNLOCK(chn); }
break; break;
case SNDCTL_DSP_SETTRIGGER: case SNDCTL_DSP_SETTRIGGER: