summaryrefslogtreecommitdiffstats
path: root/sound
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2017-12-28 17:22:51 -0500
committerAl Viro <viro@zeniv.linux.org.uk>2017-12-28 17:22:51 -0500
commit3d46d7108dd3ff8b1d477bc2b7b061b12690e83c (patch)
tree7423e0e1a803a1e5ab39673f4d4356cece809884 /sound
parent446bd647ceee73fbed50404daece9cbcec751f66 (diff)
usx2y: don't bother with memdup_user() for 16-byte structure
... when it can bloody well go into a local variable. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'sound')
-rw-r--r--sound/usb/usx2y/us122l.c43
1 files changed, 18 insertions, 25 deletions
diff --git a/sound/usb/usx2y/us122l.c b/sound/usb/usx2y/us122l.c
index 159da1f3924e..8c394178a385 100644
--- a/sound/usb/usx2y/us122l.c
+++ b/sound/usb/usx2y/us122l.c
@@ -378,7 +378,7 @@ out:
378static int usb_stream_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, 378static int usb_stream_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
379 unsigned cmd, unsigned long arg) 379 unsigned cmd, unsigned long arg)
380{ 380{
381 struct usb_stream_config *cfg; 381 struct usb_stream_config cfg;
382 struct us122l *us122l = hw->private_data; 382 struct us122l *us122l = hw->private_data;
383 struct usb_stream *s; 383 struct usb_stream *s;
384 unsigned min_period_frames; 384 unsigned min_period_frames;
@@ -388,24 +388,21 @@ static int usb_stream_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
388 if (cmd != SNDRV_USB_STREAM_IOCTL_SET_PARAMS) 388 if (cmd != SNDRV_USB_STREAM_IOCTL_SET_PARAMS)
389 return -ENOTTY; 389 return -ENOTTY;
390 390
391 cfg = memdup_user((void *)arg, sizeof(*cfg)); 391 if (copy_from_user(&cfg, (void __user *)arg, sizeof(cfg)))
392 if (IS_ERR(cfg)) 392 return -EFAULT;
393 return PTR_ERR(cfg); 393
394 if (cfg.version != USB_STREAM_INTERFACE_VERSION)
395 return -ENXIO;
394 396
395 if (cfg->version != USB_STREAM_INTERFACE_VERSION) {
396 err = -ENXIO;
397 goto free;
398 }
399 high_speed = us122l->dev->speed == USB_SPEED_HIGH; 397 high_speed = us122l->dev->speed == USB_SPEED_HIGH;
400 if ((cfg->sample_rate != 44100 && cfg->sample_rate != 48000 && 398 if ((cfg.sample_rate != 44100 && cfg.sample_rate != 48000 &&
401 (!high_speed || 399 (!high_speed ||
402 (cfg->sample_rate != 88200 && cfg->sample_rate != 96000))) || 400 (cfg.sample_rate != 88200 && cfg.sample_rate != 96000))) ||
403 cfg->frame_size != 6 || 401 cfg.frame_size != 6 ||
404 cfg->period_frames > 0x3000) { 402 cfg.period_frames > 0x3000)
405 err = -EINVAL; 403 return -EINVAL;
406 goto free; 404
407 } 405 switch (cfg.sample_rate) {
408 switch (cfg->sample_rate) {
409 case 44100: 406 case 44100:
410 min_period_frames = 48; 407 min_period_frames = 48;
411 break; 408 break;
@@ -418,10 +415,8 @@ static int usb_stream_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
418 } 415 }
419 if (!high_speed) 416 if (!high_speed)
420 min_period_frames <<= 1; 417 min_period_frames <<= 1;
421 if (cfg->period_frames < min_period_frames) { 418 if (cfg.period_frames < min_period_frames)
422 err = -EINVAL; 419 return -EINVAL;
423 goto free;
424 }
425 420
426 snd_power_wait(hw->card, SNDRV_CTL_POWER_D0); 421 snd_power_wait(hw->card, SNDRV_CTL_POWER_D0);
427 422
@@ -430,24 +425,22 @@ static int usb_stream_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
430 if (!us122l->master) 425 if (!us122l->master)
431 us122l->master = file; 426 us122l->master = file;
432 else if (us122l->master != file) { 427 else if (us122l->master != file) {
433 if (!s || memcmp(cfg, &s->cfg, sizeof(*cfg))) { 428 if (!s || memcmp(&cfg, &s->cfg, sizeof(cfg))) {
434 err = -EIO; 429 err = -EIO;
435 goto unlock; 430 goto unlock;
436 } 431 }
437 us122l->slave = file; 432 us122l->slave = file;
438 } 433 }
439 if (!s || memcmp(cfg, &s->cfg, sizeof(*cfg)) || 434 if (!s || memcmp(&cfg, &s->cfg, sizeof(cfg)) ||
440 s->state == usb_stream_xrun) { 435 s->state == usb_stream_xrun) {
441 us122l_stop(us122l); 436 us122l_stop(us122l);
442 if (!us122l_start(us122l, cfg->sample_rate, cfg->period_frames)) 437 if (!us122l_start(us122l, cfg.sample_rate, cfg.period_frames))
443 err = -EIO; 438 err = -EIO;
444 else 439 else
445 err = 1; 440 err = 1;
446 } 441 }
447unlock: 442unlock:
448 mutex_unlock(&us122l->mutex); 443 mutex_unlock(&us122l->mutex);
449free:
450 kfree(cfg);
451 wake_up_all(&us122l->sk.sleep); 444 wake_up_all(&us122l->sk.sleep);
452 return err; 445 return err;
453} 446}