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)
goto unlock;
offset = vmf->pgoff << PAGE_SHIFT;
if (offset < PAGE_ALIGN(s->read_size))
if (offset < PAGE_ALIGN(s->read_size)) {
vaddr = (char *)s + offset;
else {
} else {
offset -= PAGE_ALIGN(s->read_size);
if (offset >= PAGE_ALIGN(s->write_size))
goto unlock;
......@@ -238,7 +238,7 @@ static __poll_t usb_stream_hwdep_poll(struct snd_hwdep *hw,
struct file *file, poll_table *wait)
{
struct us122l *us122l = hw->private_data;
unsigned *polled;
unsigned int *polled;
__poll_t mask;
poll_wait(file, &us122l->sk.sleep, wait);
......@@ -255,8 +255,9 @@ static __poll_t usb_stream_hwdep_poll(struct snd_hwdep *hw,
if (*polled != s->periods_done) {
*polled = s->periods_done;
mask = EPOLLIN | EPOLLOUT | EPOLLWRNORM;
} else
} else {
mask = 0;
}
}
mutex_unlock(&us122l->mutex);
}
......@@ -294,11 +295,11 @@ static int us122l_set_sample_rate(struct usb_device *dev, int rate)
}
static bool us122l_start(struct us122l *us122l,
unsigned rate, unsigned period_frames)
unsigned int rate, unsigned int period_frames)
{
struct list_head *p;
int err;
unsigned use_packsize = 0;
unsigned int use_packsize = 0;
bool success = false;
if (us122l->dev->speed == USB_SPEED_HIGH) {
......@@ -331,7 +332,7 @@ static bool us122l_start(struct us122l *us122l,
err = usb_stream_start(&us122l->sk);
if (err < 0) {
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;
}
list_for_each(p, &us122l->midi_list)
......@@ -342,12 +343,12 @@ static bool us122l_start(struct us122l *us122l,
}
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 us122l *us122l = hw->private_data;
struct usb_stream *s;
unsigned min_period_frames;
unsigned int min_period_frames;
int err = 0;
bool high_speed;
......@@ -388,9 +389,9 @@ static int usb_stream_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
mutex_lock(&us122l->mutex);
s = us122l->sk.s;
if (!us122l->master)
if (!us122l->master) {
us122l->master = file;
else if (us122l->master != file) {
} else if (us122l->master != file) {
if (!s || memcmp(&cfg, &s->cfg, sizeof(cfg))) {
err = -EIO;
goto unlock;
......@@ -490,7 +491,7 @@ static void snd_us122l_free(struct snd_card *card)
struct us122l *us122l = US122L(card);
int index = us122l->card_index;
if (index >= 0 && index < SNDRV_CARDS)
if (index >= 0 && index < SNDRV_CARDS)
snd_us122l_card_used[index] = 0;
}
......
......@@ -11,7 +11,7 @@ struct us122l {
struct mutex mutex;
struct file *first;
unsigned second_periods_polled;
unsigned int second_periods_polled;
struct file *master;
struct file *slave;
struct list_head midi_list;
......
......@@ -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);
if (shm != NULL && shm->ctl_snapshot_last != shm->ctl_snapshot_red)
if (shm && shm->ctl_snapshot_last != shm->ctl_snapshot_red)
mask |= EPOLLIN;
return mask;
......@@ -114,7 +114,7 @@ static int snd_usx2y_hwdep_dsp_status(struct snd_hwdep *hw,
id = USX2Y_TYPE_428;
break;
}
if (0 > id)
if (id < 0)
return -ENODEV;
strcpy(info->id, type_ids[id]);
info->num_dsps = 2; // 0: Prepad Data, 1: FPGA Code
......@@ -158,7 +158,7 @@ static int usx2y_create_usbmidi(struct snd_card *card)
le16_to_cpu(dev->descriptor.idProduct) == USB_ID_US428 ?
&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);
}
......@@ -166,20 +166,21 @@ static int usx2y_create_alsa_devices(struct snd_card *card)
{
int err;
do {
if ((err = usx2y_create_usbmidi(card)) < 0) {
snd_printk(KERN_ERR "usx2y_create_alsa_devices: usx2y_create_usbmidi error %i\n", err);
break;
}
if ((err = usx2y_audio_create(card)) < 0)
break;
if ((err = usx2y_hwdep_pcm_new(card)) < 0)
break;
if ((err = snd_card_register(card)) < 0)
break;
} while (0);
return err;
err = usx2y_create_usbmidi(card);
if (err < 0) {
snd_printk(KERN_ERR "%s: usx2y_create_usbmidi error %i\n", __func__, err);
return err;
}
err = usx2y_audio_create(card);
if (err < 0)
return err;
err = usx2y_hwdep_pcm_new(card);
if (err < 0)
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,
......@@ -233,7 +234,8 @@ int usx2y_hwdep_new(struct snd_card *card, struct usb_device *device)
int err;
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;
hw->iface = SNDRV_HWDEP_IFACE_USX2Y;
......
......@@ -10,7 +10,7 @@
/* 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;
......@@ -44,9 +44,10 @@ static void playback_prep_freqn(struct usb_stream_kernel *sk, struct urb *urb)
lb, s->period_size);
}
static int init_pipe_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
struct urb **urbs, char *transfer,
struct usb_device *dev, int pipe)
static int init_pipe_urbs(struct usb_stream_kernel *sk,
unsigned int use_packsize,
struct urb **urbs, char *transfer,
struct usb_device *dev, int pipe)
{
int u, p;
int maxpacket = use_packsize ?
......@@ -82,8 +83,8 @@ static int init_pipe_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
return 0;
}
static int init_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
struct usb_device *dev, int in_pipe, int out_pipe)
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_stream *s = sk->s;
char *indata =
......@@ -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)
* 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;
}
......@@ -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)
* 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;
}
......@@ -129,7 +130,7 @@ static inline unsigned get_usb_high_speed_rate(unsigned rate)
void usb_stream_free(struct usb_stream_kernel *sk)
{
struct usb_stream *s;
unsigned u;
unsigned int u;
for (u = 0; u < USB_STREAM_NURBS; ++u) {
usb_free_urb(sk->inurb[u]);
......@@ -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_device *dev,
unsigned in_endpoint, unsigned out_endpoint,
unsigned sample_rate, unsigned use_packsize,
unsigned period_frames, unsigned frame_size)
unsigned int in_endpoint,
unsigned int out_endpoint,
unsigned int sample_rate,
unsigned int use_packsize,
unsigned int period_frames,
unsigned int frame_size)
{
int packets, max_packsize;
int in_pipe, out_pipe;
......@@ -528,7 +532,7 @@ static void stream_start(struct usb_stream_kernel *sk,
if (s->state >= usb_stream_sync1) {
int l, p, max_diff, max_diff_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 <<= 8;
......@@ -570,7 +574,7 @@ static void stream_start(struct usb_stream_kernel *sk,
(s->inpacket_head + 1) % s->inpackets;
s->next_inpacket_split_at = 0;
} else {
unsigned split = s->inpacket_head;
unsigned int split = s->inpacket_head;
l = s->idle_insize;
while (l > s->inpacket[split].length) {
......
......@@ -12,7 +12,7 @@ struct usb_stream_kernel {
void *write_page;
unsigned n_o_ps;
unsigned int n_o_ps;
struct urb *inurb[USB_STREAM_NURBS];
struct urb *idle_inurb;
......@@ -26,18 +26,21 @@ struct usb_stream_kernel {
wait_queue_head_t sleep;
unsigned out_phase;
unsigned out_phase_peeked;
unsigned freqn;
unsigned int out_phase;
unsigned int out_phase_peeked;
unsigned int freqn;
};
struct usb_stream *usb_stream_new(struct usb_stream_kernel *sk,
struct usb_device *dev,
unsigned in_endpoint, unsigned out_endpoint,
unsigned sample_rate, unsigned use_packsize,
unsigned period_frames, unsigned frame_size);
void usb_stream_free(struct usb_stream_kernel *);
int usb_stream_start(struct usb_stream_kernel *);
void usb_stream_stop(struct usb_stream_kernel *);
unsigned int in_endpoint,
unsigned int out_endpoint,
unsigned int sample_rate,
unsigned int use_packsize,
unsigned int period_frames,
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 */
......@@ -163,7 +163,7 @@ static void i_usx2y_out04_int(struct urb *urb)
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
}
......@@ -173,6 +173,8 @@ static void i_usx2y_in04_int(struct urb *urb)
int err = 0;
struct usx2ydev *usx2y = urb->context;
struct us428ctls_sharedmem *us428ctls = usx2y->us428ctls_sharedmem;
struct us428_p4out *p4out;
int i, j, n, diff, send;
usx2y->in04_int_calls++;
......@@ -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 ?!?
if (us428ctls) {
int diff = -1;
if (-2 == us428ctls->ctl_snapshot_last) {
diff = -1;
if (us428ctls->ctl_snapshot_last == -2) {
diff = 0;
memcpy(usx2y->in04_last, usx2y->in04_buf, sizeof(usx2y->in04_last));
us428ctls->ctl_snapshot_last = -1;
} else {
int i;
for (i = 0; i < 21; i++) {
if (usx2y->in04_last[i] != ((char *)usx2y->in04_buf)[i]) {
if (diff < 0)
......@@ -200,10 +199,9 @@ static void i_usx2y_in04_int(struct urb *urb)
}
}
}
if (0 <= diff) {
int n = us428ctls->ctl_snapshot_last + 1;
if (n >= N_US428_CTL_BUFS || n < 0)
if (diff >= 0) {
n = us428ctls->ctl_snapshot_last + 1;
if (n >= N_US428_CTL_BUFS || n < 0)
n = 0;
memcpy(us428ctls->ctl_snapshot + n, usx2y->in04_buf, sizeof(us428ctls->ctl_snapshot[0]));
us428ctls->ctl_snapshot_differs_at[n] = diff;
......@@ -213,21 +211,20 @@ static void i_usx2y_in04_int(struct urb *urb)
}
if (usx2y->us04) {
if (0 == usx2y->us04->submitted)
if (!usx2y->us04->submitted) {
do {
err = usb_submit_urb(usx2y->us04->urb[usx2y->us04->submitted++], GFP_ATOMIC);
} 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->p4out_last != us428ctls->p4out_sent) {
int j, send = us428ctls->p4out_sent + 1;
send = us428ctls->p4out_sent + 1;
if (send >= N_US428_P4OUT_BUFS)
send = 0;
for (j = 0; j < URBS_ASYNC_SEQ && !err; ++j)
if (0 == usx2y->as04.urb[j]->status) {
struct us428_p4out *p4out = us428ctls->p4out + send; // FIXME if more than 1 p4out is new, 1 gets lost.
for (j = 0; j < URBS_ASYNC_SEQ && !err; ++j) {
if (!usx2y->as04.urb[j]->status) {
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_sndbulkpipe(usx2y->dev, 0x04), &p4out->val.vol,
p4out->type == ELT_LIGHT ? sizeof(struct us428_lights) : 5,
......@@ -236,8 +233,10 @@ static void i_usx2y_in04_int(struct urb *urb)
us428ctls->p4out_sent = send;
break;
}
}
}
}
}
if (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)
usx2y->as04.buffer = kmalloc_array(URBS_ASYNC_SEQ,
URB_DATA_LEN_ASYNC_SEQ, GFP_KERNEL);
if (NULL == usx2y->as04.buffer) {
if (!usx2y->as04.buffer) {
err = -ENOMEM;
} else
} else {
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;
break;
}
usb_fill_bulk_urb(usx2y->as04.urb[i], usx2y->dev,
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);
err = usb_urb_ep_type_check(usx2y->as04.urb[i]);
if (err < 0)
break;
}
}
return err;
}
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;
if (!(usx2y->in04_buf = kmalloc(21, GFP_KERNEL)))
usx2y->in04_buf = kmalloc(21, GFP_KERNEL);
if (!usx2y->in04_buf)
return -ENOMEM;
init_waitqueue_head(&usx2y->in04_wait_queue);
......@@ -354,8 +357,7 @@ static int usx2y_create_card(struct usb_device *device,
le16_to_cpu(device->descriptor.idVendor),
le16_to_cpu(device->descriptor.idProduct),
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;
return 0;
}
......@@ -378,13 +380,18 @@ static int usx2y_usb_probe(struct usb_device *device,
err = usx2y_create_card(device, intf, &card);
if (err < 0)
return err;
if ((err = usx2y_hwdep_new(card, device)) < 0 ||
(err = snd_card_register(card)) < 0) {
snd_card_free(card);
return err;
}
err = usx2y_hwdep_new(card, device);
if (err < 0)
goto error;
err = snd_card_register(card);
if (err < 0)
goto error;
*cardp = card;
return 0;
error:
snd_card_free(card);
return err;
}
/*
......@@ -405,7 +412,7 @@ static int snd_usx2y_probe(struct usb_interface *intf, const struct usb_device_i
static void snd_usx2y_disconnect(struct usb_interface *intf)
{
usx2y_usb_disconnect(interface_to_usbdev(intf),
usb_get_intfdata(intf));
usb_get_intfdata(intf));
}
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)
{
kfree(usx2y(card)->in04_buf);
usb_free_urb(usx2y(card)->in04_urb);
if (usx2y(card)->us428ctls_sharedmem)
free_pages_exact(usx2y(card)->us428ctls_sharedmem,
sizeof(*usx2y(card)->us428ctls_sharedmem));
if (usx2y(card)->card_index >= 0 && usx2y(card)->card_index < SNDRV_CARDS)
snd_usx2y_card_used[usx2y(card)->card_index] = 0;
struct usx2ydev *usx2y = usx2y(card);
kfree(usx2y->in04_buf);
usb_free_urb(usx2y->in04_urb);
if (usx2y->us428ctls_sharedmem)
free_pages_exact(usx2y->us428ctls_sharedmem,
sizeof(*usx2y->us428ctls_sharedmem));
if (usx2y->card_index >= 0 && usx2y->card_index < SNDRV_CARDS)
snd_usx2y_card_used[usx2y->card_index] = 0;
}
/*
......@@ -431,23 +440,26 @@ static void snd_usx2y_card_private_free(struct snd_card *card)
*/
static void usx2y_usb_disconnect(struct usb_device *device, void *ptr)
{
if (ptr) {
struct snd_card *card = ptr;
struct usx2ydev *usx2y = usx2y(card);
struct list_head *p;
usx2y->chip_status = USX2Y_STAT_CHIP_HUP;
usx2y_unlinkseq(&usx2y->as04);
usb_kill_urb(usx2y->in04_urb);
snd_card_disconnect(card);
/* release the midi resources */
list_for_each(p, &usx2y->midi_list) {
snd_usbmidi_disconnect(p);
}
if (usx2y->us428ctls_sharedmem)
wake_up(&usx2y->us428ctls_wait_queue_head);
snd_card_free(card);
struct snd_card *card;
struct usx2ydev *usx2y;
struct list_head *p;
if (!ptr)
return;
card = ptr;
usx2y = usx2y(card);
usx2y->chip_status = USX2Y_STAT_CHIP_HUP;
usx2y_unlinkseq(&usx2y->as04);
usb_kill_urb(usx2y->in04_urb);
snd_card_disconnect(card);
/* release the midi resources */
list_for_each(p, &usx2y->midi_list) {
snd_usbmidi_disconnect(p);
}
if (usx2y->us428ctls_sharedmem)
wake_up(&usx2y->us428ctls_wait_queue_head);
snd_card_free(card);
}
module_usb_driver(snd_usx2y_usb_driver);
......@@ -30,7 +30,7 @@ struct usx2ydev {
struct urb *in04_urb;
void *in04_buf;
char in04_last[24];
unsigned in04_int_calls;
unsigned int in04_int_calls;
struct snd_usx2y_urb_seq *us04;
wait_queue_head_t in04_wait_queue;
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