Skip to content

Commit

Permalink
ALSA: seq: Fix assignment in if condition
Browse files Browse the repository at this point in the history
There are lots of places doing assignments in if condition in ALSA
sequencer core, which is a bad coding style that may confuse readers
and occasionally lead to bugs.

This patch is merely for coding-style fixes, no functional changes.

Link: https://lore.kernel.org/r/20210608140540.17885-57-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
  • Loading branch information
tiwai committed Jun 9, 2021
1 parent 51c816f commit f9a6bb8
Show file tree
Hide file tree
Showing 13 changed files with 131 additions and 72 deletions.
26 changes: 16 additions & 10 deletions sound/core/seq/oss/seq_oss.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,16 @@ static int __init alsa_seq_oss_init(void)
{
int rc;

if ((rc = register_device()) < 0)
rc = register_device();
if (rc < 0)
goto error;
if ((rc = register_proc()) < 0) {
rc = register_proc();
if (rc < 0) {
unregister_device();
goto error;
}
if ((rc = snd_seq_oss_create_client()) < 0) {
rc = snd_seq_oss_create_client();
if (rc < 0) {
unregister_proc();
unregister_device();
goto error;
Expand Down Expand Up @@ -133,7 +136,8 @@ odev_release(struct inode *inode, struct file *file)
{
struct seq_oss_devinfo *dp;

if ((dp = file->private_data) == NULL)
dp = file->private_data;
if (!dp)
return 0;

mutex_lock(&register_mutex);
Expand Down Expand Up @@ -226,16 +230,18 @@ register_device(void)
int rc;

mutex_lock(&register_mutex);
if ((rc = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER,
NULL, 0,
&seq_oss_f_ops, NULL)) < 0) {
rc = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER,
NULL, 0,
&seq_oss_f_ops, NULL);
if (rc < 0) {
pr_err("ALSA: seq_oss: can't register device seq\n");
mutex_unlock(&register_mutex);
return rc;
}
if ((rc = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_MUSIC,
NULL, 0,
&seq_oss_f_ops, NULL)) < 0) {
rc = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_MUSIC,
NULL, 0,
&seq_oss_f_ops, NULL);
if (rc < 0) {
pr_err("ALSA: seq_oss: can't register device music\n");
snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER, NULL, 0);
mutex_unlock(&register_mutex);
Expand Down
9 changes: 6 additions & 3 deletions sound/core/seq/oss/seq_oss_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ snd_seq_oss_create_client(void)
port->kernel = &port_callback;

call_ctl(SNDRV_SEQ_IOCTL_CREATE_PORT, port);
if ((system_port = port->addr.port) >= 0) {
system_port = port->addr.port;
if (system_port >= 0) {
struct snd_seq_port_subscribe subs;

memset(&subs, 0, sizeof(subs));
Expand Down Expand Up @@ -354,7 +355,8 @@ alloc_seq_queue(struct seq_oss_devinfo *dp)
qinfo.owner = system_client;
qinfo.locked = 1;
strcpy(qinfo.name, "OSS Sequencer Emulation");
if ((rc = call_ctl(SNDRV_SEQ_IOCTL_CREATE_QUEUE, &qinfo)) < 0)
rc = call_ctl(SNDRV_SEQ_IOCTL_CREATE_QUEUE, &qinfo);
if (rc < 0)
return rc;
dp->queue = qinfo.queue;
return 0;
Expand Down Expand Up @@ -485,7 +487,8 @@ snd_seq_oss_system_info_read(struct snd_info_buffer *buf)
snd_iprintf(buf, "\nNumber of applications: %d\n", num_clients);
for (i = 0; i < num_clients; i++) {
snd_iprintf(buf, "\nApplication %d: ", i);
if ((dp = client_table[i]) == NULL) {
dp = client_table[i];
if (!dp) {
snd_iprintf(buf, "*empty*\n");
continue;
}
Expand Down
33 changes: 22 additions & 11 deletions sound/core/seq/oss/seq_oss_midi.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ snd_seq_oss_midi_check_new_port(struct snd_seq_port_info *pinfo)
/*
* look for the identical slot
*/
if ((mdev = find_slot(pinfo->addr.client, pinfo->addr.port)) != NULL) {
mdev = find_slot(pinfo->addr.client, pinfo->addr.port);
if (mdev) {
/* already exists */
snd_use_lock_free(&mdev->use_lock);
return 0;
Expand Down Expand Up @@ -218,7 +219,8 @@ snd_seq_oss_midi_check_exit_port(int client, int port)
unsigned long flags;
int index;

if ((mdev = find_slot(client, port)) != NULL) {
mdev = find_slot(client, port);
if (mdev) {
spin_lock_irqsave(&register_lock, flags);
midi_devs[mdev->seq_device] = NULL;
spin_unlock_irqrestore(&register_lock, flags);
Expand Down Expand Up @@ -250,7 +252,8 @@ snd_seq_oss_midi_clear_all(void)

spin_lock_irqsave(&register_lock, flags);
for (i = 0; i < max_midi_devs; i++) {
if ((mdev = midi_devs[i]) != NULL) {
mdev = midi_devs[i];
if (mdev) {
snd_midi_event_free(mdev->coder);
kfree(mdev);
midi_devs[i] = NULL;
Expand Down Expand Up @@ -318,7 +321,8 @@ snd_seq_oss_midi_open(struct seq_oss_devinfo *dp, int dev, int fmode)
struct seq_oss_midi *mdev;
struct snd_seq_port_subscribe subs;

if ((mdev = get_mididev(dp, dev)) == NULL)
mdev = get_mididev(dp, dev);
if (!mdev)
return -ENODEV;

/* already used? */
Expand Down Expand Up @@ -384,7 +388,8 @@ snd_seq_oss_midi_close(struct seq_oss_devinfo *dp, int dev)
struct seq_oss_midi *mdev;
struct snd_seq_port_subscribe subs;

if ((mdev = get_mididev(dp, dev)) == NULL)
mdev = get_mididev(dp, dev);
if (!mdev)
return -ENODEV;
if (! mdev->opened || mdev->devinfo != dp) {
snd_use_lock_free(&mdev->use_lock);
Expand Down Expand Up @@ -421,7 +426,8 @@ snd_seq_oss_midi_filemode(struct seq_oss_devinfo *dp, int dev)
struct seq_oss_midi *mdev;
int mode;

if ((mdev = get_mididev(dp, dev)) == NULL)
mdev = get_mididev(dp, dev);
if (!mdev)
return 0;

mode = 0;
Expand All @@ -443,7 +449,8 @@ snd_seq_oss_midi_reset(struct seq_oss_devinfo *dp, int dev)
{
struct seq_oss_midi *mdev;

if ((mdev = get_mididev(dp, dev)) == NULL)
mdev = get_mididev(dp, dev);
if (!mdev)
return;
if (! mdev->opened) {
snd_use_lock_free(&mdev->use_lock);
Expand Down Expand Up @@ -491,7 +498,8 @@ snd_seq_oss_midi_get_addr(struct seq_oss_devinfo *dp, int dev, struct snd_seq_ad
{
struct seq_oss_midi *mdev;

if ((mdev = get_mididev(dp, dev)) == NULL)
mdev = get_mididev(dp, dev);
if (!mdev)
return;
addr->client = mdev->client;
addr->port = mdev->port;
Expand All @@ -511,7 +519,8 @@ snd_seq_oss_midi_input(struct snd_seq_event *ev, int direct, void *private_data)

if (dp->readq == NULL)
return 0;
if ((mdev = find_slot(ev->source.client, ev->source.port)) == NULL)
mdev = find_slot(ev->source.client, ev->source.port);
if (!mdev)
return 0;
if (! (mdev->opened & PERM_READ)) {
snd_use_lock_free(&mdev->use_lock);
Expand Down Expand Up @@ -623,7 +632,8 @@ snd_seq_oss_midi_putc(struct seq_oss_devinfo *dp, int dev, unsigned char c, stru
{
struct seq_oss_midi *mdev;

if ((mdev = get_mididev(dp, dev)) == NULL)
mdev = get_mididev(dp, dev);
if (!mdev)
return -ENODEV;
if (snd_midi_event_encode_byte(mdev->coder, c, ev)) {
snd_seq_oss_fill_addr(dp, ev, mdev->client, mdev->port);
Expand All @@ -642,7 +652,8 @@ snd_seq_oss_midi_make_info(struct seq_oss_devinfo *dp, int dev, struct midi_info
{
struct seq_oss_midi *mdev;

if ((mdev = get_mididev(dp, dev)) == NULL)
mdev = get_mididev(dp, dev);
if (!mdev)
return -ENXIO;
inf->device = dev;
inf->dev_type = 0; /* FIXME: ?? */
Expand Down
3 changes: 2 additions & 1 deletion sound/core/seq/oss/seq_oss_rw.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ snd_seq_oss_write(struct seq_oss_devinfo *dp, const char __user *buf, int count,
}

/* insert queue */
if ((err = insert_queue(dp, &rec, opt)) < 0)
err = insert_queue(dp, &rec, opt);
if (err < 0)
break;

result += ev_size;
Expand Down
9 changes: 6 additions & 3 deletions sound/core/seq/oss/seq_oss_synth.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,8 @@ snd_seq_oss_synth_load_patch(struct seq_oss_devinfo *dp, int dev, int fmt,

if (info->is_midi)
return 0;
if ((rec = get_synthdev(dp, dev)) == NULL)
rec = get_synthdev(dp, dev);
if (!rec)
return -ENXIO;

if (rec->oper.load_patch == NULL)
Expand Down Expand Up @@ -569,7 +570,8 @@ snd_seq_oss_synth_ioctl(struct seq_oss_devinfo *dp, int dev, unsigned int cmd, u
info = get_synthinfo_nospec(dp, dev);
if (!info || info->is_midi)
return -ENXIO;
if ((rec = get_synthdev(dp, dev)) == NULL)
rec = get_synthdev(dp, dev);
if (!rec)
return -ENXIO;
if (rec->oper.ioctl == NULL)
rc = -ENXIO;
Expand Down Expand Up @@ -619,7 +621,8 @@ snd_seq_oss_synth_make_info(struct seq_oss_devinfo *dp, int dev, struct synth_in
inf->device = dev;
strscpy(inf->name, minf.name, sizeof(inf->name));
} else {
if ((rec = get_synthdev(dp, dev)) == NULL)
rec = get_synthdev(dp, dev);
if (!rec)
return -ENXIO;
inf->synth_type = rec->synth_type;
inf->synth_subtype = rec->synth_subtype;
Expand Down
3 changes: 2 additions & 1 deletion sound/core/seq/oss/seq_oss_writeq.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ snd_seq_oss_writeq_new(struct seq_oss_devinfo *dp, int maxlen)
struct seq_oss_writeq *q;
struct snd_seq_client_pool pool;

if ((q = kzalloc(sizeof(*q), GFP_KERNEL)) == NULL)
q = kzalloc(sizeof(*q), GFP_KERNEL);
if (!q)
return NULL;
q->dp = dp;
q->maxlen = maxlen;
Expand Down
51 changes: 34 additions & 17 deletions sound/core/seq/seq_clientmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,10 @@ static ssize_t snd_seq_read(struct file *file, char __user *buf, size_t count,
if (snd_BUG_ON(!client))
return -ENXIO;

if (!client->accept_input || (fifo = client->data.user.fifo) == NULL)
if (!client->accept_input)
return -ENXIO;
fifo = client->data.user.fifo;
if (!fifo)
return -ENXIO;

if (atomic_read(&fifo->overflow) > 0) {
Expand All @@ -435,9 +438,9 @@ static ssize_t snd_seq_read(struct file *file, char __user *buf, size_t count,
int nonblock;

nonblock = (file->f_flags & O_NONBLOCK) || result > 0;
if ((err = snd_seq_fifo_cell_out(fifo, &cell, nonblock)) < 0) {
err = snd_seq_fifo_cell_out(fifo, &cell, nonblock);
if (err < 0)
break;
}
if (snd_seq_ev_is_variable(&cell->event)) {
struct snd_seq_event tmpev;
tmpev = cell->event;
Expand Down Expand Up @@ -970,7 +973,8 @@ static int snd_seq_client_enqueue_event(struct snd_seq_client *client,
return err;

/* we got a cell. enqueue it. */
if ((err = snd_seq_enqueue_event(cell, atomic, hop)) < 0) {
err = snd_seq_enqueue_event(cell, atomic, hop);
if (err < 0) {
snd_seq_cell_free(cell);
return err;
}
Expand Down Expand Up @@ -1312,7 +1316,8 @@ static int snd_seq_ioctl_create_port(struct snd_seq_client *client, void *arg)
return -EINVAL;
}
if (client->type == KERNEL_CLIENT) {
if ((callback = info->kernel) != NULL) {
callback = info->kernel;
if (callback) {
if (callback->owner)
port->owner = callback->owner;
port->private_data = callback->private_data;
Expand Down Expand Up @@ -1466,13 +1471,17 @@ static int snd_seq_ioctl_subscribe_port(struct snd_seq_client *client,
struct snd_seq_client *receiver = NULL, *sender = NULL;
struct snd_seq_client_port *sport = NULL, *dport = NULL;

if ((receiver = snd_seq_client_use_ptr(subs->dest.client)) == NULL)
receiver = snd_seq_client_use_ptr(subs->dest.client);
if (!receiver)
goto __end;
if ((sender = snd_seq_client_use_ptr(subs->sender.client)) == NULL)
sender = snd_seq_client_use_ptr(subs->sender.client);
if (!sender)
goto __end;
if ((sport = snd_seq_port_use_ptr(sender, subs->sender.port)) == NULL)
sport = snd_seq_port_use_ptr(sender, subs->sender.port);
if (!sport)
goto __end;
if ((dport = snd_seq_port_use_ptr(receiver, subs->dest.port)) == NULL)
dport = snd_seq_port_use_ptr(receiver, subs->dest.port);
if (!dport)
goto __end;

result = check_subscription_permission(client, sport, dport, subs);
Expand Down Expand Up @@ -1508,13 +1517,17 @@ static int snd_seq_ioctl_unsubscribe_port(struct snd_seq_client *client,
struct snd_seq_client *receiver = NULL, *sender = NULL;
struct snd_seq_client_port *sport = NULL, *dport = NULL;

if ((receiver = snd_seq_client_use_ptr(subs->dest.client)) == NULL)
receiver = snd_seq_client_use_ptr(subs->dest.client);
if (!receiver)
goto __end;
if ((sender = snd_seq_client_use_ptr(subs->sender.client)) == NULL)
sender = snd_seq_client_use_ptr(subs->sender.client);
if (!sender)
goto __end;
if ((sport = snd_seq_port_use_ptr(sender, subs->sender.port)) == NULL)
sport = snd_seq_port_use_ptr(sender, subs->sender.port);
if (!sport)
goto __end;
if ((dport = snd_seq_port_use_ptr(receiver, subs->dest.port)) == NULL)
dport = snd_seq_port_use_ptr(receiver, subs->dest.port);
if (!dport)
goto __end;

result = check_subscription_permission(client, sport, dport, subs);
Expand Down Expand Up @@ -1926,9 +1939,11 @@ static int snd_seq_ioctl_get_subscription(struct snd_seq_client *client,
struct snd_seq_client_port *sport = NULL;

result = -EINVAL;
if ((sender = snd_seq_client_use_ptr(subs->sender.client)) == NULL)
sender = snd_seq_client_use_ptr(subs->sender.client);
if (!sender)
goto __end;
if ((sport = snd_seq_port_use_ptr(sender, subs->sender.port)) == NULL)
sport = snd_seq_port_use_ptr(sender, subs->sender.port);
if (!sport)
goto __end;
result = snd_seq_port_get_subscription(&sport->c_src, &subs->dest,
subs);
Expand All @@ -1955,9 +1970,11 @@ static int snd_seq_ioctl_query_subs(struct snd_seq_client *client, void *arg)
struct list_head *p;
int i;

if ((cptr = snd_seq_client_use_ptr(subs->root.client)) == NULL)
cptr = snd_seq_client_use_ptr(subs->root.client);
if (!cptr)
goto __end;
if ((port = snd_seq_port_use_ptr(cptr, subs->root.port)) == NULL)
port = snd_seq_port_use_ptr(cptr, subs->root.port);
if (!port)
goto __end;

switch (subs->type) {
Expand Down
3 changes: 2 additions & 1 deletion sound/core/seq/seq_dummy.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ create_port(int idx, int type)
struct snd_seq_port_callback pcb;
struct snd_seq_dummy_port *rec;

if ((rec = kzalloc(sizeof(*rec), GFP_KERNEL)) == NULL)
rec = kzalloc(sizeof(*rec), GFP_KERNEL);
if (!rec)
return NULL;

rec->client = my_client;
Expand Down
3 changes: 2 additions & 1 deletion sound/core/seq/seq_fifo.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ static struct snd_seq_event_cell *fifo_cell_out(struct snd_seq_fifo *f)
{
struct snd_seq_event_cell *cell;

if ((cell = f->head) != NULL) {
cell = f->head;
if (cell) {
f->head = cell->next;

/* reset tail if this was the last element */
Expand Down
Loading

0 comments on commit f9a6bb8

Please sign in to comment.