Commit a829dd5b authored by Takashi Iwai's avatar Takashi Iwai

ALSA: usx2y: Coding style fixes

This patch fixes various trivial coding-style issues in usx2y code,
such as:
* the assginments in if condition
* comparison order with constants
* NULL / zero checks
* unsigned -> unsigned int
* addition of braces in control blocks
* debug print with function names
* move local variables in block into function head
* reduction of too nested indentations

No functional changes.

Link: https://lore.kernel.org/r/20210517131545.27252-4-tiwai@suse.deSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 4c0a58ef
...@@ -114,9 +114,9 @@ static vm_fault_t usb_stream_hwdep_vm_fault(struct vm_fault *vmf) ...@@ -114,9 +114,9 @@ static vm_fault_t usb_stream_hwdep_vm_fault(struct vm_fault *vmf)
goto unlock; goto unlock;
offset = vmf->pgoff << PAGE_SHIFT; offset = vmf->pgoff << PAGE_SHIFT;
if (offset < PAGE_ALIGN(s->read_size)) if (offset < PAGE_ALIGN(s->read_size)) {
vaddr = (char *)s + offset; vaddr = (char *)s + offset;
else { } else {
offset -= PAGE_ALIGN(s->read_size); offset -= PAGE_ALIGN(s->read_size);
if (offset >= PAGE_ALIGN(s->write_size)) if (offset >= PAGE_ALIGN(s->write_size))
goto unlock; goto unlock;
...@@ -238,7 +238,7 @@ static __poll_t usb_stream_hwdep_poll(struct snd_hwdep *hw, ...@@ -238,7 +238,7 @@ static __poll_t usb_stream_hwdep_poll(struct snd_hwdep *hw,
struct file *file, poll_table *wait) struct file *file, poll_table *wait)
{ {
struct us122l *us122l = hw->private_data; struct us122l *us122l = hw->private_data;
unsigned *polled; unsigned int *polled;
__poll_t mask; __poll_t mask;
poll_wait(file, &us122l->sk.sleep, wait); poll_wait(file, &us122l->sk.sleep, wait);
...@@ -255,9 +255,10 @@ static __poll_t usb_stream_hwdep_poll(struct snd_hwdep *hw, ...@@ -255,9 +255,10 @@ static __poll_t usb_stream_hwdep_poll(struct snd_hwdep *hw,
if (*polled != s->periods_done) { if (*polled != s->periods_done) {
*polled = s->periods_done; *polled = s->periods_done;
mask = EPOLLIN | EPOLLOUT | EPOLLWRNORM; mask = EPOLLIN | EPOLLOUT | EPOLLWRNORM;
} else } else {
mask = 0; mask = 0;
} }
}
mutex_unlock(&us122l->mutex); mutex_unlock(&us122l->mutex);
} }
return mask; return mask;
...@@ -294,11 +295,11 @@ static int us122l_set_sample_rate(struct usb_device *dev, int rate) ...@@ -294,11 +295,11 @@ static int us122l_set_sample_rate(struct usb_device *dev, int rate)
} }
static bool us122l_start(struct us122l *us122l, static bool us122l_start(struct us122l *us122l,
unsigned rate, unsigned period_frames) unsigned int rate, unsigned int period_frames)
{ {
struct list_head *p; struct list_head *p;
int err; int err;
unsigned use_packsize = 0; unsigned int use_packsize = 0;
bool success = false; bool success = false;
if (us122l->dev->speed == USB_SPEED_HIGH) { if (us122l->dev->speed == USB_SPEED_HIGH) {
...@@ -331,7 +332,7 @@ static bool us122l_start(struct us122l *us122l, ...@@ -331,7 +332,7 @@ static bool us122l_start(struct us122l *us122l,
err = usb_stream_start(&us122l->sk); err = usb_stream_start(&us122l->sk);
if (err < 0) { if (err < 0) {
us122l_stop(us122l); us122l_stop(us122l);
snd_printk(KERN_ERR "us122l_start error %i\n", err); snd_printk(KERN_ERR "%s error %i\n", __func__, err);
goto out; goto out;
} }
list_for_each(p, &us122l->midi_list) list_for_each(p, &us122l->midi_list)
...@@ -342,12 +343,12 @@ static bool us122l_start(struct us122l *us122l, ...@@ -342,12 +343,12 @@ 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 int 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 int min_period_frames;
int err = 0; int err = 0;
bool high_speed; bool high_speed;
...@@ -388,9 +389,9 @@ static int usb_stream_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, ...@@ -388,9 +389,9 @@ static int usb_stream_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
mutex_lock(&us122l->mutex); mutex_lock(&us122l->mutex);
s = us122l->sk.s; s = us122l->sk.s;
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;
......
...@@ -11,7 +11,7 @@ struct us122l { ...@@ -11,7 +11,7 @@ struct us122l {
struct mutex mutex; struct mutex mutex;
struct file *first; struct file *first;
unsigned second_periods_polled; unsigned int second_periods_polled;
struct file *master; struct file *master;
struct file *slave; struct file *slave;
struct list_head midi_list; struct list_head midi_list;
......
...@@ -85,7 +85,7 @@ static __poll_t snd_us428ctls_poll(struct snd_hwdep *hw, struct file *file, poll ...@@ -85,7 +85,7 @@ static __poll_t snd_us428ctls_poll(struct snd_hwdep *hw, struct file *file, poll
poll_wait(file, &us428->us428ctls_wait_queue_head, wait); poll_wait(file, &us428->us428ctls_wait_queue_head, wait);
if (shm != NULL && shm->ctl_snapshot_last != shm->ctl_snapshot_red) if (shm && shm->ctl_snapshot_last != shm->ctl_snapshot_red)
mask |= EPOLLIN; mask |= EPOLLIN;
return mask; return mask;
...@@ -114,7 +114,7 @@ static int snd_usx2y_hwdep_dsp_status(struct snd_hwdep *hw, ...@@ -114,7 +114,7 @@ static int snd_usx2y_hwdep_dsp_status(struct snd_hwdep *hw,
id = USX2Y_TYPE_428; id = USX2Y_TYPE_428;
break; break;
} }
if (0 > id) if (id < 0)
return -ENODEV; return -ENODEV;
strcpy(info->id, type_ids[id]); strcpy(info->id, type_ids[id]);
info->num_dsps = 2; // 0: Prepad Data, 1: FPGA Code info->num_dsps = 2; // 0: Prepad Data, 1: FPGA Code
...@@ -158,7 +158,7 @@ static int usx2y_create_usbmidi(struct snd_card *card) ...@@ -158,7 +158,7 @@ static int usx2y_create_usbmidi(struct snd_card *card)
le16_to_cpu(dev->descriptor.idProduct) == USB_ID_US428 ? le16_to_cpu(dev->descriptor.idProduct) == USB_ID_US428 ?
&quirk_2 : &quirk_1; &quirk_2 : &quirk_1;
snd_printdd("usx2y_create_usbmidi\n"); snd_printdd("%s\n", __func__);
return snd_usbmidi_create(card, iface, &usx2y(card)->midi_list, quirk); return snd_usbmidi_create(card, iface, &usx2y(card)->midi_list, quirk);
} }
...@@ -166,20 +166,21 @@ static int usx2y_create_alsa_devices(struct snd_card *card) ...@@ -166,20 +166,21 @@ static int usx2y_create_alsa_devices(struct snd_card *card)
{ {
int err; int err;
do { err = usx2y_create_usbmidi(card);
if ((err = usx2y_create_usbmidi(card)) < 0) { if (err < 0) {
snd_printk(KERN_ERR "usx2y_create_alsa_devices: usx2y_create_usbmidi error %i\n", err); snd_printk(KERN_ERR "%s: usx2y_create_usbmidi error %i\n", __func__, err);
break; return err;
} }
if ((err = usx2y_audio_create(card)) < 0) err = usx2y_audio_create(card);
break; if (err < 0)
if ((err = usx2y_hwdep_pcm_new(card)) < 0) return err;
break; err = usx2y_hwdep_pcm_new(card);
if ((err = snd_card_register(card)) < 0) if (err < 0)
break;
} while (0);
return err; return err;
err = snd_card_register(card);
if (err < 0)
return err;
return 0;
} }
static int snd_usx2y_hwdep_dsp_load(struct snd_hwdep *hw, static int snd_usx2y_hwdep_dsp_load(struct snd_hwdep *hw,
...@@ -233,7 +234,8 @@ int usx2y_hwdep_new(struct snd_card *card, struct usb_device *device) ...@@ -233,7 +234,8 @@ int usx2y_hwdep_new(struct snd_card *card, struct usb_device *device)
int err; int err;
struct snd_hwdep *hw; struct snd_hwdep *hw;
if ((err = snd_hwdep_new(card, SND_USX2Y_LOADER_ID, 0, &hw)) < 0) err = snd_hwdep_new(card, SND_USX2Y_LOADER_ID, 0, &hw);
if (err < 0)
return err; return err;
hw->iface = SNDRV_HWDEP_IFACE_USX2Y; hw->iface = SNDRV_HWDEP_IFACE_USX2Y;
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
/* setup */ /* setup */
static unsigned usb_stream_next_packet_size(struct usb_stream_kernel *sk) static unsigned int usb_stream_next_packet_size(struct usb_stream_kernel *sk)
{ {
struct usb_stream *s = sk->s; struct usb_stream *s = sk->s;
...@@ -44,7 +44,8 @@ static void playback_prep_freqn(struct usb_stream_kernel *sk, struct urb *urb) ...@@ -44,7 +44,8 @@ static void playback_prep_freqn(struct usb_stream_kernel *sk, struct urb *urb)
lb, s->period_size); lb, s->period_size);
} }
static int init_pipe_urbs(struct usb_stream_kernel *sk, unsigned use_packsize, static int init_pipe_urbs(struct usb_stream_kernel *sk,
unsigned int use_packsize,
struct urb **urbs, char *transfer, struct urb **urbs, char *transfer,
struct usb_device *dev, int pipe) struct usb_device *dev, int pipe)
{ {
...@@ -82,7 +83,7 @@ static int init_pipe_urbs(struct usb_stream_kernel *sk, unsigned use_packsize, ...@@ -82,7 +83,7 @@ static int init_pipe_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
return 0; return 0;
} }
static int init_urbs(struct usb_stream_kernel *sk, unsigned use_packsize, static int init_urbs(struct usb_stream_kernel *sk, unsigned int use_packsize,
struct usb_device *dev, int in_pipe, int out_pipe) struct usb_device *dev, int in_pipe, int out_pipe)
{ {
struct usb_stream *s = sk->s; struct usb_stream *s = sk->s;
...@@ -112,7 +113,7 @@ static int init_urbs(struct usb_stream_kernel *sk, unsigned use_packsize, ...@@ -112,7 +113,7 @@ static int init_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
* convert a sampling rate into our full speed format (fs/1000 in Q16.16) * convert a sampling rate into our full speed format (fs/1000 in Q16.16)
* this will overflow at approx 524 kHz * this will overflow at approx 524 kHz
*/ */
static inline unsigned get_usb_full_speed_rate(unsigned rate) static inline unsigned int get_usb_full_speed_rate(unsigned int rate)
{ {
return ((rate << 13) + 62) / 125; return ((rate << 13) + 62) / 125;
} }
...@@ -121,7 +122,7 @@ static inline unsigned get_usb_full_speed_rate(unsigned rate) ...@@ -121,7 +122,7 @@ static inline unsigned get_usb_full_speed_rate(unsigned rate)
* convert a sampling rate into USB high speed format (fs/8000 in Q16.16) * convert a sampling rate into USB high speed format (fs/8000 in Q16.16)
* this will overflow at approx 4 MHz * this will overflow at approx 4 MHz
*/ */
static inline unsigned get_usb_high_speed_rate(unsigned rate) static inline unsigned int get_usb_high_speed_rate(unsigned int rate)
{ {
return ((rate << 10) + 62) / 125; return ((rate << 10) + 62) / 125;
} }
...@@ -129,7 +130,7 @@ static inline unsigned get_usb_high_speed_rate(unsigned rate) ...@@ -129,7 +130,7 @@ static inline unsigned get_usb_high_speed_rate(unsigned rate)
void usb_stream_free(struct usb_stream_kernel *sk) void usb_stream_free(struct usb_stream_kernel *sk)
{ {
struct usb_stream *s; struct usb_stream *s;
unsigned u; unsigned int u;
for (u = 0; u < USB_STREAM_NURBS; ++u) { for (u = 0; u < USB_STREAM_NURBS; ++u) {
usb_free_urb(sk->inurb[u]); usb_free_urb(sk->inurb[u]);
...@@ -150,9 +151,12 @@ void usb_stream_free(struct usb_stream_kernel *sk) ...@@ -150,9 +151,12 @@ void usb_stream_free(struct usb_stream_kernel *sk)
struct usb_stream *usb_stream_new(struct usb_stream_kernel *sk, struct usb_stream *usb_stream_new(struct usb_stream_kernel *sk,
struct usb_device *dev, struct usb_device *dev,
unsigned in_endpoint, unsigned out_endpoint, unsigned int in_endpoint,
unsigned sample_rate, unsigned use_packsize, unsigned int out_endpoint,
unsigned period_frames, unsigned frame_size) unsigned int sample_rate,
unsigned int use_packsize,
unsigned int period_frames,
unsigned int frame_size)
{ {
int packets, max_packsize; int packets, max_packsize;
int in_pipe, out_pipe; int in_pipe, out_pipe;
...@@ -528,7 +532,7 @@ static void stream_start(struct usb_stream_kernel *sk, ...@@ -528,7 +532,7 @@ static void stream_start(struct usb_stream_kernel *sk,
if (s->state >= usb_stream_sync1) { if (s->state >= usb_stream_sync1) {
int l, p, max_diff, max_diff_0; int l, p, max_diff, max_diff_0;
int urb_size = 0; int urb_size = 0;
unsigned frames_per_packet, min_frames = 0; unsigned int frames_per_packet, min_frames = 0;
frames_per_packet = (s->period_size - s->idle_insize); frames_per_packet = (s->period_size - s->idle_insize);
frames_per_packet <<= 8; frames_per_packet <<= 8;
...@@ -570,7 +574,7 @@ static void stream_start(struct usb_stream_kernel *sk, ...@@ -570,7 +574,7 @@ static void stream_start(struct usb_stream_kernel *sk,
(s->inpacket_head + 1) % s->inpackets; (s->inpacket_head + 1) % s->inpackets;
s->next_inpacket_split_at = 0; s->next_inpacket_split_at = 0;
} else { } else {
unsigned split = s->inpacket_head; unsigned int split = s->inpacket_head;
l = s->idle_insize; l = s->idle_insize;
while (l > s->inpacket[split].length) { while (l > s->inpacket[split].length) {
......
...@@ -12,7 +12,7 @@ struct usb_stream_kernel { ...@@ -12,7 +12,7 @@ struct usb_stream_kernel {
void *write_page; void *write_page;
unsigned n_o_ps; unsigned int n_o_ps;
struct urb *inurb[USB_STREAM_NURBS]; struct urb *inurb[USB_STREAM_NURBS];
struct urb *idle_inurb; struct urb *idle_inurb;
...@@ -26,18 +26,21 @@ struct usb_stream_kernel { ...@@ -26,18 +26,21 @@ struct usb_stream_kernel {
wait_queue_head_t sleep; wait_queue_head_t sleep;
unsigned out_phase; unsigned int out_phase;
unsigned out_phase_peeked; unsigned int out_phase_peeked;
unsigned freqn; unsigned int freqn;
}; };
struct usb_stream *usb_stream_new(struct usb_stream_kernel *sk, struct usb_stream *usb_stream_new(struct usb_stream_kernel *sk,
struct usb_device *dev, struct usb_device *dev,
unsigned in_endpoint, unsigned out_endpoint, unsigned int in_endpoint,
unsigned sample_rate, unsigned use_packsize, unsigned int out_endpoint,
unsigned period_frames, unsigned frame_size); unsigned int sample_rate,
void usb_stream_free(struct usb_stream_kernel *); unsigned int use_packsize,
int usb_stream_start(struct usb_stream_kernel *); unsigned int period_frames,
void usb_stream_stop(struct usb_stream_kernel *); unsigned int frame_size);
void usb_stream_free(struct usb_stream_kernel *sk);
int usb_stream_start(struct usb_stream_kernel *sk);
void usb_stream_stop(struct usb_stream_kernel *sk);
#endif /* __USB_STREAM_H */ #endif /* __USB_STREAM_H */
...@@ -163,7 +163,7 @@ static void i_usx2y_out04_int(struct urb *urb) ...@@ -163,7 +163,7 @@ static void i_usx2y_out04_int(struct urb *urb)
for (i = 0; i < 10 && usx2y->as04.urb[i] != urb; i++) for (i = 0; i < 10 && usx2y->as04.urb[i] != urb; i++)
; ;
snd_printdd("i_usx2y_out04_int() urb %i status=%i\n", i, urb->status); snd_printdd("%s urb %i status=%i\n", __func__, i, urb->status);
} }
#endif #endif
} }
...@@ -173,6 +173,8 @@ static void i_usx2y_in04_int(struct urb *urb) ...@@ -173,6 +173,8 @@ static void i_usx2y_in04_int(struct urb *urb)
int err = 0; int err = 0;
struct usx2ydev *usx2y = urb->context; struct usx2ydev *usx2y = urb->context;
struct us428ctls_sharedmem *us428ctls = usx2y->us428ctls_sharedmem; struct us428ctls_sharedmem *us428ctls = usx2y->us428ctls_sharedmem;
struct us428_p4out *p4out;
int i, j, n, diff, send;
usx2y->in04_int_calls++; usx2y->in04_int_calls++;
...@@ -183,15 +185,12 @@ static void i_usx2y_in04_int(struct urb *urb) ...@@ -183,15 +185,12 @@ static void i_usx2y_in04_int(struct urb *urb)
// printk("%i:0x%02X ", 8, (int)((unsigned char*)usx2y->in04_buf)[8]); Master volume shows 0 here if fader is at max during boot ?!? // printk("%i:0x%02X ", 8, (int)((unsigned char*)usx2y->in04_buf)[8]); Master volume shows 0 here if fader is at max during boot ?!?
if (us428ctls) { if (us428ctls) {
int diff = -1; diff = -1;
if (us428ctls->ctl_snapshot_last == -2) {
if (-2 == us428ctls->ctl_snapshot_last) {
diff = 0; diff = 0;
memcpy(usx2y->in04_last, usx2y->in04_buf, sizeof(usx2y->in04_last)); memcpy(usx2y->in04_last, usx2y->in04_buf, sizeof(usx2y->in04_last));
us428ctls->ctl_snapshot_last = -1; us428ctls->ctl_snapshot_last = -1;
} else { } else {
int i;
for (i = 0; i < 21; i++) { for (i = 0; i < 21; i++) {
if (usx2y->in04_last[i] != ((char *)usx2y->in04_buf)[i]) { if (usx2y->in04_last[i] != ((char *)usx2y->in04_buf)[i]) {
if (diff < 0) if (diff < 0)
...@@ -200,9 +199,8 @@ static void i_usx2y_in04_int(struct urb *urb) ...@@ -200,9 +199,8 @@ static void i_usx2y_in04_int(struct urb *urb)
} }
} }
} }
if (0 <= diff) { if (diff >= 0) {
int n = us428ctls->ctl_snapshot_last + 1; n = us428ctls->ctl_snapshot_last + 1;
if (n >= N_US428_CTL_BUFS || n < 0) if (n >= N_US428_CTL_BUFS || n < 0)
n = 0; n = 0;
memcpy(us428ctls->ctl_snapshot + n, usx2y->in04_buf, sizeof(us428ctls->ctl_snapshot[0])); memcpy(us428ctls->ctl_snapshot + n, usx2y->in04_buf, sizeof(us428ctls->ctl_snapshot[0]));
...@@ -213,21 +211,20 @@ static void i_usx2y_in04_int(struct urb *urb) ...@@ -213,21 +211,20 @@ static void i_usx2y_in04_int(struct urb *urb)
} }
if (usx2y->us04) { if (usx2y->us04) {
if (0 == usx2y->us04->submitted) if (!usx2y->us04->submitted) {
do { do {
err = usb_submit_urb(usx2y->us04->urb[usx2y->us04->submitted++], GFP_ATOMIC); err = usb_submit_urb(usx2y->us04->urb[usx2y->us04->submitted++], GFP_ATOMIC);
} while (!err && usx2y->us04->submitted < usx2y->us04->len); } while (!err && usx2y->us04->submitted < usx2y->us04->len);
} else }
} else {
if (us428ctls && us428ctls->p4out_last >= 0 && us428ctls->p4out_last < N_US428_P4OUT_BUFS) { if (us428ctls && us428ctls->p4out_last >= 0 && us428ctls->p4out_last < N_US428_P4OUT_BUFS) {
if (us428ctls->p4out_last != us428ctls->p4out_sent) { if (us428ctls->p4out_last != us428ctls->p4out_sent) {
int j, send = us428ctls->p4out_sent + 1; send = us428ctls->p4out_sent + 1;
if (send >= N_US428_P4OUT_BUFS) if (send >= N_US428_P4OUT_BUFS)
send = 0; send = 0;
for (j = 0; j < URBS_ASYNC_SEQ && !err; ++j) for (j = 0; j < URBS_ASYNC_SEQ && !err; ++j) {
if (0 == usx2y->as04.urb[j]->status) { if (!usx2y->as04.urb[j]->status) {
struct us428_p4out *p4out = us428ctls->p4out + send; // FIXME if more than 1 p4out is new, 1 gets lost. p4out = us428ctls->p4out + send; // FIXME if more than 1 p4out is new, 1 gets lost.
usb_fill_bulk_urb(usx2y->as04.urb[j], usx2y->dev, usb_fill_bulk_urb(usx2y->as04.urb[j], usx2y->dev,
usb_sndbulkpipe(usx2y->dev, 0x04), &p4out->val.vol, usb_sndbulkpipe(usx2y->dev, 0x04), &p4out->val.vol,
p4out->type == ELT_LIGHT ? sizeof(struct us428_lights) : 5, p4out->type == ELT_LIGHT ? sizeof(struct us428_lights) : 5,
...@@ -238,6 +235,8 @@ static void i_usx2y_in04_int(struct urb *urb) ...@@ -238,6 +235,8 @@ static void i_usx2y_in04_int(struct urb *urb)
} }
} }
} }
}
}
if (err) if (err)
snd_printk(KERN_ERR "in04_int() usb_submit_urb err=%i\n", err); snd_printk(KERN_ERR "in04_int() usb_submit_urb err=%i\n", err);
...@@ -255,31 +254,35 @@ int usx2y_async_seq04_init(struct usx2ydev *usx2y) ...@@ -255,31 +254,35 @@ int usx2y_async_seq04_init(struct usx2ydev *usx2y)
usx2y->as04.buffer = kmalloc_array(URBS_ASYNC_SEQ, usx2y->as04.buffer = kmalloc_array(URBS_ASYNC_SEQ,
URB_DATA_LEN_ASYNC_SEQ, GFP_KERNEL); URB_DATA_LEN_ASYNC_SEQ, GFP_KERNEL);
if (NULL == usx2y->as04.buffer) { if (!usx2y->as04.buffer) {
err = -ENOMEM; err = -ENOMEM;
} else } else {
for (i = 0; i < URBS_ASYNC_SEQ; ++i) { for (i = 0; i < URBS_ASYNC_SEQ; ++i) {
if (NULL == (usx2y->as04.urb[i] = usb_alloc_urb(0, GFP_KERNEL))) { usx2y->as04.urb[i] = usb_alloc_urb(0, GFP_KERNEL);
if (!usx2y->as04.urb[i]) {
err = -ENOMEM; err = -ENOMEM;
break; break;
} }
usb_fill_bulk_urb(usx2y->as04.urb[i], usx2y->dev, usb_fill_bulk_urb(usx2y->as04.urb[i], usx2y->dev,
usb_sndbulkpipe(usx2y->dev, 0x04), usb_sndbulkpipe(usx2y->dev, 0x04),
usx2y->as04.buffer + URB_DATA_LEN_ASYNC_SEQ*i, 0, usx2y->as04.buffer + URB_DATA_LEN_ASYNC_SEQ * i, 0,
i_usx2y_out04_int, usx2y); i_usx2y_out04_int, usx2y);
err = usb_urb_ep_type_check(usx2y->as04.urb[i]); err = usb_urb_ep_type_check(usx2y->as04.urb[i]);
if (err < 0) if (err < 0)
break; break;
} }
}
return err; return err;
} }
int usx2y_in04_init(struct usx2ydev *usx2y) int usx2y_in04_init(struct usx2ydev *usx2y)
{ {
if (!(usx2y->in04_urb = usb_alloc_urb(0, GFP_KERNEL))) usx2y->in04_urb = usb_alloc_urb(0, GFP_KERNEL);
if (!usx2y->in04_urb)
return -ENOMEM; return -ENOMEM;
if (!(usx2y->in04_buf = kmalloc(21, GFP_KERNEL))) usx2y->in04_buf = kmalloc(21, GFP_KERNEL);
if (!usx2y->in04_buf)
return -ENOMEM; return -ENOMEM;
init_waitqueue_head(&usx2y->in04_wait_queue); init_waitqueue_head(&usx2y->in04_wait_queue);
...@@ -354,8 +357,7 @@ static int usx2y_create_card(struct usb_device *device, ...@@ -354,8 +357,7 @@ static int usx2y_create_card(struct usb_device *device,
le16_to_cpu(device->descriptor.idVendor), le16_to_cpu(device->descriptor.idVendor),
le16_to_cpu(device->descriptor.idProduct), le16_to_cpu(device->descriptor.idProduct),
0,//us428(card)->usbmidi.ifnum, 0,//us428(card)->usbmidi.ifnum,
usx2y(card)->dev->bus->busnum, usx2y(card)->dev->devnum usx2y(card)->dev->bus->busnum, usx2y(card)->dev->devnum);
);
*cardp = card; *cardp = card;
return 0; return 0;
} }
...@@ -378,13 +380,18 @@ static int usx2y_usb_probe(struct usb_device *device, ...@@ -378,13 +380,18 @@ static int usx2y_usb_probe(struct usb_device *device,
err = usx2y_create_card(device, intf, &card); err = usx2y_create_card(device, intf, &card);
if (err < 0) if (err < 0)
return err; return err;
if ((err = usx2y_hwdep_new(card, device)) < 0 || err = usx2y_hwdep_new(card, device);
(err = snd_card_register(card)) < 0) { if (err < 0)
snd_card_free(card); goto error;
return err; err = snd_card_register(card);
} if (err < 0)
goto error;
*cardp = card; *cardp = card;
return 0; return 0;
error:
snd_card_free(card);
return err;
} }
/* /*
...@@ -417,13 +424,15 @@ static struct usb_driver snd_usx2y_usb_driver = { ...@@ -417,13 +424,15 @@ static struct usb_driver snd_usx2y_usb_driver = {
static void snd_usx2y_card_private_free(struct snd_card *card) static void snd_usx2y_card_private_free(struct snd_card *card)
{ {
kfree(usx2y(card)->in04_buf); struct usx2ydev *usx2y = usx2y(card);
usb_free_urb(usx2y(card)->in04_urb);
if (usx2y(card)->us428ctls_sharedmem) kfree(usx2y->in04_buf);
free_pages_exact(usx2y(card)->us428ctls_sharedmem, usb_free_urb(usx2y->in04_urb);
sizeof(*usx2y(card)->us428ctls_sharedmem)); if (usx2y->us428ctls_sharedmem)
if (usx2y(card)->card_index >= 0 && usx2y(card)->card_index < SNDRV_CARDS) free_pages_exact(usx2y->us428ctls_sharedmem,
snd_usx2y_card_used[usx2y(card)->card_index] = 0; sizeof(*usx2y->us428ctls_sharedmem));
if (usx2y->card_index >= 0 && usx2y->card_index < SNDRV_CARDS)
snd_usx2y_card_used[usx2y->card_index] = 0;
} }
/* /*
...@@ -431,15 +440,19 @@ static void snd_usx2y_card_private_free(struct snd_card *card) ...@@ -431,15 +440,19 @@ static void snd_usx2y_card_private_free(struct snd_card *card)
*/ */
static void usx2y_usb_disconnect(struct usb_device *device, void *ptr) static void usx2y_usb_disconnect(struct usb_device *device, void *ptr)
{ {
if (ptr) { struct snd_card *card;
struct snd_card *card = ptr; struct usx2ydev *usx2y;
struct usx2ydev *usx2y = usx2y(card);
struct list_head *p; struct list_head *p;
if (!ptr)
return;
card = ptr;
usx2y = usx2y(card);
usx2y->chip_status = USX2Y_STAT_CHIP_HUP; usx2y->chip_status = USX2Y_STAT_CHIP_HUP;
usx2y_unlinkseq(&usx2y->as04); usx2y_unlinkseq(&usx2y->as04);
usb_kill_urb(usx2y->in04_urb); usb_kill_urb(usx2y->in04_urb);
snd_card_disconnect(card); snd_card_disconnect(card);
/* release the midi resources */ /* release the midi resources */
list_for_each(p, &usx2y->midi_list) { list_for_each(p, &usx2y->midi_list) {
snd_usbmidi_disconnect(p); snd_usbmidi_disconnect(p);
...@@ -447,7 +460,6 @@ static void usx2y_usb_disconnect(struct usb_device *device, void *ptr) ...@@ -447,7 +460,6 @@ static void usx2y_usb_disconnect(struct usb_device *device, void *ptr)
if (usx2y->us428ctls_sharedmem) if (usx2y->us428ctls_sharedmem)
wake_up(&usx2y->us428ctls_wait_queue_head); wake_up(&usx2y->us428ctls_wait_queue_head);
snd_card_free(card); snd_card_free(card);
}
} }
module_usb_driver(snd_usx2y_usb_driver); module_usb_driver(snd_usx2y_usb_driver);
...@@ -30,7 +30,7 @@ struct usx2ydev { ...@@ -30,7 +30,7 @@ struct usx2ydev {
struct urb *in04_urb; struct urb *in04_urb;
void *in04_buf; void *in04_buf;
char in04_last[24]; char in04_last[24];
unsigned in04_int_calls; unsigned int in04_int_calls;
struct snd_usx2y_urb_seq *us04; struct snd_usx2y_urb_seq *us04;
wait_queue_head_t in04_wait_queue; wait_queue_head_t in04_wait_queue;
struct snd_usx2y_async_seq as04; struct snd_usx2y_async_seq as04;
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment