Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ALSA: seq: Fix assignment in if condition

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>

+131 -72
+16 -10
sound/core/seq/oss/seq_oss.c
··· 67 67 { 68 68 int rc; 69 69 70 - if ((rc = register_device()) < 0) 70 + rc = register_device(); 71 + if (rc < 0) 71 72 goto error; 72 - if ((rc = register_proc()) < 0) { 73 + rc = register_proc(); 74 + if (rc < 0) { 73 75 unregister_device(); 74 76 goto error; 75 77 } 76 - if ((rc = snd_seq_oss_create_client()) < 0) { 78 + rc = snd_seq_oss_create_client(); 79 + if (rc < 0) { 77 80 unregister_proc(); 78 81 unregister_device(); 79 82 goto error; ··· 136 133 { 137 134 struct seq_oss_devinfo *dp; 138 135 139 - if ((dp = file->private_data) == NULL) 136 + dp = file->private_data; 137 + if (!dp) 140 138 return 0; 141 139 142 140 mutex_lock(&register_mutex); ··· 230 226 int rc; 231 227 232 228 mutex_lock(&register_mutex); 233 - if ((rc = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER, 234 - NULL, 0, 235 - &seq_oss_f_ops, NULL)) < 0) { 229 + rc = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER, 230 + NULL, 0, 231 + &seq_oss_f_ops, NULL); 232 + if (rc < 0) { 236 233 pr_err("ALSA: seq_oss: can't register device seq\n"); 237 234 mutex_unlock(&register_mutex); 238 235 return rc; 239 236 } 240 - if ((rc = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_MUSIC, 241 - NULL, 0, 242 - &seq_oss_f_ops, NULL)) < 0) { 237 + rc = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_MUSIC, 238 + NULL, 0, 239 + &seq_oss_f_ops, NULL); 240 + if (rc < 0) { 243 241 pr_err("ALSA: seq_oss: can't register device music\n"); 244 242 snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER, NULL, 0); 245 243 mutex_unlock(&register_mutex);
+6 -3
sound/core/seq/oss/seq_oss_init.c
··· 95 95 port->kernel = &port_callback; 96 96 97 97 call_ctl(SNDRV_SEQ_IOCTL_CREATE_PORT, port); 98 - if ((system_port = port->addr.port) >= 0) { 98 + system_port = port->addr.port; 99 + if (system_port >= 0) { 99 100 struct snd_seq_port_subscribe subs; 100 101 101 102 memset(&subs, 0, sizeof(subs)); ··· 355 354 qinfo.owner = system_client; 356 355 qinfo.locked = 1; 357 356 strcpy(qinfo.name, "OSS Sequencer Emulation"); 358 - if ((rc = call_ctl(SNDRV_SEQ_IOCTL_CREATE_QUEUE, &qinfo)) < 0) 357 + rc = call_ctl(SNDRV_SEQ_IOCTL_CREATE_QUEUE, &qinfo); 358 + if (rc < 0) 359 359 return rc; 360 360 dp->queue = qinfo.queue; 361 361 return 0; ··· 487 485 snd_iprintf(buf, "\nNumber of applications: %d\n", num_clients); 488 486 for (i = 0; i < num_clients; i++) { 489 487 snd_iprintf(buf, "\nApplication %d: ", i); 490 - if ((dp = client_table[i]) == NULL) { 488 + dp = client_table[i]; 489 + if (!dp) { 491 490 snd_iprintf(buf, "*empty*\n"); 492 491 continue; 493 492 }
+22 -11
sound/core/seq/oss/seq_oss_midi.c
··· 152 152 /* 153 153 * look for the identical slot 154 154 */ 155 - if ((mdev = find_slot(pinfo->addr.client, pinfo->addr.port)) != NULL) { 155 + mdev = find_slot(pinfo->addr.client, pinfo->addr.port); 156 + if (mdev) { 156 157 /* already exists */ 157 158 snd_use_lock_free(&mdev->use_lock); 158 159 return 0; ··· 219 218 unsigned long flags; 220 219 int index; 221 220 222 - if ((mdev = find_slot(client, port)) != NULL) { 221 + mdev = find_slot(client, port); 222 + if (mdev) { 223 223 spin_lock_irqsave(&register_lock, flags); 224 224 midi_devs[mdev->seq_device] = NULL; 225 225 spin_unlock_irqrestore(&register_lock, flags); ··· 252 250 253 251 spin_lock_irqsave(&register_lock, flags); 254 252 for (i = 0; i < max_midi_devs; i++) { 255 - if ((mdev = midi_devs[i]) != NULL) { 253 + mdev = midi_devs[i]; 254 + if (mdev) { 256 255 snd_midi_event_free(mdev->coder); 257 256 kfree(mdev); 258 257 midi_devs[i] = NULL; ··· 321 318 struct seq_oss_midi *mdev; 322 319 struct snd_seq_port_subscribe subs; 323 320 324 - if ((mdev = get_mididev(dp, dev)) == NULL) 321 + mdev = get_mididev(dp, dev); 322 + if (!mdev) 325 323 return -ENODEV; 326 324 327 325 /* already used? */ ··· 388 384 struct seq_oss_midi *mdev; 389 385 struct snd_seq_port_subscribe subs; 390 386 391 - if ((mdev = get_mididev(dp, dev)) == NULL) 387 + mdev = get_mididev(dp, dev); 388 + if (!mdev) 392 389 return -ENODEV; 393 390 if (! mdev->opened || mdev->devinfo != dp) { 394 391 snd_use_lock_free(&mdev->use_lock); ··· 426 421 struct seq_oss_midi *mdev; 427 422 int mode; 428 423 429 - if ((mdev = get_mididev(dp, dev)) == NULL) 424 + mdev = get_mididev(dp, dev); 425 + if (!mdev) 430 426 return 0; 431 427 432 428 mode = 0; ··· 449 443 { 450 444 struct seq_oss_midi *mdev; 451 445 452 - if ((mdev = get_mididev(dp, dev)) == NULL) 446 + mdev = get_mididev(dp, dev); 447 + if (!mdev) 453 448 return; 454 449 if (! mdev->opened) { 455 450 snd_use_lock_free(&mdev->use_lock); ··· 498 491 { 499 492 struct seq_oss_midi *mdev; 500 493 501 - if ((mdev = get_mididev(dp, dev)) == NULL) 494 + mdev = get_mididev(dp, dev); 495 + if (!mdev) 502 496 return; 503 497 addr->client = mdev->client; 504 498 addr->port = mdev->port; ··· 519 511 520 512 if (dp->readq == NULL) 521 513 return 0; 522 - if ((mdev = find_slot(ev->source.client, ev->source.port)) == NULL) 514 + mdev = find_slot(ev->source.client, ev->source.port); 515 + if (!mdev) 523 516 return 0; 524 517 if (! (mdev->opened & PERM_READ)) { 525 518 snd_use_lock_free(&mdev->use_lock); ··· 632 623 { 633 624 struct seq_oss_midi *mdev; 634 625 635 - if ((mdev = get_mididev(dp, dev)) == NULL) 626 + mdev = get_mididev(dp, dev); 627 + if (!mdev) 636 628 return -ENODEV; 637 629 if (snd_midi_event_encode_byte(mdev->coder, c, ev)) { 638 630 snd_seq_oss_fill_addr(dp, ev, mdev->client, mdev->port); ··· 652 642 { 653 643 struct seq_oss_midi *mdev; 654 644 655 - if ((mdev = get_mididev(dp, dev)) == NULL) 645 + mdev = get_mididev(dp, dev); 646 + if (!mdev) 656 647 return -ENXIO; 657 648 inf->device = dev; 658 649 inf->dev_type = 0; /* FIXME: ?? */
+2 -1
sound/core/seq/oss/seq_oss_rw.c
··· 132 132 } 133 133 134 134 /* insert queue */ 135 - if ((err = insert_queue(dp, &rec, opt)) < 0) 135 + err = insert_queue(dp, &rec, opt); 136 + if (err < 0) 136 137 break; 137 138 138 139 result += ev_size;
+6 -3
sound/core/seq/oss/seq_oss_synth.c
··· 451 451 452 452 if (info->is_midi) 453 453 return 0; 454 - if ((rec = get_synthdev(dp, dev)) == NULL) 454 + rec = get_synthdev(dp, dev); 455 + if (!rec) 455 456 return -ENXIO; 456 457 457 458 if (rec->oper.load_patch == NULL) ··· 570 569 info = get_synthinfo_nospec(dp, dev); 571 570 if (!info || info->is_midi) 572 571 return -ENXIO; 573 - if ((rec = get_synthdev(dp, dev)) == NULL) 572 + rec = get_synthdev(dp, dev); 573 + if (!rec) 574 574 return -ENXIO; 575 575 if (rec->oper.ioctl == NULL) 576 576 rc = -ENXIO; ··· 621 619 inf->device = dev; 622 620 strscpy(inf->name, minf.name, sizeof(inf->name)); 623 621 } else { 624 - if ((rec = get_synthdev(dp, dev)) == NULL) 622 + rec = get_synthdev(dp, dev); 623 + if (!rec) 625 624 return -ENXIO; 626 625 inf->synth_type = rec->synth_type; 627 626 inf->synth_subtype = rec->synth_subtype;
+2 -1
sound/core/seq/oss/seq_oss_writeq.c
··· 27 27 struct seq_oss_writeq *q; 28 28 struct snd_seq_client_pool pool; 29 29 30 - if ((q = kzalloc(sizeof(*q), GFP_KERNEL)) == NULL) 30 + q = kzalloc(sizeof(*q), GFP_KERNEL); 31 + if (!q) 31 32 return NULL; 32 33 q->dp = dp; 33 34 q->maxlen = maxlen;
+34 -17
sound/core/seq/seq_clientmgr.c
··· 416 416 if (snd_BUG_ON(!client)) 417 417 return -ENXIO; 418 418 419 - if (!client->accept_input || (fifo = client->data.user.fifo) == NULL) 419 + if (!client->accept_input) 420 + return -ENXIO; 421 + fifo = client->data.user.fifo; 422 + if (!fifo) 420 423 return -ENXIO; 421 424 422 425 if (atomic_read(&fifo->overflow) > 0) { ··· 438 435 int nonblock; 439 436 440 437 nonblock = (file->f_flags & O_NONBLOCK) || result > 0; 441 - if ((err = snd_seq_fifo_cell_out(fifo, &cell, nonblock)) < 0) { 438 + err = snd_seq_fifo_cell_out(fifo, &cell, nonblock); 439 + if (err < 0) 442 440 break; 443 - } 444 441 if (snd_seq_ev_is_variable(&cell->event)) { 445 442 struct snd_seq_event tmpev; 446 443 tmpev = cell->event; ··· 973 970 return err; 974 971 975 972 /* we got a cell. enqueue it. */ 976 - if ((err = snd_seq_enqueue_event(cell, atomic, hop)) < 0) { 973 + err = snd_seq_enqueue_event(cell, atomic, hop); 974 + if (err < 0) { 977 975 snd_seq_cell_free(cell); 978 976 return err; 979 977 } ··· 1316 1312 return -EINVAL; 1317 1313 } 1318 1314 if (client->type == KERNEL_CLIENT) { 1319 - if ((callback = info->kernel) != NULL) { 1315 + callback = info->kernel; 1316 + if (callback) { 1320 1317 if (callback->owner) 1321 1318 port->owner = callback->owner; 1322 1319 port->private_data = callback->private_data; ··· 1471 1466 struct snd_seq_client *receiver = NULL, *sender = NULL; 1472 1467 struct snd_seq_client_port *sport = NULL, *dport = NULL; 1473 1468 1474 - if ((receiver = snd_seq_client_use_ptr(subs->dest.client)) == NULL) 1469 + receiver = snd_seq_client_use_ptr(subs->dest.client); 1470 + if (!receiver) 1475 1471 goto __end; 1476 - if ((sender = snd_seq_client_use_ptr(subs->sender.client)) == NULL) 1472 + sender = snd_seq_client_use_ptr(subs->sender.client); 1473 + if (!sender) 1477 1474 goto __end; 1478 - if ((sport = snd_seq_port_use_ptr(sender, subs->sender.port)) == NULL) 1475 + sport = snd_seq_port_use_ptr(sender, subs->sender.port); 1476 + if (!sport) 1479 1477 goto __end; 1480 - if ((dport = snd_seq_port_use_ptr(receiver, subs->dest.port)) == NULL) 1478 + dport = snd_seq_port_use_ptr(receiver, subs->dest.port); 1479 + if (!dport) 1481 1480 goto __end; 1482 1481 1483 1482 result = check_subscription_permission(client, sport, dport, subs); ··· 1517 1508 struct snd_seq_client *receiver = NULL, *sender = NULL; 1518 1509 struct snd_seq_client_port *sport = NULL, *dport = NULL; 1519 1510 1520 - if ((receiver = snd_seq_client_use_ptr(subs->dest.client)) == NULL) 1511 + receiver = snd_seq_client_use_ptr(subs->dest.client); 1512 + if (!receiver) 1521 1513 goto __end; 1522 - if ((sender = snd_seq_client_use_ptr(subs->sender.client)) == NULL) 1514 + sender = snd_seq_client_use_ptr(subs->sender.client); 1515 + if (!sender) 1523 1516 goto __end; 1524 - if ((sport = snd_seq_port_use_ptr(sender, subs->sender.port)) == NULL) 1517 + sport = snd_seq_port_use_ptr(sender, subs->sender.port); 1518 + if (!sport) 1525 1519 goto __end; 1526 - if ((dport = snd_seq_port_use_ptr(receiver, subs->dest.port)) == NULL) 1520 + dport = snd_seq_port_use_ptr(receiver, subs->dest.port); 1521 + if (!dport) 1527 1522 goto __end; 1528 1523 1529 1524 result = check_subscription_permission(client, sport, dport, subs); ··· 1939 1926 struct snd_seq_client_port *sport = NULL; 1940 1927 1941 1928 result = -EINVAL; 1942 - if ((sender = snd_seq_client_use_ptr(subs->sender.client)) == NULL) 1929 + sender = snd_seq_client_use_ptr(subs->sender.client); 1930 + if (!sender) 1943 1931 goto __end; 1944 - if ((sport = snd_seq_port_use_ptr(sender, subs->sender.port)) == NULL) 1932 + sport = snd_seq_port_use_ptr(sender, subs->sender.port); 1933 + if (!sport) 1945 1934 goto __end; 1946 1935 result = snd_seq_port_get_subscription(&sport->c_src, &subs->dest, 1947 1936 subs); ··· 1970 1955 struct list_head *p; 1971 1956 int i; 1972 1957 1973 - if ((cptr = snd_seq_client_use_ptr(subs->root.client)) == NULL) 1958 + cptr = snd_seq_client_use_ptr(subs->root.client); 1959 + if (!cptr) 1974 1960 goto __end; 1975 - if ((port = snd_seq_port_use_ptr(cptr, subs->root.port)) == NULL) 1961 + port = snd_seq_port_use_ptr(cptr, subs->root.port); 1962 + if (!port) 1976 1963 goto __end; 1977 1964 1978 1965 switch (subs->type) {
+2 -1
sound/core/seq/seq_dummy.c
··· 109 109 struct snd_seq_port_callback pcb; 110 110 struct snd_seq_dummy_port *rec; 111 111 112 - if ((rec = kzalloc(sizeof(*rec), GFP_KERNEL)) == NULL) 112 + rec = kzalloc(sizeof(*rec), GFP_KERNEL); 113 + if (!rec) 113 114 return NULL; 114 115 115 116 rec->client = my_client;
+2 -1
sound/core/seq/seq_fifo.c
··· 143 143 { 144 144 struct snd_seq_event_cell *cell; 145 145 146 - if ((cell = f->head) != NULL) { 146 + cell = f->head; 147 + if (cell) { 147 148 f->head = cell->next; 148 149 149 150 /* reset tail if this was the last element */
+4 -2
sound/core/seq/seq_memory.c
··· 69 69 int len, err; 70 70 struct snd_seq_event_cell *cell; 71 71 72 - if ((len = get_var_len(event)) <= 0) 72 + len = get_var_len(event); 73 + if (len <= 0) 73 74 return len; 74 75 75 76 if (event->data.ext.len & SNDRV_SEQ_EXT_USRPTR) { ··· 134 133 int len, newlen; 135 134 int err; 136 135 137 - if ((len = get_var_len(event)) < 0) 136 + len = get_var_len(event); 137 + if (len < 0) 138 138 return len; 139 139 newlen = len; 140 140 if (size_aligned > 0)
+16 -11
sound/core/seq/seq_midi.c
··· 101 101 if (snd_BUG_ON(!substream || !buf)) 102 102 return -EINVAL; 103 103 runtime = substream->runtime; 104 - if ((tmp = runtime->avail) < count) { 104 + tmp = runtime->avail; 105 + if (tmp < count) { 105 106 if (printk_ratelimit()) 106 107 pr_err("ALSA: seq_midi: MIDI output buffer overrun\n"); 107 108 return -ENOMEM; ··· 168 167 struct snd_rawmidi_params params; 169 168 170 169 /* open midi port */ 171 - if ((err = snd_rawmidi_kernel_open(msynth->card, msynth->device, 172 - msynth->subdevice, 173 - SNDRV_RAWMIDI_LFLG_INPUT, 174 - &msynth->input_rfile)) < 0) { 170 + err = snd_rawmidi_kernel_open(msynth->card, msynth->device, 171 + msynth->subdevice, 172 + SNDRV_RAWMIDI_LFLG_INPUT, 173 + &msynth->input_rfile); 174 + if (err < 0) { 175 175 pr_debug("ALSA: seq_midi: midi input open failed!!!\n"); 176 176 return err; 177 177 } ··· 180 178 memset(&params, 0, sizeof(params)); 181 179 params.avail_min = 1; 182 180 params.buffer_size = input_buffer_size; 183 - if ((err = snd_rawmidi_input_params(msynth->input_rfile.input, &params)) < 0) { 181 + err = snd_rawmidi_input_params(msynth->input_rfile.input, &params); 182 + if (err < 0) { 184 183 snd_rawmidi_kernel_release(&msynth->input_rfile); 185 184 return err; 186 185 } ··· 212 209 struct snd_rawmidi_params params; 213 210 214 211 /* open midi port */ 215 - if ((err = snd_rawmidi_kernel_open(msynth->card, msynth->device, 216 - msynth->subdevice, 217 - SNDRV_RAWMIDI_LFLG_OUTPUT, 218 - &msynth->output_rfile)) < 0) { 212 + err = snd_rawmidi_kernel_open(msynth->card, msynth->device, 213 + msynth->subdevice, 214 + SNDRV_RAWMIDI_LFLG_OUTPUT, 215 + &msynth->output_rfile); 216 + if (err < 0) { 219 217 pr_debug("ALSA: seq_midi: midi output open failed!!!\n"); 220 218 return err; 221 219 } ··· 224 220 params.avail_min = 1; 225 221 params.buffer_size = output_buffer_size; 226 222 params.no_active_sensing = 1; 227 - if ((err = snd_rawmidi_output_params(msynth->output_rfile.output, &params)) < 0) { 223 + err = snd_rawmidi_output_params(msynth->output_rfile.output, &params); 224 + if (err < 0) { 228 225 snd_rawmidi_kernel_release(&msynth->output_rfile); 229 226 return err; 230 227 }
+14 -7
sound/core/seq/seq_queue.c
··· 222 222 struct snd_seq_queue *q; 223 223 224 224 for (i = 0; i < SNDRV_SEQ_MAX_QUEUES; i++) { 225 - if ((q = queueptr(i)) != NULL) { 225 + q = queueptr(i); 226 + if (q) { 226 227 if (strncmp(q->name, name, sizeof(q->name)) == 0) 227 228 return q; 228 229 queuefree(q); ··· 433 432 if (queue == NULL) 434 433 return -EINVAL; 435 434 tmr = queue->timer; 436 - if ((result = snd_seq_timer_open(queue)) < 0) { 435 + result = snd_seq_timer_open(queue); 436 + if (result < 0) { 437 437 snd_seq_timer_defaults(tmr); 438 438 result = snd_seq_timer_open(queue); 439 439 } ··· 550 548 551 549 /* delete own queues from queue list */ 552 550 for (i = 0; i < SNDRV_SEQ_MAX_QUEUES; i++) { 553 - if ((q = queue_list_remove(i, client)) != NULL) 551 + q = queue_list_remove(i, client); 552 + if (q) 554 553 queue_delete(q); 555 554 } 556 555 ··· 559 556 * they are not owned by this client 560 557 */ 561 558 for (i = 0; i < SNDRV_SEQ_MAX_QUEUES; i++) { 562 - if ((q = queueptr(i)) == NULL) 559 + q = queueptr(i); 560 + if (!q) 563 561 continue; 564 562 if (test_bit(client, q->clients_bitmap)) { 565 563 snd_seq_prioq_leave(q->tickq, client, 0); ··· 582 578 struct snd_seq_queue *q; 583 579 584 580 for (i = 0; i < SNDRV_SEQ_MAX_QUEUES; i++) { 585 - if ((q = queueptr(i)) == NULL) 581 + q = queueptr(i); 582 + if (!q) 586 583 continue; 587 584 snd_seq_prioq_leave(q->tickq, client, 0); 588 585 snd_seq_prioq_leave(q->timeq, client, 0); ··· 598 593 struct snd_seq_queue *q; 599 594 600 595 for (i = 0; i < SNDRV_SEQ_MAX_QUEUES; i++) { 601 - if ((q = queueptr(i)) == NULL) 596 + q = queueptr(i); 597 + if (!q) 602 598 continue; 603 599 if (test_bit(client, q->clients_bitmap) && 604 600 (! (info->remove_mode & SNDRV_SEQ_REMOVE_DEST) || ··· 730 724 int owner; 731 725 732 726 for (i = 0; i < SNDRV_SEQ_MAX_QUEUES; i++) { 733 - if ((q = queueptr(i)) == NULL) 727 + q = queueptr(i); 728 + if (!q) 734 729 continue; 735 730 736 731 tmr = q->timer;
+5 -4
sound/core/seq/seq_virmidi.c
··· 482 482 int err; 483 483 484 484 *rrmidi = NULL; 485 - if ((err = snd_rawmidi_new(card, "VirMidi", device, 486 - 16, /* may be configurable */ 487 - 16, /* may be configurable */ 488 - &rmidi)) < 0) 485 + err = snd_rawmidi_new(card, "VirMidi", device, 486 + 16, /* may be configurable */ 487 + 16, /* may be configurable */ 488 + &rmidi); 489 + if (err < 0) 489 490 return err; 490 491 strcpy(rmidi->name, rmidi->id); 491 492 rdev = kzalloc(sizeof(*rdev), GFP_KERNEL);