提交 3d46d710 编写于 作者: A Al Viro

usx2y: don't bother with memdup_user() for 16-byte structure

... when it can bloody well go into a local variable.
Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
上级 446bd647
...@@ -378,7 +378,7 @@ static bool us122l_start(struct us122l *us122l, ...@@ -378,7 +378,7 @@ static bool us122l_start(struct us122l *us122l,
static int usb_stream_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, static int usb_stream_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
unsigned cmd, unsigned long arg) unsigned cmd, unsigned long arg)
{ {
struct usb_stream_config *cfg; struct usb_stream_config cfg;
struct us122l *us122l = hw->private_data; struct us122l *us122l = hw->private_data;
struct usb_stream *s; struct usb_stream *s;
unsigned min_period_frames; unsigned min_period_frames;
...@@ -388,24 +388,21 @@ static int usb_stream_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, ...@@ -388,24 +388,21 @@ static int usb_stream_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
if (cmd != SNDRV_USB_STREAM_IOCTL_SET_PARAMS) if (cmd != SNDRV_USB_STREAM_IOCTL_SET_PARAMS)
return -ENOTTY; return -ENOTTY;
cfg = memdup_user((void *)arg, sizeof(*cfg)); if (copy_from_user(&cfg, (void __user *)arg, sizeof(cfg)))
if (IS_ERR(cfg)) return -EFAULT;
return PTR_ERR(cfg);
if (cfg.version != USB_STREAM_INTERFACE_VERSION)
return -ENXIO;
if (cfg->version != USB_STREAM_INTERFACE_VERSION) {
err = -ENXIO;
goto free;
}
high_speed = us122l->dev->speed == USB_SPEED_HIGH; high_speed = us122l->dev->speed == USB_SPEED_HIGH;
if ((cfg->sample_rate != 44100 && cfg->sample_rate != 48000 && if ((cfg.sample_rate != 44100 && cfg.sample_rate != 48000 &&
(!high_speed || (!high_speed ||
(cfg->sample_rate != 88200 && cfg->sample_rate != 96000))) || (cfg.sample_rate != 88200 && cfg.sample_rate != 96000))) ||
cfg->frame_size != 6 || cfg.frame_size != 6 ||
cfg->period_frames > 0x3000) { cfg.period_frames > 0x3000)
err = -EINVAL; return -EINVAL;
goto free;
} switch (cfg.sample_rate) {
switch (cfg->sample_rate) {
case 44100: case 44100:
min_period_frames = 48; min_period_frames = 48;
break; break;
...@@ -418,10 +415,8 @@ static int usb_stream_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, ...@@ -418,10 +415,8 @@ static int usb_stream_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
} }
if (!high_speed) if (!high_speed)
min_period_frames <<= 1; min_period_frames <<= 1;
if (cfg->period_frames < min_period_frames) { if (cfg.period_frames < min_period_frames)
err = -EINVAL; return -EINVAL;
goto free;
}
snd_power_wait(hw->card, SNDRV_CTL_POWER_D0); snd_power_wait(hw->card, SNDRV_CTL_POWER_D0);
...@@ -430,24 +425,22 @@ static int usb_stream_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, ...@@ -430,24 +425,22 @@ static int usb_stream_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
if (!us122l->master) if (!us122l->master)
us122l->master = file; us122l->master = file;
else if (us122l->master != file) { else if (us122l->master != file) {
if (!s || memcmp(cfg, &s->cfg, sizeof(*cfg))) { if (!s || memcmp(&cfg, &s->cfg, sizeof(cfg))) {
err = -EIO; err = -EIO;
goto unlock; goto unlock;
} }
us122l->slave = file; us122l->slave = file;
} }
if (!s || memcmp(cfg, &s->cfg, sizeof(*cfg)) || if (!s || memcmp(&cfg, &s->cfg, sizeof(cfg)) ||
s->state == usb_stream_xrun) { s->state == usb_stream_xrun) {
us122l_stop(us122l); us122l_stop(us122l);
if (!us122l_start(us122l, cfg->sample_rate, cfg->period_frames)) if (!us122l_start(us122l, cfg.sample_rate, cfg.period_frames))
err = -EIO; err = -EIO;
else else
err = 1; err = 1;
} }
unlock: unlock:
mutex_unlock(&us122l->mutex); mutex_unlock(&us122l->mutex);
free:
kfree(cfg);
wake_up_all(&us122l->sk.sleep); wake_up_all(&us122l->sk.sleep);
return err; return err;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册