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

ALSA: via82xx: Fix assignment in if condition

PCI VIA82xx driver code contains a few assignments in if condition,
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-34-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>

+85 -45
+51 -27
sound/pci/via82xx.c
··· 515 515 516 516 while (timeout-- > 0) { 517 517 udelay(1); 518 - if (!((val = snd_via82xx_codec_xread(chip)) & VIA_REG_AC97_BUSY)) 518 + val = snd_via82xx_codec_xread(chip); 519 + if (!(val & VIA_REG_AC97_BUSY)) 519 520 return val & 0xffff; 520 521 } 521 522 dev_err(chip->card->dev, "codec_ready: codec %i is not ready [0x%x]\n", ··· 1024 1023 int rate_changed; 1025 1024 u32 rbits; 1026 1025 1027 - if ((rate_changed = via_lock_rate(&chip->rates[0], ac97_rate)) < 0) 1026 + rate_changed = via_lock_rate(&chip->rates[0], ac97_rate); 1027 + if (rate_changed < 0) 1028 1028 return rate_changed; 1029 1029 if (rate_changed) 1030 1030 snd_ac97_set_rate(chip->ac97, AC97_PCM_FRONT_DAC_RATE, ··· 1199 1197 1200 1198 /* we may remove following constaint when we modify table entries 1201 1199 in interrupt */ 1202 - if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0) 1200 + err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS); 1201 + if (err < 0) 1203 1202 return err; 1204 1203 1205 1204 if (use_src) { ··· 1225 1222 struct viadev *viadev = &chip->devs[chip->playback_devno + substream->number]; 1226 1223 int err; 1227 1224 1228 - if ((err = snd_via82xx_pcm_open(chip, viadev, substream)) < 0) 1225 + err = snd_via82xx_pcm_open(chip, viadev, substream); 1226 + if (err < 0) 1229 1227 return err; 1230 1228 return 0; 1231 1229 } ··· 1242 1238 int err; 1243 1239 1244 1240 viadev = &chip->devs[chip->playback_devno + substream->number]; 1245 - if ((err = snd_via82xx_pcm_open(chip, viadev, substream)) < 0) 1241 + err = snd_via82xx_pcm_open(chip, viadev, substream); 1242 + if (err < 0) 1246 1243 return err; 1247 1244 stream = viadev->reg_offset / 0x10; 1248 1245 if (chip->dxs_controls[stream]) { ··· 1280 1275 .mask = 0, 1281 1276 }; 1282 1277 1283 - if ((err = snd_via82xx_pcm_open(chip, viadev, substream)) < 0) 1278 + err = snd_via82xx_pcm_open(chip, viadev, substream); 1279 + if (err < 0) 1284 1280 return err; 1285 1281 substream->runtime->hw.channels_max = 6; 1286 1282 if (chip->revision == VIA_REV_8233A) ··· 1881 1875 .wait = snd_via82xx_codec_wait, 1882 1876 }; 1883 1877 1884 - if ((err = snd_ac97_bus(chip->card, 0, &ops, chip, &chip->ac97_bus)) < 0) 1878 + err = snd_ac97_bus(chip->card, 0, &ops, chip, &chip->ac97_bus); 1879 + if (err < 0) 1885 1880 return err; 1886 1881 chip->ac97_bus->private_free = snd_via82xx_mixer_free_ac97_bus; 1887 1882 chip->ac97_bus->clock = chip->ac97_clock; ··· 1892 1885 ac97.private_free = snd_via82xx_mixer_free_ac97; 1893 1886 ac97.pci = chip->pci; 1894 1887 ac97.scaps = AC97_SCAP_SKIP_MODEM | AC97_SCAP_POWER_SAVE; 1895 - if ((err = snd_ac97_mixer(chip->ac97_bus, &ac97, &chip->ac97)) < 0) 1888 + err = snd_ac97_mixer(chip->ac97_bus, &ac97, &chip->ac97); 1889 + if (err < 0) 1896 1890 return err; 1897 1891 1898 1892 snd_ac97_tune_hardware(chip->ac97, ac97_quirks, quirk_override); ··· 2062 2054 break; 2063 2055 } 2064 2056 } 2065 - if (mpu_port >= 0x200 && 2066 - (chip->mpu_res = request_region(mpu_port, 2, "VIA82xx MPU401")) 2067 - != NULL) { 2057 + if (mpu_port >= 0x200) 2058 + chip->mpu_res = request_region(mpu_port, 2, "VIA82xx MPU401"); 2059 + if (chip->mpu_res) { 2068 2060 if (rev_h) 2069 2061 legacy |= VIA_FUNC_MIDI_PNP; /* enable PCI I/O 2 */ 2070 2062 legacy |= VIA_FUNC_ENABLE_MIDI; ··· 2181 2173 schedule_timeout_uninterruptible(1); 2182 2174 } while (time_before(jiffies, end_time)); 2183 2175 2184 - if ((val = snd_via82xx_codec_xread(chip)) & VIA_REG_AC97_BUSY) 2176 + val = snd_via82xx_codec_xread(chip); 2177 + if (val & VIA_REG_AC97_BUSY) 2185 2178 dev_err(chip->card->dev, 2186 2179 "AC'97 codec is not ready [0x%x]\n", val); 2187 2180 ··· 2195 2186 VIA_REG_AC97_SECONDARY_VALID | 2196 2187 (VIA_REG_AC97_CODEC_ID_SECONDARY << VIA_REG_AC97_CODEC_ID_SHIFT)); 2197 2188 do { 2198 - if ((val = snd_via82xx_codec_xread(chip)) & VIA_REG_AC97_SECONDARY_VALID) { 2189 + val = snd_via82xx_codec_xread(chip); 2190 + if (val & VIA_REG_AC97_SECONDARY_VALID) { 2199 2191 chip->ac97_secondary = 1; 2200 2192 goto __ac97_ok2; 2201 2193 } ··· 2347 2337 .dev_free = snd_via82xx_dev_free, 2348 2338 }; 2349 2339 2350 - if ((err = pci_enable_device(pci)) < 0) 2340 + err = pci_enable_device(pci); 2341 + if (err < 0) 2351 2342 return err; 2352 2343 2353 - if ((chip = kzalloc(sizeof(*chip), GFP_KERNEL)) == NULL) { 2344 + chip = kzalloc(sizeof(*chip), GFP_KERNEL); 2345 + if (!chip) { 2354 2346 pci_disable_device(pci); 2355 2347 return -ENOMEM; 2356 2348 } ··· 2372 2360 pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, 2373 2361 chip->old_legacy & ~(VIA_FUNC_ENABLE_SB|VIA_FUNC_ENABLE_FM)); 2374 2362 2375 - if ((err = pci_request_regions(pci, card->driver)) < 0) { 2363 + err = pci_request_regions(pci, card->driver); 2364 + if (err < 0) { 2376 2365 kfree(chip); 2377 2366 pci_disable_device(pci); 2378 2367 return err; ··· 2393 2380 if (ac97_clock >= 8000 && ac97_clock <= 48000) 2394 2381 chip->ac97_clock = ac97_clock; 2395 2382 2396 - if ((err = snd_via82xx_chip_init(chip)) < 0) { 2383 + err = snd_via82xx_chip_init(chip); 2384 + if (err < 0) { 2397 2385 snd_via82xx_free(chip); 2398 2386 return err; 2399 2387 } 2400 2388 2401 - if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) { 2389 + err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); 2390 + if (err < 0) { 2402 2391 snd_via82xx_free(chip); 2403 2392 return err; 2404 2393 } ··· 2556 2541 goto __error; 2557 2542 } 2558 2543 2559 - if ((err = snd_via82xx_create(card, pci, chip_type, pci->revision, 2560 - ac97_clock, &chip)) < 0) 2544 + err = snd_via82xx_create(card, pci, chip_type, pci->revision, 2545 + ac97_clock, &chip); 2546 + if (err < 0) 2561 2547 goto __error; 2562 2548 card->private_data = chip; 2563 - if ((err = snd_via82xx_mixer_new(chip, ac97_quirk)) < 0) 2549 + err = snd_via82xx_mixer_new(chip, ac97_quirk); 2550 + if (err < 0) 2564 2551 goto __error; 2565 2552 2566 2553 if (chip_type == TYPE_VIA686) { 2567 - if ((err = snd_via686_pcm_new(chip)) < 0 || 2568 - (err = snd_via686_init_misc(chip)) < 0) 2554 + err = snd_via686_pcm_new(chip); 2555 + if (err < 0) 2556 + goto __error; 2557 + err = snd_via686_init_misc(chip); 2558 + if (err < 0) 2569 2559 goto __error; 2570 2560 } else { 2571 2561 if (chip_type == TYPE_VIA8233A) { 2572 - if ((err = snd_via8233a_pcm_new(chip)) < 0) 2562 + err = snd_via8233a_pcm_new(chip); 2563 + if (err < 0) 2573 2564 goto __error; 2574 2565 // chip->dxs_fixed = 1; /* FIXME: use 48k for DXS #3? */ 2575 2566 } else { 2576 - if ((err = snd_via8233_pcm_new(chip)) < 0) 2567 + err = snd_via8233_pcm_new(chip); 2568 + if (err < 0) 2577 2569 goto __error; 2578 2570 if (dxs_support == VIA_DXS_48K) 2579 2571 chip->dxs_fixed = 1; ··· 2591 2569 chip->dxs_src = 1; 2592 2570 } 2593 2571 } 2594 - if ((err = snd_via8233_init_misc(chip)) < 0) 2572 + err = snd_via8233_init_misc(chip); 2573 + if (err < 0) 2595 2574 goto __error; 2596 2575 } 2597 2576 ··· 2606 2583 2607 2584 snd_via82xx_proc_init(chip); 2608 2585 2609 - if ((err = snd_card_register(card)) < 0) { 2586 + err = snd_card_register(card); 2587 + if (err < 0) { 2610 2588 snd_card_free(card); 2611 2589 return err; 2612 2590 }
+34 -18
sound/pci/via82xx_modem.c
··· 369 369 370 370 while (timeout-- > 0) { 371 371 udelay(1); 372 - if (!((val = snd_via82xx_codec_xread(chip)) & VIA_REG_AC97_BUSY)) 372 + val = snd_via82xx_codec_xread(chip); 373 + if (!(val & VIA_REG_AC97_BUSY)) 373 374 return val & 0xffff; 374 375 } 375 376 dev_err(chip->card->dev, "codec_ready: codec %i is not ready [0x%x]\n", ··· 739 738 740 739 runtime->hw = snd_via82xx_hw; 741 740 742 - if ((err = snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, 743 - &hw_constraints_rates)) < 0) 741 + err = snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, 742 + &hw_constraints_rates); 743 + if (err < 0) 744 744 return err; 745 745 746 746 /* we may remove following constaint when we modify table entries 747 747 in interrupt */ 748 - if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0) 748 + err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS); 749 + if (err < 0) 749 750 return err; 750 751 751 752 runtime->private_data = viadev; ··· 881 878 .wait = snd_via82xx_codec_wait, 882 879 }; 883 880 884 - if ((err = snd_ac97_bus(chip->card, 0, &ops, chip, &chip->ac97_bus)) < 0) 881 + err = snd_ac97_bus(chip->card, 0, &ops, chip, &chip->ac97_bus); 882 + if (err < 0) 885 883 return err; 886 884 chip->ac97_bus->private_free = snd_via82xx_mixer_free_ac97_bus; 887 885 chip->ac97_bus->clock = chip->ac97_clock; ··· 894 890 ac97.scaps = AC97_SCAP_SKIP_AUDIO | AC97_SCAP_POWER_SAVE; 895 891 ac97.num = chip->ac97_secondary; 896 892 897 - if ((err = snd_ac97_mixer(chip->ac97_bus, &ac97, &chip->ac97)) < 0) 893 + err = snd_ac97_mixer(chip->ac97_bus, &ac97, &chip->ac97); 894 + if (err < 0) 898 895 return err; 899 896 900 897 return 0; ··· 976 971 schedule_timeout_uninterruptible(1); 977 972 } while (time_before(jiffies, end_time)); 978 973 979 - if ((val = snd_via82xx_codec_xread(chip)) & VIA_REG_AC97_BUSY) 974 + val = snd_via82xx_codec_xread(chip); 975 + if (val & VIA_REG_AC97_BUSY) 980 976 dev_err(chip->card->dev, 981 977 "AC'97 codec is not ready [0x%x]\n", val); 982 978 ··· 989 983 VIA_REG_AC97_SECONDARY_VALID | 990 984 (VIA_REG_AC97_CODEC_ID_SECONDARY << VIA_REG_AC97_CODEC_ID_SHIFT)); 991 985 do { 992 - if ((val = snd_via82xx_codec_xread(chip)) & VIA_REG_AC97_SECONDARY_VALID) { 986 + val = snd_via82xx_codec_xread(chip); 987 + if (val & VIA_REG_AC97_SECONDARY_VALID) { 993 988 chip->ac97_secondary = 1; 994 989 goto __ac97_ok2; 995 990 } ··· 1086 1079 .dev_free = snd_via82xx_dev_free, 1087 1080 }; 1088 1081 1089 - if ((err = pci_enable_device(pci)) < 0) 1082 + err = pci_enable_device(pci); 1083 + if (err < 0) 1090 1084 return err; 1091 1085 1092 - if ((chip = kzalloc(sizeof(*chip), GFP_KERNEL)) == NULL) { 1086 + chip = kzalloc(sizeof(*chip), GFP_KERNEL); 1087 + if (!chip) { 1093 1088 pci_disable_device(pci); 1094 1089 return -ENOMEM; 1095 1090 } ··· 1101 1092 chip->pci = pci; 1102 1093 chip->irq = -1; 1103 1094 1104 - if ((err = pci_request_regions(pci, card->driver)) < 0) { 1095 + err = pci_request_regions(pci, card->driver); 1096 + if (err < 0) { 1105 1097 kfree(chip); 1106 1098 pci_disable_device(pci); 1107 1099 return err; ··· 1119 1109 if (ac97_clock >= 8000 && ac97_clock <= 48000) 1120 1110 chip->ac97_clock = ac97_clock; 1121 1111 1122 - if ((err = snd_via82xx_chip_init(chip)) < 0) { 1112 + err = snd_via82xx_chip_init(chip); 1113 + if (err < 0) { 1123 1114 snd_via82xx_free(chip); 1124 1115 return err; 1125 1116 } 1126 1117 1127 - if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) { 1118 + err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); 1119 + if (err < 0) { 1128 1120 snd_via82xx_free(chip); 1129 1121 return err; 1130 1122 } ··· 1166 1154 goto __error; 1167 1155 } 1168 1156 1169 - if ((err = snd_via82xx_create(card, pci, chip_type, pci->revision, 1170 - ac97_clock, &chip)) < 0) 1157 + err = snd_via82xx_create(card, pci, chip_type, pci->revision, 1158 + ac97_clock, &chip); 1159 + if (err < 0) 1171 1160 goto __error; 1172 1161 card->private_data = chip; 1173 - if ((err = snd_via82xx_mixer_new(chip)) < 0) 1162 + err = snd_via82xx_mixer_new(chip); 1163 + if (err < 0) 1174 1164 goto __error; 1175 1165 1176 - if ((err = snd_via686_pcm_new(chip)) < 0 ) 1166 + err = snd_via686_pcm_new(chip); 1167 + if (err < 0) 1177 1168 goto __error; 1178 1169 1179 1170 /* disable interrupts */ ··· 1188 1173 1189 1174 snd_via82xx_proc_init(chip); 1190 1175 1191 - if ((err = snd_card_register(card)) < 0) { 1176 + err = snd_card_register(card); 1177 + if (err < 0) { 1192 1178 snd_card_free(card); 1193 1179 return err; 1194 1180 }