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

Merge branch 'for-next' into for-linus

Prep for 6.9 merge.

Signed-off-by: Takashi Iwai <tiwai@suse.de>

+3380 -3032
+4 -2
Documentation/sound/kernel-api/writing-an-alsa-driver.rst
··· 3864 3864 3865 3865 And next, set suspend/resume callbacks to the pci_driver:: 3866 3866 3867 - static SIMPLE_DEV_PM_OPS(snd_my_pm_ops, mychip_suspend, mychip_resume); 3867 + static DEFINE_SIMPLE_DEV_PM_OPS(snd_my_pm_ops, mychip_suspend, mychip_resume); 3868 3868 3869 3869 static struct pci_driver driver = { 3870 3870 .name = KBUILD_MODNAME, 3871 3871 .id_table = snd_my_ids, 3872 3872 .probe = snd_my_probe, 3873 3873 .remove = snd_my_remove, 3874 - .driver.pm = &snd_my_pm_ops, 3874 + .driver = { 3875 + .pm = &snd_my_pm_ops, 3876 + }, 3875 3877 }; 3876 3878 3877 3879 Module Parameters
+7
MAINTAINERS
··· 5014 5014 F: include/sound/cs* 5015 5015 F: sound/pci/hda/cirrus* 5016 5016 F: sound/pci/hda/cs* 5017 + F: sound/pci/hda/hda_component* 5017 5018 F: sound/pci/hda/hda_cs_dsp_ctl.* 5018 5019 F: sound/soc/codecs/cs* 5019 5020 ··· 20485 20484 F: include/uapi/sound/compress_* 20486 20485 F: sound/core/compress_offload.c 20487 20486 F: sound/soc/soc-compress.c 20487 + 20488 + SOUND - CORE KUNIT TEST 20489 + M: Ivan Orlov <ivan.orlov0322@gmail.com> 20490 + L: linux-sound@vger.kernel.org 20491 + S: Supported 20492 + F: sound/core/sound_kunit.c 20488 20493 20489 20494 SOUND - DMAENGINE HELPERS 20490 20495 M: Lars-Peter Clausen <lars@metafoo.de>
+2
drivers/acpi/scan.c
··· 1725 1725 {"BSG1160", }, 1726 1726 {"BSG2150", }, 1727 1727 {"CSC3551", }, 1728 + {"CSC3554", }, 1728 1729 {"CSC3556", }, 1730 + {"CSC3557", }, 1729 1731 {"INT33FE", }, 1730 1732 {"INT3515", }, 1731 1733 /* Non-conforming _HID for Cirrus Logic already released */
+28
drivers/platform/x86/serial-multi-instantiate.c
··· 329 329 .bus_type = SMI_AUTO_DETECT, 330 330 }; 331 331 332 + static const struct smi_node cs35l54_hda = { 333 + .instances = { 334 + { "cs35l54-hda", IRQ_RESOURCE_AUTO, 0 }, 335 + { "cs35l54-hda", IRQ_RESOURCE_AUTO, 0 }, 336 + { "cs35l54-hda", IRQ_RESOURCE_AUTO, 0 }, 337 + { "cs35l54-hda", IRQ_RESOURCE_AUTO, 0 }, 338 + /* a 5th entry is an alias address, not a real device */ 339 + { "cs35l54-hda_dummy_dev" }, 340 + {} 341 + }, 342 + .bus_type = SMI_AUTO_DETECT, 343 + }; 344 + 332 345 static const struct smi_node cs35l56_hda = { 333 346 .instances = { 334 347 { "cs35l56-hda", IRQ_RESOURCE_AUTO, 0 }, ··· 355 342 .bus_type = SMI_AUTO_DETECT, 356 343 }; 357 344 345 + static const struct smi_node cs35l57_hda = { 346 + .instances = { 347 + { "cs35l57-hda", IRQ_RESOURCE_AUTO, 0 }, 348 + { "cs35l57-hda", IRQ_RESOURCE_AUTO, 0 }, 349 + { "cs35l57-hda", IRQ_RESOURCE_AUTO, 0 }, 350 + { "cs35l57-hda", IRQ_RESOURCE_AUTO, 0 }, 351 + /* a 5th entry is an alias address, not a real device */ 352 + { "cs35l57-hda_dummy_dev" }, 353 + {} 354 + }, 355 + .bus_type = SMI_AUTO_DETECT, 356 + }; 357 + 358 358 /* 359 359 * Note new device-ids must also be added to ignore_serial_bus_ids in 360 360 * drivers/acpi/scan.c: acpi_device_enumeration_by_parent(). ··· 376 350 { "BSG1160", (unsigned long)&bsg1160_data }, 377 351 { "BSG2150", (unsigned long)&bsg2150_data }, 378 352 { "CSC3551", (unsigned long)&cs35l41_hda }, 353 + { "CSC3554", (unsigned long)&cs35l54_hda }, 379 354 { "CSC3556", (unsigned long)&cs35l56_hda }, 355 + { "CSC3557", (unsigned long)&cs35l57_hda }, 380 356 { "INT3515", (unsigned long)&int3515_data }, 381 357 /* Non-conforming _HID for Cirrus Logic already released */ 382 358 { "CLSA0100", (unsigned long)&cs35l41_hda },
+3
include/sound/ak4531_codec.h
··· 65 65 #ifdef CONFIG_PM 66 66 void snd_ak4531_suspend(struct snd_ak4531 *ak4531); 67 67 void snd_ak4531_resume(struct snd_ak4531 *ak4531); 68 + #else 69 + static inline void snd_ak4531_suspend(struct snd_ak4531 *ak4531) {} 70 + static inline void snd_ak4531_resume(struct snd_ak4531 *ak4531) {} 68 71 #endif 69 72 70 73 #endif /* __SOUND_AK4531_CODEC_H */
+1
include/sound/cs35l56.h
··· 257 257 struct regmap *regmap; 258 258 int irq; 259 259 struct mutex irq_lock; 260 + u8 type; 260 261 u8 rev; 261 262 bool init_done; 262 263 bool fw_patched;
+1 -1
include/sound/emux_synth.h
··· 103 103 int ports[SNDRV_EMUX_MAX_PORTS]; /* The ports for this device */ 104 104 struct snd_emux_port *portptrs[SNDRV_EMUX_MAX_PORTS]; 105 105 int used; /* use counter */ 106 - char *name; /* name of the device (internal) */ 106 + const char *name; /* name of the device (internal) */ 107 107 struct snd_rawmidi **vmidi; 108 108 struct timer_list tlist; /* for pending note-offs */ 109 109 int timer_active;
+12
include/sound/pcm.h
··· 659 659 flags = _snd_pcm_stream_lock_irqsave_nested(substream); \ 660 660 } while (0) 661 661 662 + /* definitions for guard(); use like guard(pcm_stream_lock) */ 663 + DEFINE_LOCK_GUARD_1(pcm_stream_lock, struct snd_pcm_substream, 664 + snd_pcm_stream_lock(_T->lock), 665 + snd_pcm_stream_unlock(_T->lock)) 666 + DEFINE_LOCK_GUARD_1(pcm_stream_lock_irq, struct snd_pcm_substream, 667 + snd_pcm_stream_lock_irq(_T->lock), 668 + snd_pcm_stream_unlock_irq(_T->lock)) 669 + DEFINE_LOCK_GUARD_1(pcm_stream_lock_irqsave, struct snd_pcm_substream, 670 + snd_pcm_stream_lock_irqsave(_T->lock, _T->flags), 671 + snd_pcm_stream_unlock_irqrestore(_T->lock, _T->flags), 672 + unsigned long flags) 673 + 662 674 /** 663 675 * snd_pcm_group_for_each_entry - iterate over the linked substreams 664 676 * @s: the iterator
+3
include/sound/sb.h
··· 290 290 #ifdef CONFIG_PM 291 291 void snd_sbmixer_suspend(struct snd_sb *chip); 292 292 void snd_sbmixer_resume(struct snd_sb *chip); 293 + #else 294 + static inline void snd_sbmixer_suspend(struct snd_sb *chip) {} 295 + static inline void snd_sbmixer_resume(struct snd_sb *chip) {} 293 296 #endif 294 297 295 298 /* sb8_init.c */
+154
include/uapi/linux/virtio_snd.h
··· 8 8 #include <linux/virtio_types.h> 9 9 10 10 /******************************************************************************* 11 + * FEATURE BITS 12 + */ 13 + enum { 14 + /* device supports control elements */ 15 + VIRTIO_SND_F_CTLS = 0 16 + }; 17 + 18 + /******************************************************************************* 11 19 * CONFIGURATION SPACE 12 20 */ 13 21 struct virtio_snd_config { ··· 25 17 __le32 streams; 26 18 /* # of available channel maps */ 27 19 __le32 chmaps; 20 + /* # of available control elements */ 21 + __le32 controls; 28 22 }; 29 23 30 24 enum { ··· 65 55 /* channel map control request types */ 66 56 VIRTIO_SND_R_CHMAP_INFO = 0x0200, 67 57 58 + /* control element request types */ 59 + VIRTIO_SND_R_CTL_INFO = 0x0300, 60 + VIRTIO_SND_R_CTL_ENUM_ITEMS, 61 + VIRTIO_SND_R_CTL_READ, 62 + VIRTIO_SND_R_CTL_WRITE, 63 + VIRTIO_SND_R_CTL_TLV_READ, 64 + VIRTIO_SND_R_CTL_TLV_WRITE, 65 + VIRTIO_SND_R_CTL_TLV_COMMAND, 66 + 68 67 /* jack event types */ 69 68 VIRTIO_SND_EVT_JACK_CONNECTED = 0x1000, 70 69 VIRTIO_SND_EVT_JACK_DISCONNECTED, ··· 81 62 /* PCM event types */ 82 63 VIRTIO_SND_EVT_PCM_PERIOD_ELAPSED = 0x1100, 83 64 VIRTIO_SND_EVT_PCM_XRUN, 65 + 66 + /* control element event types */ 67 + VIRTIO_SND_EVT_CTL_NOTIFY = 0x1200, 84 68 85 69 /* common status codes */ 86 70 VIRTIO_SND_S_OK = 0x8000, ··· 351 329 __u8 channels; 352 330 /* channel position values (VIRTIO_SND_CHMAP_XXX) */ 353 331 __u8 positions[VIRTIO_SND_CHMAP_MAX_SIZE]; 332 + }; 333 + 334 + /******************************************************************************* 335 + * CONTROL ELEMENTS MESSAGES 336 + */ 337 + struct virtio_snd_ctl_hdr { 338 + /* VIRTIO_SND_R_CTL_XXX */ 339 + struct virtio_snd_hdr hdr; 340 + /* 0 ... virtio_snd_config::controls - 1 */ 341 + __le32 control_id; 342 + }; 343 + 344 + /* supported roles for control elements */ 345 + enum { 346 + VIRTIO_SND_CTL_ROLE_UNDEFINED = 0, 347 + VIRTIO_SND_CTL_ROLE_VOLUME, 348 + VIRTIO_SND_CTL_ROLE_MUTE, 349 + VIRTIO_SND_CTL_ROLE_GAIN 350 + }; 351 + 352 + /* supported value types for control elements */ 353 + enum { 354 + VIRTIO_SND_CTL_TYPE_BOOLEAN = 0, 355 + VIRTIO_SND_CTL_TYPE_INTEGER, 356 + VIRTIO_SND_CTL_TYPE_INTEGER64, 357 + VIRTIO_SND_CTL_TYPE_ENUMERATED, 358 + VIRTIO_SND_CTL_TYPE_BYTES, 359 + VIRTIO_SND_CTL_TYPE_IEC958 360 + }; 361 + 362 + /* supported access rights for control elements */ 363 + enum { 364 + VIRTIO_SND_CTL_ACCESS_READ = 0, 365 + VIRTIO_SND_CTL_ACCESS_WRITE, 366 + VIRTIO_SND_CTL_ACCESS_VOLATILE, 367 + VIRTIO_SND_CTL_ACCESS_INACTIVE, 368 + VIRTIO_SND_CTL_ACCESS_TLV_READ, 369 + VIRTIO_SND_CTL_ACCESS_TLV_WRITE, 370 + VIRTIO_SND_CTL_ACCESS_TLV_COMMAND 371 + }; 372 + 373 + struct virtio_snd_ctl_info { 374 + /* common header */ 375 + struct virtio_snd_info hdr; 376 + /* element role (VIRTIO_SND_CTL_ROLE_XXX) */ 377 + __le32 role; 378 + /* element value type (VIRTIO_SND_CTL_TYPE_XXX) */ 379 + __le32 type; 380 + /* element access right bit map (1 << VIRTIO_SND_CTL_ACCESS_XXX) */ 381 + __le32 access; 382 + /* # of members in the element value */ 383 + __le32 count; 384 + /* index for an element with a non-unique name */ 385 + __le32 index; 386 + /* name identifier string for the element */ 387 + __u8 name[44]; 388 + /* additional information about the element's value */ 389 + union { 390 + /* VIRTIO_SND_CTL_TYPE_INTEGER */ 391 + struct { 392 + /* minimum supported value */ 393 + __le32 min; 394 + /* maximum supported value */ 395 + __le32 max; 396 + /* fixed step size for value (0 = variable size) */ 397 + __le32 step; 398 + } integer; 399 + /* VIRTIO_SND_CTL_TYPE_INTEGER64 */ 400 + struct { 401 + /* minimum supported value */ 402 + __le64 min; 403 + /* maximum supported value */ 404 + __le64 max; 405 + /* fixed step size for value (0 = variable size) */ 406 + __le64 step; 407 + } integer64; 408 + /* VIRTIO_SND_CTL_TYPE_ENUMERATED */ 409 + struct { 410 + /* # of options supported for value */ 411 + __le32 items; 412 + } enumerated; 413 + } value; 414 + }; 415 + 416 + struct virtio_snd_ctl_enum_item { 417 + /* option name */ 418 + __u8 item[64]; 419 + }; 420 + 421 + struct virtio_snd_ctl_iec958 { 422 + /* AES/IEC958 channel status bits */ 423 + __u8 status[24]; 424 + /* AES/IEC958 subcode bits */ 425 + __u8 subcode[147]; 426 + /* nothing */ 427 + __u8 pad; 428 + /* AES/IEC958 subframe bits */ 429 + __u8 dig_subframe[4]; 430 + }; 431 + 432 + struct virtio_snd_ctl_value { 433 + union { 434 + /* VIRTIO_SND_CTL_TYPE_BOOLEAN|INTEGER value */ 435 + __le32 integer[128]; 436 + /* VIRTIO_SND_CTL_TYPE_INTEGER64 value */ 437 + __le64 integer64[64]; 438 + /* VIRTIO_SND_CTL_TYPE_ENUMERATED value (option indexes) */ 439 + __le32 enumerated[128]; 440 + /* VIRTIO_SND_CTL_TYPE_BYTES value */ 441 + __u8 bytes[512]; 442 + /* VIRTIO_SND_CTL_TYPE_IEC958 value */ 443 + struct virtio_snd_ctl_iec958 iec958; 444 + } value; 445 + }; 446 + 447 + /* supported event reason types */ 448 + enum { 449 + /* element's value has changed */ 450 + VIRTIO_SND_CTL_EVT_MASK_VALUE = 0, 451 + /* element's information has changed */ 452 + VIRTIO_SND_CTL_EVT_MASK_INFO, 453 + /* element's metadata has changed */ 454 + VIRTIO_SND_CTL_EVT_MASK_TLV 455 + }; 456 + 457 + struct virtio_snd_ctl_event { 458 + /* VIRTIO_SND_EVT_CTL_NOTIFY */ 459 + struct virtio_snd_hdr hdr; 460 + /* 0 ... virtio_snd_config::controls - 1 */ 461 + __le16 control_id; 462 + /* event reason bit map (1 << VIRTIO_SND_CTL_EVT_MASK_XXX) */ 463 + __le16 mask; 354 464 }; 355 465 356 466 #endif /* VIRTIO_SND_IF_H */
+1 -6
sound/aoa/fabrics/layout.c
··· 1126 1126 sdev->pcmname = NULL; 1127 1127 } 1128 1128 1129 - #ifdef CONFIG_PM_SLEEP 1130 1129 static int aoa_fabric_layout_suspend(struct device *dev) 1131 1130 { 1132 1131 struct layout_dev *ldev = dev_get_drvdata(dev); ··· 1146 1147 return 0; 1147 1148 } 1148 1149 1149 - static SIMPLE_DEV_PM_OPS(aoa_fabric_layout_pm_ops, 1150 + static DEFINE_SIMPLE_DEV_PM_OPS(aoa_fabric_layout_pm_ops, 1150 1151 aoa_fabric_layout_suspend, aoa_fabric_layout_resume); 1151 - 1152 - #endif 1153 1152 1154 1153 static struct soundbus_driver aoa_soundbus_driver = { 1155 1154 .name = "snd_aoa_soundbus_drv", ··· 1156 1159 .remove = aoa_fabric_layout_remove, 1157 1160 .driver = { 1158 1161 .owner = THIS_MODULE, 1159 - #ifdef CONFIG_PM_SLEEP 1160 1162 .pm = &aoa_fabric_layout_pm_ops, 1161 - #endif 1162 1163 } 1163 1164 }; 1164 1165
+1 -1
sound/aoa/soundbus/core.c
··· 127 127 128 128 /* soundbus_dev_attrs is declared in sysfs.c */ 129 129 ATTRIBUTE_GROUPS(soundbus_dev); 130 - static struct bus_type soundbus_bus_type = { 130 + static const struct bus_type soundbus_bus_type = { 131 131 .name = "aoa-soundbus", 132 132 .probe = soundbus_probe, 133 133 .uevent = soundbus_uevent,
+2 -8
sound/arm/aaci.c
··· 737 737 /* 738 738 * Power Management. 739 739 */ 740 - #ifdef CONFIG_PM 741 740 static int aaci_do_suspend(struct snd_card *card) 742 741 { 743 742 struct aaci *aaci = card->private_data; ··· 762 763 return card ? aaci_do_resume(card) : 0; 763 764 } 764 765 765 - static SIMPLE_DEV_PM_OPS(aaci_dev_pm_ops, aaci_suspend, aaci_resume); 766 - #define AACI_DEV_PM_OPS (&aaci_dev_pm_ops) 767 - #else 768 - #define AACI_DEV_PM_OPS NULL 769 - #endif 770 - 766 + static DEFINE_SIMPLE_DEV_PM_OPS(aaci_dev_pm_ops, aaci_suspend, aaci_resume); 771 767 772 768 static const struct ac97_pcm ac97_defs[] = { 773 769 [0] = { /* Front PCM */ ··· 1075 1081 static struct amba_driver aaci_driver = { 1076 1082 .drv = { 1077 1083 .name = DRIVER_NAME, 1078 - .pm = AACI_DEV_PM_OPS, 1084 + .pm = &aaci_dev_pm_ops, 1079 1085 }, 1080 1086 .probe = aaci_probe, 1081 1087 .remove = aaci_remove,
+1 -6
sound/arm/pxa2xx-ac97.c
··· 111 111 return snd_ac97_set_rate(pxa2xx_ac97_ac97, reg, runtime->rate); 112 112 } 113 113 114 - #ifdef CONFIG_PM_SLEEP 115 - 116 114 static int pxa2xx_ac97_do_suspend(struct snd_card *card) 117 115 { 118 116 pxa2xx_audio_ops_t *platform_ops = card->dev->platform_data; ··· 162 164 return ret; 163 165 } 164 166 165 - static SIMPLE_DEV_PM_OPS(pxa2xx_ac97_pm_ops, pxa2xx_ac97_suspend, pxa2xx_ac97_resume); 166 - #endif 167 + static DEFINE_SIMPLE_DEV_PM_OPS(pxa2xx_ac97_pm_ops, pxa2xx_ac97_suspend, pxa2xx_ac97_resume); 167 168 168 169 static const struct snd_pcm_ops pxa2xx_ac97_pcm_ops = { 169 170 .open = pxa2xx_ac97_pcm_open, ··· 274 277 .remove_new = pxa2xx_ac97_remove, 275 278 .driver = { 276 279 .name = "pxa2xx-ac97", 277 - #ifdef CONFIG_PM_SLEEP 278 280 .pm = &pxa2xx_ac97_pm_ops, 279 - #endif 280 281 }, 281 282 }; 282 283
+17
sound/core/Kconfig
··· 39 39 legacy MIDI 1.0 byte streams is created for each UMP Endpoint. 40 40 The device contains 16 substreams corresponding to UMP groups. 41 41 42 + config SND_CORE_TEST 43 + tristate "Sound core KUnit test" 44 + depends on KUNIT 45 + select SND_PCM 46 + default KUNIT_ALL_TESTS 47 + help 48 + This options enables the sound core functions KUnit test. 49 + 50 + KUnit tests run during boot and output the results to the debug 51 + log in TAP format (https://testanything.org/). Only useful for 52 + kernel devs running KUnit test harness and are not for inclusion 53 + into a production build. 54 + 55 + For more information on KUnit and unit tests in general, refer 56 + to the KUnit documentation in Documentation/dev-tools/kunit/. 57 + 58 + 42 59 config SND_COMPRESS_OFFLOAD 43 60 tristate 44 61
+2
sound/core/Makefile
··· 48 48 obj-$(CONFIG_SND_RAWMIDI) += snd-rawmidi.o 49 49 obj-$(CONFIG_SND_UMP) += snd-ump.o 50 50 51 + obj-$(CONFIG_SND_CORE_TEST) += sound_kunit.o 52 + 51 53 obj-$(CONFIG_SND_OSSEMUL) += oss/ 52 54 obj-$(CONFIG_SND_SEQUENCER) += seq/ 53 55
+46 -88
sound/core/compress_offload.c
··· 127 127 init_waitqueue_head(&runtime->sleep); 128 128 data->stream.runtime = runtime; 129 129 f->private_data = (void *)data; 130 - mutex_lock(&compr->lock); 131 - ret = compr->ops->open(&data->stream); 132 - mutex_unlock(&compr->lock); 130 + scoped_guard(mutex, &compr->lock) 131 + ret = compr->ops->open(&data->stream); 133 132 if (ret) { 134 133 kfree(runtime); 135 134 kfree(data); ··· 287 288 return -EFAULT; 288 289 289 290 stream = &data->stream; 290 - mutex_lock(&stream->device->lock); 291 + guard(mutex)(&stream->device->lock); 291 292 /* write is allowed when stream is running or has been steup */ 292 293 switch (stream->runtime->state) { 293 294 case SNDRV_PCM_STATE_SETUP: ··· 295 296 case SNDRV_PCM_STATE_RUNNING: 296 297 break; 297 298 default: 298 - mutex_unlock(&stream->device->lock); 299 299 return -EBADFD; 300 300 } 301 301 ··· 320 322 pr_debug("stream prepared, Houston we are good to go\n"); 321 323 } 322 324 323 - mutex_unlock(&stream->device->lock); 324 325 return retval; 325 326 } 326 327 ··· 336 339 return -EFAULT; 337 340 338 341 stream = &data->stream; 339 - mutex_lock(&stream->device->lock); 342 + guard(mutex)(&stream->device->lock); 340 343 341 344 /* read is allowed when stream is running, paused, draining and setup 342 345 * (yes setup is state which we transition to after stop, so if user ··· 347 350 case SNDRV_PCM_STATE_PREPARED: 348 351 case SNDRV_PCM_STATE_SUSPENDED: 349 352 case SNDRV_PCM_STATE_DISCONNECTED: 350 - retval = -EBADFD; 351 - goto out; 353 + return -EBADFD; 352 354 case SNDRV_PCM_STATE_XRUN: 353 - retval = -EPIPE; 354 - goto out; 355 + return -EPIPE; 355 356 } 356 357 357 358 avail = snd_compr_get_avail(stream); ··· 358 363 if (avail > count) 359 364 avail = count; 360 365 361 - if (stream->ops->copy) { 366 + if (stream->ops->copy) 362 367 retval = stream->ops->copy(stream, buf, avail); 363 - } else { 364 - retval = -ENXIO; 365 - goto out; 366 - } 368 + else 369 + return -ENXIO; 367 370 if (retval > 0) 368 371 stream->runtime->total_bytes_transferred += retval; 369 372 370 - out: 371 - mutex_unlock(&stream->device->lock); 372 373 return retval; 373 374 } 374 375 ··· 393 402 394 403 stream = &data->stream; 395 404 396 - mutex_lock(&stream->device->lock); 405 + guard(mutex)(&stream->device->lock); 397 406 398 407 switch (stream->runtime->state) { 399 408 case SNDRV_PCM_STATE_OPEN: 400 409 case SNDRV_PCM_STATE_XRUN: 401 - retval = snd_compr_get_poll(stream) | EPOLLERR; 402 - goto out; 410 + return snd_compr_get_poll(stream) | EPOLLERR; 403 411 default: 404 412 break; 405 413 } ··· 423 433 retval = snd_compr_get_poll(stream); 424 434 break; 425 435 default: 426 - retval = snd_compr_get_poll(stream) | EPOLLERR; 427 - break; 436 + return snd_compr_get_poll(stream) | EPOLLERR; 428 437 } 429 - out: 430 - mutex_unlock(&stream->device->lock); 438 + 431 439 return retval; 432 440 } 433 441 ··· 453 465 snd_compr_get_codec_caps(struct snd_compr_stream *stream, unsigned long arg) 454 466 { 455 467 int retval; 456 - struct snd_compr_codec_caps *caps; 468 + struct snd_compr_codec_caps *caps __free(kfree) = NULL; 457 469 458 470 if (!stream->ops->get_codec_caps) 459 471 return -ENXIO; ··· 464 476 465 477 retval = stream->ops->get_codec_caps(stream, caps); 466 478 if (retval) 467 - goto out; 479 + return retval; 468 480 if (copy_to_user((void __user *)arg, caps, sizeof(*caps))) 469 - retval = -EFAULT; 470 - 471 - out: 472 - kfree(caps); 481 + return -EFAULT; 473 482 return retval; 474 483 } 475 484 #endif /* !COMPR_CODEC_CAPS_OVERFLOW */ ··· 571 586 static int 572 587 snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg) 573 588 { 574 - struct snd_compr_params *params; 589 + struct snd_compr_params *params __free(kfree) = NULL; 575 590 int retval; 576 591 577 592 if (stream->runtime->state == SNDRV_PCM_STATE_OPEN || stream->next_track) { ··· 581 596 */ 582 597 params = memdup_user((void __user *)arg, sizeof(*params)); 583 598 if (IS_ERR(params)) 584 - return PTR_ERR(params); 599 + return PTR_ERR(no_free_ptr(params)); 585 600 586 601 retval = snd_compress_check_input(params); 587 602 if (retval) 588 - goto out; 603 + return retval; 589 604 590 605 retval = snd_compr_allocate_buffer(stream, params); 591 - if (retval) { 592 - retval = -ENOMEM; 593 - goto out; 594 - } 606 + if (retval) 607 + return -ENOMEM; 595 608 596 609 retval = stream->ops->set_params(stream, params); 597 610 if (retval) 598 - goto out; 611 + return retval; 599 612 600 613 if (stream->next_track) 601 - goto out; 614 + return retval; 602 615 603 616 stream->metadata_set = false; 604 617 stream->next_track = false; ··· 605 622 } else { 606 623 return -EPERM; 607 624 } 608 - out: 609 - kfree(params); 610 625 return retval; 611 626 } 612 627 613 628 static int 614 629 snd_compr_get_params(struct snd_compr_stream *stream, unsigned long arg) 615 630 { 616 - struct snd_codec *params; 631 + struct snd_codec *params __free(kfree) = NULL; 617 632 int retval; 618 633 619 634 if (!stream->ops->get_params) ··· 622 641 return -ENOMEM; 623 642 retval = stream->ops->get_params(stream, params); 624 643 if (retval) 625 - goto out; 644 + return retval; 626 645 if (copy_to_user((char __user *)arg, params, sizeof(*params))) 627 - retval = -EFAULT; 628 - 629 - out: 630 - kfree(params); 646 + return -EFAULT; 631 647 return retval; 632 648 } 633 649 ··· 783 805 784 806 stream = container_of(work, struct snd_compr_stream, error_work.work); 785 807 786 - mutex_lock(&stream->device->lock); 808 + guard(mutex)(&stream->device->lock); 787 809 788 810 stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_STOP); 789 811 wake_up(&stream->runtime->sleep); 790 - 791 - mutex_unlock(&stream->device->lock); 792 812 } 793 813 794 814 /** ··· 943 967 { 944 968 struct snd_compr_file *data = f->private_data; 945 969 struct snd_compr_stream *stream; 946 - int retval = -ENOTTY; 947 970 948 971 if (snd_BUG_ON(!data)) 949 972 return -EFAULT; 950 973 951 974 stream = &data->stream; 952 975 953 - mutex_lock(&stream->device->lock); 976 + guard(mutex)(&stream->device->lock); 954 977 switch (_IOC_NR(cmd)) { 955 978 case _IOC_NR(SNDRV_COMPRESS_IOCTL_VERSION): 956 - retval = put_user(SNDRV_COMPRESS_VERSION, 979 + return put_user(SNDRV_COMPRESS_VERSION, 957 980 (int __user *)arg) ? -EFAULT : 0; 958 - break; 959 981 case _IOC_NR(SNDRV_COMPRESS_GET_CAPS): 960 - retval = snd_compr_get_caps(stream, arg); 961 - break; 982 + return snd_compr_get_caps(stream, arg); 962 983 #ifndef COMPR_CODEC_CAPS_OVERFLOW 963 984 case _IOC_NR(SNDRV_COMPRESS_GET_CODEC_CAPS): 964 - retval = snd_compr_get_codec_caps(stream, arg); 965 - break; 985 + return snd_compr_get_codec_caps(stream, arg); 966 986 #endif 967 987 case _IOC_NR(SNDRV_COMPRESS_SET_PARAMS): 968 - retval = snd_compr_set_params(stream, arg); 969 - break; 988 + return snd_compr_set_params(stream, arg); 970 989 case _IOC_NR(SNDRV_COMPRESS_GET_PARAMS): 971 - retval = snd_compr_get_params(stream, arg); 972 - break; 990 + return snd_compr_get_params(stream, arg); 973 991 case _IOC_NR(SNDRV_COMPRESS_SET_METADATA): 974 - retval = snd_compr_set_metadata(stream, arg); 975 - break; 992 + return snd_compr_set_metadata(stream, arg); 976 993 case _IOC_NR(SNDRV_COMPRESS_GET_METADATA): 977 - retval = snd_compr_get_metadata(stream, arg); 978 - break; 994 + return snd_compr_get_metadata(stream, arg); 979 995 case _IOC_NR(SNDRV_COMPRESS_TSTAMP): 980 - retval = snd_compr_tstamp(stream, arg); 981 - break; 996 + return snd_compr_tstamp(stream, arg); 982 997 case _IOC_NR(SNDRV_COMPRESS_AVAIL): 983 - retval = snd_compr_ioctl_avail(stream, arg); 984 - break; 998 + return snd_compr_ioctl_avail(stream, arg); 985 999 case _IOC_NR(SNDRV_COMPRESS_PAUSE): 986 - retval = snd_compr_pause(stream); 987 - break; 1000 + return snd_compr_pause(stream); 988 1001 case _IOC_NR(SNDRV_COMPRESS_RESUME): 989 - retval = snd_compr_resume(stream); 990 - break; 1002 + return snd_compr_resume(stream); 991 1003 case _IOC_NR(SNDRV_COMPRESS_START): 992 - retval = snd_compr_start(stream); 993 - break; 1004 + return snd_compr_start(stream); 994 1005 case _IOC_NR(SNDRV_COMPRESS_STOP): 995 - retval = snd_compr_stop(stream); 996 - break; 1006 + return snd_compr_stop(stream); 997 1007 case _IOC_NR(SNDRV_COMPRESS_DRAIN): 998 - retval = snd_compr_drain(stream); 999 - break; 1008 + return snd_compr_drain(stream); 1000 1009 case _IOC_NR(SNDRV_COMPRESS_PARTIAL_DRAIN): 1001 - retval = snd_compr_partial_drain(stream); 1002 - break; 1010 + return snd_compr_partial_drain(stream); 1003 1011 case _IOC_NR(SNDRV_COMPRESS_NEXT_TRACK): 1004 - retval = snd_compr_next_track(stream); 1005 - break; 1006 - 1012 + return snd_compr_next_track(stream); 1007 1013 } 1008 - mutex_unlock(&stream->device->lock); 1009 - return retval; 1014 + 1015 + return -ENOTTY; 1010 1016 } 1011 1017 1012 1018 /* support of 32bit userspace on 64bit platforms */
+179 -275
sound/core/control.c
··· 44 44 45 45 static int snd_ctl_open(struct inode *inode, struct file *file) 46 46 { 47 - unsigned long flags; 48 47 struct snd_card *card; 49 48 struct snd_ctl_file *ctl; 50 49 int i, err; ··· 79 80 ctl->preferred_subdevice[i] = -1; 80 81 ctl->pid = get_pid(task_pid(current)); 81 82 file->private_data = ctl; 82 - write_lock_irqsave(&card->ctl_files_rwlock, flags); 83 - list_add_tail(&ctl->list, &card->ctl_files); 84 - write_unlock_irqrestore(&card->ctl_files_rwlock, flags); 83 + scoped_guard(write_lock_irqsave, &card->ctl_files_rwlock) 84 + list_add_tail(&ctl->list, &card->ctl_files); 85 85 snd_card_unref(card); 86 86 return 0; 87 87 ··· 96 98 97 99 static void snd_ctl_empty_read_queue(struct snd_ctl_file * ctl) 98 100 { 99 - unsigned long flags; 100 101 struct snd_kctl_event *cread; 101 102 102 - spin_lock_irqsave(&ctl->read_lock, flags); 103 + guard(spinlock_irqsave)(&ctl->read_lock); 103 104 while (!list_empty(&ctl->events)) { 104 105 cread = snd_kctl_event(ctl->events.next); 105 106 list_del(&cread->list); 106 107 kfree(cread); 107 108 } 108 - spin_unlock_irqrestore(&ctl->read_lock, flags); 109 109 } 110 110 111 111 static int snd_ctl_release(struct inode *inode, struct file *file) 112 112 { 113 - unsigned long flags; 114 113 struct snd_card *card; 115 114 struct snd_ctl_file *ctl; 116 115 struct snd_kcontrol *control; ··· 116 121 ctl = file->private_data; 117 122 file->private_data = NULL; 118 123 card = ctl->card; 119 - write_lock_irqsave(&card->ctl_files_rwlock, flags); 120 - list_del(&ctl->list); 121 - write_unlock_irqrestore(&card->ctl_files_rwlock, flags); 122 - down_write(&card->controls_rwsem); 123 - list_for_each_entry(control, &card->controls, list) 124 - for (idx = 0; idx < control->count; idx++) 125 - if (control->vd[idx].owner == ctl) 126 - control->vd[idx].owner = NULL; 127 - up_write(&card->controls_rwsem); 124 + 125 + scoped_guard(write_lock_irqsave, &card->ctl_files_rwlock) 126 + list_del(&ctl->list); 127 + 128 + scoped_guard(rwsem_write, &card->controls_rwsem) { 129 + list_for_each_entry(control, &card->controls, list) 130 + for (idx = 0; idx < control->count; idx++) 131 + if (control->vd[idx].owner == ctl) 132 + control->vd[idx].owner = NULL; 133 + } 134 + 128 135 snd_fasync_free(ctl->fasync); 129 136 snd_ctl_empty_read_queue(ctl); 130 137 put_pid(ctl->pid); ··· 149 152 void snd_ctl_notify(struct snd_card *card, unsigned int mask, 150 153 struct snd_ctl_elem_id *id) 151 154 { 152 - unsigned long flags; 153 155 struct snd_ctl_file *ctl; 154 156 struct snd_kctl_event *ev; 155 157 ··· 156 160 return; 157 161 if (card->shutdown) 158 162 return; 159 - read_lock_irqsave(&card->ctl_files_rwlock, flags); 163 + 164 + guard(read_lock_irqsave)(&card->ctl_files_rwlock); 160 165 #if IS_ENABLED(CONFIG_SND_MIXER_OSS) 161 166 card->mixer_oss_change_count++; 162 167 #endif 163 168 list_for_each_entry(ctl, &card->ctl_files, list) { 164 169 if (!ctl->subscribed) 165 170 continue; 166 - spin_lock(&ctl->read_lock); 167 - list_for_each_entry(ev, &ctl->events, list) { 168 - if (ev->id.numid == id->numid) { 169 - ev->mask |= mask; 170 - goto _found; 171 + scoped_guard(spinlock, &ctl->read_lock) { 172 + list_for_each_entry(ev, &ctl->events, list) { 173 + if (ev->id.numid == id->numid) { 174 + ev->mask |= mask; 175 + goto _found; 176 + } 171 177 } 178 + ev = kzalloc(sizeof(*ev), GFP_ATOMIC); 179 + if (ev) { 180 + ev->id = *id; 181 + ev->mask = mask; 182 + list_add_tail(&ev->list, &ctl->events); 183 + } else { 184 + dev_err(card->dev, "No memory available to allocate event\n"); 185 + } 186 + _found: 187 + wake_up(&ctl->change_sleep); 172 188 } 173 - ev = kzalloc(sizeof(*ev), GFP_ATOMIC); 174 - if (ev) { 175 - ev->id = *id; 176 - ev->mask = mask; 177 - list_add_tail(&ev->list, &ctl->events); 178 - } else { 179 - dev_err(card->dev, "No memory available to allocate event\n"); 180 - } 181 - _found: 182 - wake_up(&ctl->change_sleep); 183 - spin_unlock(&ctl->read_lock); 184 189 snd_kill_fasync(ctl->fasync, SIGIO, POLL_IN); 185 190 } 186 - read_unlock_irqrestore(&card->ctl_files_rwlock, flags); 187 191 } 188 192 EXPORT_SYMBOL(snd_ctl_notify); 189 193 ··· 206 210 id.index += ioff; 207 211 id.numid += ioff; 208 212 snd_ctl_notify(card, mask, &id); 209 - down_read(&snd_ctl_layer_rwsem); 213 + guard(rwsem_read)(&snd_ctl_layer_rwsem); 210 214 for (lops = snd_ctl_layer; lops; lops = lops->next) 211 215 lops->lnotify(card, mask, kctl, ioff); 212 - up_read(&snd_ctl_layer_rwsem); 213 216 } 214 217 EXPORT_SYMBOL(snd_ctl_notify_one); 215 218 ··· 515 520 if (snd_BUG_ON(!card || !kcontrol->info)) 516 521 goto error; 517 522 518 - down_write(&card->controls_rwsem); 519 - err = __snd_ctl_add_replace(card, kcontrol, mode); 520 - up_write(&card->controls_rwsem); 523 + scoped_guard(rwsem_write, &card->controls_rwsem) 524 + err = __snd_ctl_add_replace(card, kcontrol, mode); 525 + 521 526 if (err < 0) 522 527 goto error; 523 528 return 0; ··· 611 616 */ 612 617 int snd_ctl_remove(struct snd_card *card, struct snd_kcontrol *kcontrol) 613 618 { 614 - int ret; 615 - 616 - down_write(&card->controls_rwsem); 617 - ret = snd_ctl_remove_locked(card, kcontrol); 618 - up_write(&card->controls_rwsem); 619 - return ret; 619 + guard(rwsem_write)(&card->controls_rwsem); 620 + return snd_ctl_remove_locked(card, kcontrol); 620 621 } 621 622 EXPORT_SYMBOL(snd_ctl_remove); 622 623 ··· 629 638 int snd_ctl_remove_id(struct snd_card *card, struct snd_ctl_elem_id *id) 630 639 { 631 640 struct snd_kcontrol *kctl; 632 - int ret; 633 641 634 - down_write(&card->controls_rwsem); 642 + guard(rwsem_write)(&card->controls_rwsem); 635 643 kctl = snd_ctl_find_id_locked(card, id); 636 - if (kctl == NULL) { 637 - up_write(&card->controls_rwsem); 644 + if (kctl == NULL) 638 645 return -ENOENT; 639 - } 640 - ret = snd_ctl_remove_locked(card, kctl); 641 - up_write(&card->controls_rwsem); 642 - return ret; 646 + return snd_ctl_remove_locked(card, kctl); 643 647 } 644 648 EXPORT_SYMBOL(snd_ctl_remove_id); 645 649 ··· 653 667 { 654 668 struct snd_card *card = file->card; 655 669 struct snd_kcontrol *kctl; 656 - int idx, ret; 670 + int idx; 657 671 658 - down_write(&card->controls_rwsem); 672 + guard(rwsem_write)(&card->controls_rwsem); 659 673 kctl = snd_ctl_find_id_locked(card, id); 660 - if (kctl == NULL) { 661 - ret = -ENOENT; 662 - goto error; 663 - } 664 - if (!(kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_USER)) { 665 - ret = -EINVAL; 666 - goto error; 667 - } 674 + if (kctl == NULL) 675 + return -ENOENT; 676 + if (!(kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_USER)) 677 + return -EINVAL; 668 678 for (idx = 0; idx < kctl->count; idx++) 669 - if (kctl->vd[idx].owner != NULL && kctl->vd[idx].owner != file) { 670 - ret = -EBUSY; 671 - goto error; 672 - } 673 - ret = snd_ctl_remove_locked(card, kctl); 674 - error: 675 - up_write(&card->controls_rwsem); 676 - return ret; 679 + if (kctl->vd[idx].owner != NULL && kctl->vd[idx].owner != file) 680 + return -EBUSY; 681 + return snd_ctl_remove_locked(card, kctl); 677 682 } 678 683 679 684 /** ··· 741 764 struct snd_kcontrol *kctl; 742 765 int saved_numid; 743 766 744 - down_write(&card->controls_rwsem); 767 + guard(rwsem_write)(&card->controls_rwsem); 745 768 kctl = snd_ctl_find_id_locked(card, src_id); 746 - if (kctl == NULL) { 747 - up_write(&card->controls_rwsem); 769 + if (kctl == NULL) 748 770 return -ENOENT; 749 - } 750 771 saved_numid = kctl->id.numid; 751 772 remove_hash_entries(card, kctl); 752 773 kctl->id = *dst_id; 753 774 kctl->id.numid = saved_numid; 754 775 add_hash_entries(card, kctl); 755 - up_write(&card->controls_rwsem); 756 776 return 0; 757 777 } 758 778 EXPORT_SYMBOL(snd_ctl_rename_id); ··· 767 793 void snd_ctl_rename(struct snd_card *card, struct snd_kcontrol *kctl, 768 794 const char *name) 769 795 { 770 - down_write(&card->controls_rwsem); 796 + guard(rwsem_write)(&card->controls_rwsem); 771 797 remove_hash_entries(card, kctl); 772 798 773 799 if (strscpy(kctl->id.name, name, sizeof(kctl->id.name)) < 0) ··· 775 801 name, kctl->id.name); 776 802 777 803 add_hash_entries(card, kctl); 778 - up_write(&card->controls_rwsem); 779 804 } 780 805 EXPORT_SYMBOL(snd_ctl_rename); 781 806 ··· 832 859 struct snd_kcontrol *snd_ctl_find_numid(struct snd_card *card, 833 860 unsigned int numid) 834 861 { 835 - struct snd_kcontrol *kctl; 836 - 837 - down_read(&card->controls_rwsem); 838 - kctl = snd_ctl_find_numid_locked(card, numid); 839 - up_read(&card->controls_rwsem); 840 - return kctl; 862 + guard(rwsem_read)(&card->controls_rwsem); 863 + return snd_ctl_find_numid_locked(card, numid); 841 864 } 842 865 EXPORT_SYMBOL(snd_ctl_find_numid); 843 866 ··· 889 920 struct snd_kcontrol *snd_ctl_find_id(struct snd_card *card, 890 921 const struct snd_ctl_elem_id *id) 891 922 { 892 - struct snd_kcontrol *kctl; 893 - 894 - down_read(&card->controls_rwsem); 895 - kctl = snd_ctl_find_id_locked(card, id); 896 - up_read(&card->controls_rwsem); 897 - return kctl; 923 + guard(rwsem_read)(&card->controls_rwsem); 924 + return snd_ctl_find_id_locked(card, id); 898 925 } 899 926 EXPORT_SYMBOL(snd_ctl_find_id); 900 927 901 928 static int snd_ctl_card_info(struct snd_card *card, struct snd_ctl_file * ctl, 902 929 unsigned int cmd, void __user *arg) 903 930 { 904 - struct snd_ctl_card_info *info; 931 + struct snd_ctl_card_info *info __free(kfree) = NULL; 905 932 906 933 info = kzalloc(sizeof(*info), GFP_KERNEL); 907 934 if (! info) 908 935 return -ENOMEM; 909 - down_read(&snd_ioctl_rwsem); 910 - info->card = card->number; 911 - strscpy(info->id, card->id, sizeof(info->id)); 912 - strscpy(info->driver, card->driver, sizeof(info->driver)); 913 - strscpy(info->name, card->shortname, sizeof(info->name)); 914 - strscpy(info->longname, card->longname, sizeof(info->longname)); 915 - strscpy(info->mixername, card->mixername, sizeof(info->mixername)); 916 - strscpy(info->components, card->components, sizeof(info->components)); 917 - up_read(&snd_ioctl_rwsem); 918 - if (copy_to_user(arg, info, sizeof(struct snd_ctl_card_info))) { 919 - kfree(info); 920 - return -EFAULT; 936 + scoped_guard(rwsem_read, &snd_ioctl_rwsem) { 937 + info->card = card->number; 938 + strscpy(info->id, card->id, sizeof(info->id)); 939 + strscpy(info->driver, card->driver, sizeof(info->driver)); 940 + strscpy(info->name, card->shortname, sizeof(info->name)); 941 + strscpy(info->longname, card->longname, sizeof(info->longname)); 942 + strscpy(info->mixername, card->mixername, sizeof(info->mixername)); 943 + strscpy(info->components, card->components, sizeof(info->components)); 921 944 } 922 - kfree(info); 945 + if (copy_to_user(arg, info, sizeof(struct snd_ctl_card_info))) 946 + return -EFAULT; 923 947 return 0; 924 948 } 925 949 ··· 922 960 struct snd_kcontrol *kctl; 923 961 struct snd_ctl_elem_id id; 924 962 unsigned int offset, space, jidx; 925 - int err = 0; 926 963 927 964 offset = list->offset; 928 965 space = list->space; 929 966 930 - down_read(&card->controls_rwsem); 967 + guard(rwsem_read)(&card->controls_rwsem); 931 968 list->count = card->controls_count; 932 969 list->used = 0; 933 - if (space > 0) { 934 - list_for_each_entry(kctl, &card->controls, list) { 935 - if (offset >= kctl->count) { 936 - offset -= kctl->count; 937 - continue; 938 - } 939 - for (jidx = offset; jidx < kctl->count; jidx++) { 940 - snd_ctl_build_ioff(&id, kctl, jidx); 941 - if (copy_to_user(list->pids + list->used, &id, 942 - sizeof(id))) { 943 - err = -EFAULT; 944 - goto out; 945 - } 946 - list->used++; 947 - if (!--space) 948 - goto out; 949 - } 950 - offset = 0; 970 + if (!space) 971 + return 0; 972 + list_for_each_entry(kctl, &card->controls, list) { 973 + if (offset >= kctl->count) { 974 + offset -= kctl->count; 975 + continue; 951 976 } 977 + for (jidx = offset; jidx < kctl->count; jidx++) { 978 + snd_ctl_build_ioff(&id, kctl, jidx); 979 + if (copy_to_user(list->pids + list->used, &id, sizeof(id))) 980 + return -EFAULT; 981 + list->used++; 982 + if (!--space) 983 + return 0; 984 + } 985 + offset = 0; 952 986 } 953 - out: 954 - up_read(&card->controls_rwsem); 955 - return err; 987 + return 0; 956 988 } 957 989 958 990 static int snd_ctl_elem_list_user(struct snd_card *card, ··· 1194 1238 { 1195 1239 struct snd_card *card = ctl->card; 1196 1240 struct snd_kcontrol *kctl; 1197 - int result; 1198 1241 1199 - down_read(&card->controls_rwsem); 1242 + guard(rwsem_read)(&card->controls_rwsem); 1200 1243 kctl = snd_ctl_find_id_locked(card, &info->id); 1201 - if (kctl == NULL) 1202 - result = -ENOENT; 1203 - else 1204 - result = __snd_ctl_elem_info(card, kctl, info, ctl); 1205 - up_read(&card->controls_rwsem); 1206 - return result; 1244 + if (!kctl) 1245 + return -ENOENT; 1246 + return __snd_ctl_elem_info(card, kctl, info, ctl); 1207 1247 } 1208 1248 1209 1249 static int snd_ctl_elem_info_user(struct snd_ctl_file *ctl, ··· 1231 1279 const u32 pattern = 0xdeadbeef; 1232 1280 int ret; 1233 1281 1234 - down_read(&card->controls_rwsem); 1282 + guard(rwsem_read)(&card->controls_rwsem); 1235 1283 kctl = snd_ctl_find_id_locked(card, &control->id); 1236 - if (kctl == NULL) { 1237 - ret = -ENOENT; 1238 - goto unlock; 1239 - } 1284 + if (!kctl) 1285 + return -ENOENT; 1240 1286 1241 1287 index_offset = snd_ctl_get_ioff(kctl, &control->id); 1242 1288 vd = &kctl->vd[index_offset]; 1243 - if (!(vd->access & SNDRV_CTL_ELEM_ACCESS_READ) || kctl->get == NULL) { 1244 - ret = -EPERM; 1245 - goto unlock; 1246 - } 1289 + if (!(vd->access & SNDRV_CTL_ELEM_ACCESS_READ) || !kctl->get) 1290 + return -EPERM; 1247 1291 1248 1292 snd_ctl_build_ioff(&control->id, kctl, index_offset); 1249 1293 ··· 1249 1301 info.id = control->id; 1250 1302 ret = __snd_ctl_elem_info(card, kctl, &info, NULL); 1251 1303 if (ret < 0) 1252 - goto unlock; 1304 + return ret; 1253 1305 #endif 1254 1306 1255 1307 if (!snd_ctl_skip_validation(&info)) ··· 1259 1311 ret = kctl->get(kctl, control); 1260 1312 snd_power_unref(card); 1261 1313 if (ret < 0) 1262 - goto unlock; 1314 + return ret; 1263 1315 if (!snd_ctl_skip_validation(&info) && 1264 1316 sanity_check_elem_value(card, control, &info, pattern) < 0) { 1265 1317 dev_err(card->dev, ··· 1267 1319 control->id.iface, control->id.device, 1268 1320 control->id.subdevice, control->id.name, 1269 1321 control->id.index); 1270 - ret = -EINVAL; 1271 - goto unlock; 1322 + return -EINVAL; 1272 1323 } 1273 - unlock: 1274 - up_read(&card->controls_rwsem); 1275 - return ret; 1324 + return 0; 1276 1325 } 1277 1326 1278 1327 static int snd_ctl_elem_read_user(struct snd_card *card, ··· 1284 1339 1285 1340 result = snd_ctl_elem_read(card, control); 1286 1341 if (result < 0) 1287 - goto error; 1342 + return result; 1288 1343 1289 1344 if (copy_to_user(_control, control, sizeof(*control))) 1290 - result = -EFAULT; 1291 - error: 1292 - kfree(control); 1345 + return -EFAULT; 1293 1346 return result; 1294 1347 } 1295 1348 ··· 1349 1406 static int snd_ctl_elem_write_user(struct snd_ctl_file *file, 1350 1407 struct snd_ctl_elem_value __user *_control) 1351 1408 { 1352 - struct snd_ctl_elem_value *control; 1409 + struct snd_ctl_elem_value *control __free(kfree) = NULL; 1353 1410 struct snd_card *card; 1354 1411 int result; 1355 1412 1356 1413 control = memdup_user(_control, sizeof(*control)); 1357 1414 if (IS_ERR(control)) 1358 - return PTR_ERR(control); 1415 + return PTR_ERR(no_free_ptr(control)); 1359 1416 1360 1417 card = file->card; 1361 1418 result = snd_ctl_elem_write(card, file, control); 1362 1419 if (result < 0) 1363 - goto error; 1420 + return result; 1364 1421 1365 1422 if (copy_to_user(_control, control, sizeof(*control))) 1366 - result = -EFAULT; 1367 - error: 1368 - kfree(control); 1423 + return -EFAULT; 1369 1424 return result; 1370 1425 } 1371 1426 ··· 1374 1433 struct snd_ctl_elem_id id; 1375 1434 struct snd_kcontrol *kctl; 1376 1435 struct snd_kcontrol_volatile *vd; 1377 - int result; 1378 1436 1379 1437 if (copy_from_user(&id, _id, sizeof(id))) 1380 1438 return -EFAULT; 1381 - down_write(&card->controls_rwsem); 1439 + guard(rwsem_write)(&card->controls_rwsem); 1382 1440 kctl = snd_ctl_find_id_locked(card, &id); 1383 - if (kctl == NULL) { 1384 - result = -ENOENT; 1385 - } else { 1386 - vd = &kctl->vd[snd_ctl_get_ioff(kctl, &id)]; 1387 - if (vd->owner != NULL) 1388 - result = -EBUSY; 1389 - else { 1390 - vd->owner = file; 1391 - result = 0; 1392 - } 1393 - } 1394 - up_write(&card->controls_rwsem); 1395 - return result; 1441 + if (!kctl) 1442 + return -ENOENT; 1443 + vd = &kctl->vd[snd_ctl_get_ioff(kctl, &id)]; 1444 + if (vd->owner) 1445 + return -EBUSY; 1446 + vd->owner = file; 1447 + return 0; 1396 1448 } 1397 1449 1398 1450 static int snd_ctl_elem_unlock(struct snd_ctl_file *file, ··· 1395 1461 struct snd_ctl_elem_id id; 1396 1462 struct snd_kcontrol *kctl; 1397 1463 struct snd_kcontrol_volatile *vd; 1398 - int result; 1399 1464 1400 1465 if (copy_from_user(&id, _id, sizeof(id))) 1401 1466 return -EFAULT; 1402 - down_write(&card->controls_rwsem); 1467 + guard(rwsem_write)(&card->controls_rwsem); 1403 1468 kctl = snd_ctl_find_id_locked(card, &id); 1404 - if (kctl == NULL) { 1405 - result = -ENOENT; 1406 - } else { 1407 - vd = &kctl->vd[snd_ctl_get_ioff(kctl, &id)]; 1408 - if (vd->owner == NULL) 1409 - result = -EINVAL; 1410 - else if (vd->owner != file) 1411 - result = -EPERM; 1412 - else { 1413 - vd->owner = NULL; 1414 - result = 0; 1415 - } 1416 - } 1417 - up_write(&card->controls_rwsem); 1418 - return result; 1469 + if (!kctl) 1470 + return -ENOENT; 1471 + vd = &kctl->vd[snd_ctl_get_ioff(kctl, &id)]; 1472 + if (!vd->owner) 1473 + return -EINVAL; 1474 + if (vd->owner != file) 1475 + return -EPERM; 1476 + vd->owner = NULL; 1477 + return 0; 1419 1478 } 1420 1479 1421 1480 struct user_element { ··· 1690 1763 private_size = value_sizes[info->type] * info->count; 1691 1764 alloc_size = compute_user_elem_size(private_size, count); 1692 1765 1693 - down_write(&card->controls_rwsem); 1694 - if (check_user_elem_overflow(card, alloc_size)) { 1695 - err = -ENOMEM; 1696 - goto unlock; 1697 - } 1766 + guard(rwsem_write)(&card->controls_rwsem); 1767 + if (check_user_elem_overflow(card, alloc_size)) 1768 + return -ENOMEM; 1698 1769 1699 1770 /* 1700 1771 * Keep memory object for this userspace control. After passing this ··· 1702 1777 */ 1703 1778 err = snd_ctl_new(&kctl, count, access, file); 1704 1779 if (err < 0) 1705 - goto unlock; 1780 + return err; 1706 1781 memcpy(&kctl->id, &info->id, sizeof(kctl->id)); 1707 1782 ue = kzalloc(alloc_size, GFP_KERNEL); 1708 1783 if (!ue) { 1709 1784 kfree(kctl); 1710 - err = -ENOMEM; 1711 - goto unlock; 1785 + return -ENOMEM; 1712 1786 } 1713 1787 kctl->private_data = ue; 1714 1788 kctl->private_free = snd_ctl_elem_user_free; ··· 1725 1801 err = snd_ctl_elem_init_enum_names(ue); 1726 1802 if (err < 0) { 1727 1803 snd_ctl_free_one(kctl); 1728 - goto unlock; 1804 + return err; 1729 1805 } 1730 1806 } 1731 1807 ··· 1745 1821 err = __snd_ctl_add_replace(card, kctl, CTL_ADD_EXCLUSIVE); 1746 1822 if (err < 0) { 1747 1823 snd_ctl_free_one(kctl); 1748 - goto unlock; 1824 + return err; 1749 1825 } 1750 1826 offset = snd_ctl_get_ioff(kctl, &info->id); 1751 1827 snd_ctl_build_ioff(&info->id, kctl, offset); ··· 1756 1832 * applications because the field originally means PID of a process 1757 1833 * which locks the element. 1758 1834 */ 1759 - unlock: 1760 - up_write(&card->controls_rwsem); 1761 - return err; 1835 + return 0; 1762 1836 } 1763 1837 1764 1838 static int snd_ctl_elem_add_user(struct snd_ctl_file *file, ··· 1958 2036 case SNDRV_CTL_IOCTL_SUBSCRIBE_EVENTS: 1959 2037 return snd_ctl_subscribe_events(ctl, ip); 1960 2038 case SNDRV_CTL_IOCTL_TLV_READ: 1961 - down_read(&ctl->card->controls_rwsem); 1962 - err = snd_ctl_tlv_ioctl(ctl, argp, SNDRV_CTL_TLV_OP_READ); 1963 - up_read(&ctl->card->controls_rwsem); 2039 + scoped_guard(rwsem_read, &ctl->card->controls_rwsem) 2040 + err = snd_ctl_tlv_ioctl(ctl, argp, SNDRV_CTL_TLV_OP_READ); 1964 2041 return err; 1965 2042 case SNDRV_CTL_IOCTL_TLV_WRITE: 1966 - down_write(&ctl->card->controls_rwsem); 1967 - err = snd_ctl_tlv_ioctl(ctl, argp, SNDRV_CTL_TLV_OP_WRITE); 1968 - up_write(&ctl->card->controls_rwsem); 2043 + scoped_guard(rwsem_write, &ctl->card->controls_rwsem) 2044 + err = snd_ctl_tlv_ioctl(ctl, argp, SNDRV_CTL_TLV_OP_WRITE); 1969 2045 return err; 1970 2046 case SNDRV_CTL_IOCTL_TLV_COMMAND: 1971 - down_write(&ctl->card->controls_rwsem); 1972 - err = snd_ctl_tlv_ioctl(ctl, argp, SNDRV_CTL_TLV_OP_CMD); 1973 - up_write(&ctl->card->controls_rwsem); 2047 + scoped_guard(rwsem_write, &ctl->card->controls_rwsem) 2048 + err = snd_ctl_tlv_ioctl(ctl, argp, SNDRV_CTL_TLV_OP_CMD); 1974 2049 return err; 1975 2050 case SNDRV_CTL_IOCTL_POWER: 1976 2051 return -ENOPROTOOPT; 1977 2052 case SNDRV_CTL_IOCTL_POWER_STATE: 1978 2053 return put_user(SNDRV_CTL_POWER_D0, ip) ? -EFAULT : 0; 1979 2054 } 1980 - down_read(&snd_ioctl_rwsem); 2055 + 2056 + guard(rwsem_read)(&snd_ioctl_rwsem); 1981 2057 list_for_each_entry(p, &snd_control_ioctls, list) { 1982 2058 err = p->fioctl(card, ctl, cmd, arg); 1983 - if (err != -ENOIOCTLCMD) { 1984 - up_read(&snd_ioctl_rwsem); 2059 + if (err != -ENOIOCTLCMD) 1985 2060 return err; 1986 - } 1987 2061 } 1988 - up_read(&snd_ioctl_rwsem); 1989 2062 dev_dbg(card->dev, "unknown ioctl = 0x%x\n", cmd); 1990 2063 return -ENOTTY; 1991 2064 } ··· 2072 2155 if (pn == NULL) 2073 2156 return -ENOMEM; 2074 2157 pn->fioctl = fcn; 2075 - down_write(&snd_ioctl_rwsem); 2158 + guard(rwsem_write)(&snd_ioctl_rwsem); 2076 2159 list_add_tail(&pn->list, lists); 2077 - up_write(&snd_ioctl_rwsem); 2078 2160 return 0; 2079 2161 } 2080 2162 ··· 2116 2200 2117 2201 if (snd_BUG_ON(!fcn)) 2118 2202 return -EINVAL; 2119 - down_write(&snd_ioctl_rwsem); 2203 + guard(rwsem_write)(&snd_ioctl_rwsem); 2120 2204 list_for_each_entry(p, lists, list) { 2121 2205 if (p->fioctl == fcn) { 2122 2206 list_del(&p->list); 2123 - up_write(&snd_ioctl_rwsem); 2124 2207 kfree(p); 2125 2208 return 0; 2126 2209 } 2127 2210 } 2128 - up_write(&snd_ioctl_rwsem); 2129 2211 snd_BUG(); 2130 2212 return -EINVAL; 2131 2213 } ··· 2170 2256 { 2171 2257 struct snd_ctl_file *kctl; 2172 2258 int subdevice = -1; 2173 - unsigned long flags; 2174 2259 2175 - read_lock_irqsave(&card->ctl_files_rwlock, flags); 2260 + guard(read_lock_irqsave)(&card->ctl_files_rwlock); 2176 2261 list_for_each_entry(kctl, &card->ctl_files, list) { 2177 2262 if (kctl->pid == task_pid(current)) { 2178 2263 subdevice = kctl->preferred_subdevice[type]; ··· 2179 2266 break; 2180 2267 } 2181 2268 } 2182 - read_unlock_irqrestore(&card->ctl_files_rwlock, flags); 2183 2269 return subdevice; 2184 2270 } 2185 2271 EXPORT_SYMBOL_GPL(snd_ctl_get_preferred_subdevice); ··· 2208 2296 2209 2297 if (module_name == NULL) 2210 2298 return 0; 2211 - down_read(&snd_ctl_layer_rwsem); 2212 - for (lops = snd_ctl_layer; lops; lops = lops->next) 2213 - if (strcmp(lops->module_name, module_name) == 0) 2214 - break; 2215 - up_read(&snd_ctl_layer_rwsem); 2216 - if (lops) 2217 - return 0; 2299 + scoped_guard(rwsem_read, &snd_ctl_layer_rwsem) { 2300 + for (lops = snd_ctl_layer; lops; lops = lops->next) 2301 + if (strcmp(lops->module_name, module_name) == 0) 2302 + return 0; 2303 + } 2218 2304 return request_module(module_name); 2219 2305 } 2220 2306 EXPORT_SYMBOL_GPL(snd_ctl_request_layer); ··· 2229 2319 struct snd_card *card; 2230 2320 int card_number; 2231 2321 2232 - down_write(&snd_ctl_layer_rwsem); 2233 - lops->next = snd_ctl_layer; 2234 - snd_ctl_layer = lops; 2235 - up_write(&snd_ctl_layer_rwsem); 2322 + scoped_guard(rwsem_write, &snd_ctl_layer_rwsem) { 2323 + lops->next = snd_ctl_layer; 2324 + snd_ctl_layer = lops; 2325 + } 2236 2326 for (card_number = 0; card_number < SNDRV_CARDS; card_number++) { 2237 2327 card = snd_card_ref(card_number); 2238 2328 if (card) { 2239 - down_read(&card->controls_rwsem); 2240 - lops->lregister(card); 2241 - up_read(&card->controls_rwsem); 2329 + scoped_guard(rwsem_read, &card->controls_rwsem) 2330 + lops->lregister(card); 2242 2331 snd_card_unref(card); 2243 2332 } 2244 2333 } ··· 2256 2347 { 2257 2348 struct snd_ctl_layer_ops *lops2, *prev_lops2; 2258 2349 2259 - down_write(&snd_ctl_layer_rwsem); 2350 + guard(rwsem_write)(&snd_ctl_layer_rwsem); 2260 2351 for (lops2 = snd_ctl_layer, prev_lops2 = NULL; lops2; lops2 = lops2->next) { 2261 2352 if (lops2 == lops) { 2262 2353 if (!prev_lops2) ··· 2267 2358 } 2268 2359 prev_lops2 = lops2; 2269 2360 } 2270 - up_write(&snd_ctl_layer_rwsem); 2271 2361 } 2272 2362 EXPORT_SYMBOL_GPL(snd_ctl_disconnect_layer); 2273 2363 ··· 2287 2379 .fasync = snd_ctl_fasync, 2288 2380 }; 2289 2381 2382 + /* call lops under rwsems; called from snd_ctl_dev_*() below() */ 2383 + #define call_snd_ctl_lops(_card, _op) \ 2384 + do { \ 2385 + struct snd_ctl_layer_ops *lops; \ 2386 + guard(rwsem_read)(&(_card)->controls_rwsem); \ 2387 + guard(rwsem_read)(&snd_ctl_layer_rwsem); \ 2388 + for (lops = snd_ctl_layer; lops; lops = lops->next) \ 2389 + lops->_op(_card); \ 2390 + } while (0) 2391 + 2290 2392 /* 2291 2393 * registration of the control device 2292 2394 */ 2293 2395 static int snd_ctl_dev_register(struct snd_device *device) 2294 2396 { 2295 2397 struct snd_card *card = device->device_data; 2296 - struct snd_ctl_layer_ops *lops; 2297 2398 int err; 2298 2399 2299 2400 err = snd_register_device(SNDRV_DEVICE_TYPE_CONTROL, card, -1, 2300 2401 &snd_ctl_f_ops, card, card->ctl_dev); 2301 2402 if (err < 0) 2302 2403 return err; 2303 - down_read(&card->controls_rwsem); 2304 - down_read(&snd_ctl_layer_rwsem); 2305 - for (lops = snd_ctl_layer; lops; lops = lops->next) 2306 - lops->lregister(card); 2307 - up_read(&snd_ctl_layer_rwsem); 2308 - up_read(&card->controls_rwsem); 2404 + call_snd_ctl_lops(card, lregister); 2309 2405 return 0; 2310 2406 } 2311 2407 ··· 2320 2408 { 2321 2409 struct snd_card *card = device->device_data; 2322 2410 struct snd_ctl_file *ctl; 2323 - struct snd_ctl_layer_ops *lops; 2324 - unsigned long flags; 2325 2411 2326 - read_lock_irqsave(&card->ctl_files_rwlock, flags); 2327 - list_for_each_entry(ctl, &card->ctl_files, list) { 2328 - wake_up(&ctl->change_sleep); 2329 - snd_kill_fasync(ctl->fasync, SIGIO, POLL_ERR); 2412 + scoped_guard(read_lock_irqsave, &card->ctl_files_rwlock) { 2413 + list_for_each_entry(ctl, &card->ctl_files, list) { 2414 + wake_up(&ctl->change_sleep); 2415 + snd_kill_fasync(ctl->fasync, SIGIO, POLL_ERR); 2416 + } 2330 2417 } 2331 - read_unlock_irqrestore(&card->ctl_files_rwlock, flags); 2332 2418 2333 - down_read(&card->controls_rwsem); 2334 - down_read(&snd_ctl_layer_rwsem); 2335 - for (lops = snd_ctl_layer; lops; lops = lops->next) 2336 - lops->ldisconnect(card); 2337 - up_read(&snd_ctl_layer_rwsem); 2338 - up_read(&card->controls_rwsem); 2339 - 2419 + call_snd_ctl_lops(card, ldisconnect); 2340 2420 return snd_unregister_device(card->ctl_dev); 2341 2421 } 2342 2422 ··· 2340 2436 struct snd_card *card = device->device_data; 2341 2437 struct snd_kcontrol *control; 2342 2438 2343 - down_write(&card->controls_rwsem); 2344 - while (!list_empty(&card->controls)) { 2345 - control = snd_kcontrol(card->controls.next); 2346 - __snd_ctl_remove(card, control, false); 2347 - } 2439 + scoped_guard(rwsem_write, &card->controls_rwsem) { 2440 + while (!list_empty(&card->controls)) { 2441 + control = snd_kcontrol(card->controls.next); 2442 + __snd_ctl_remove(card, control, false); 2443 + } 2348 2444 2349 2445 #ifdef CONFIG_SND_CTL_FAST_LOOKUP 2350 - xa_destroy(&card->ctl_numids); 2351 - xa_destroy(&card->ctl_hash); 2446 + xa_destroy(&card->ctl_numids); 2447 + xa_destroy(&card->ctl_hash); 2352 2448 #endif 2353 - up_write(&card->controls_rwsem); 2449 + } 2354 2450 put_device(card->ctl_dev); 2355 2451 return 0; 2356 2452 }
+31 -56
sound/core/control_compat.c
··· 79 79 static int snd_ctl_elem_info_compat(struct snd_ctl_file *ctl, 80 80 struct snd_ctl_elem_info32 __user *data32) 81 81 { 82 - struct snd_ctl_elem_info *data; 82 + struct snd_ctl_elem_info *data __free(kfree) = NULL; 83 83 int err; 84 84 85 85 data = kzalloc(sizeof(*data), GFP_KERNEL); 86 86 if (! data) 87 87 return -ENOMEM; 88 88 89 - err = -EFAULT; 90 89 /* copy id */ 91 90 if (copy_from_user(&data->id, &data32->id, sizeof(data->id))) 92 - goto error; 91 + return -EFAULT; 93 92 /* we need to copy the item index. 94 93 * hope this doesn't break anything.. 95 94 */ 96 95 if (get_user(data->value.enumerated.item, &data32->value.enumerated.item)) 97 - goto error; 96 + return -EFAULT; 98 97 99 98 err = snd_ctl_elem_info(ctl, data); 100 99 if (err < 0) 101 - goto error; 100 + return err; 102 101 /* restore info to 32bit */ 103 - err = -EFAULT; 104 102 /* id, type, access, count */ 105 103 if (copy_to_user(&data32->id, &data->id, sizeof(data->id)) || 106 104 copy_to_user(&data32->type, &data->type, 3 * sizeof(u32))) 107 - goto error; 105 + return -EFAULT; 108 106 if (put_user(data->owner, &data32->owner)) 109 - goto error; 107 + return -EFAULT; 110 108 switch (data->type) { 111 109 case SNDRV_CTL_ELEM_TYPE_BOOLEAN: 112 110 case SNDRV_CTL_ELEM_TYPE_INTEGER: 113 111 if (put_user(data->value.integer.min, &data32->value.integer.min) || 114 112 put_user(data->value.integer.max, &data32->value.integer.max) || 115 113 put_user(data->value.integer.step, &data32->value.integer.step)) 116 - goto error; 114 + return -EFAULT; 117 115 break; 118 116 case SNDRV_CTL_ELEM_TYPE_INTEGER64: 119 117 if (copy_to_user(&data32->value.integer64, 120 118 &data->value.integer64, 121 119 sizeof(data->value.integer64))) 122 - goto error; 120 + return -EFAULT; 123 121 break; 124 122 case SNDRV_CTL_ELEM_TYPE_ENUMERATED: 125 123 if (copy_to_user(&data32->value.enumerated, 126 124 &data->value.enumerated, 127 125 sizeof(data->value.enumerated))) 128 - goto error; 126 + return -EFAULT; 129 127 break; 130 128 default: 131 129 break; 132 130 } 133 - err = 0; 134 - error: 135 - kfree(data); 136 - return err; 131 + return 0; 137 132 } 138 133 139 134 /* read / write */ ··· 164 169 int *countp) 165 170 { 166 171 struct snd_kcontrol *kctl; 167 - struct snd_ctl_elem_info *info; 172 + struct snd_ctl_elem_info *info __free(kfree) = NULL; 168 173 int err; 169 174 170 - down_read(&card->controls_rwsem); 175 + guard(rwsem_read)(&card->controls_rwsem); 171 176 kctl = snd_ctl_find_id_locked(card, id); 172 - if (! kctl) { 173 - up_read(&card->controls_rwsem); 177 + if (!kctl) 174 178 return -ENOENT; 175 - } 176 179 info = kzalloc(sizeof(*info), GFP_KERNEL); 177 - if (info == NULL) { 178 - up_read(&card->controls_rwsem); 180 + if (info == NULL) 179 181 return -ENOMEM; 180 - } 181 182 info->id = *id; 182 183 err = snd_power_ref_and_wait(card); 183 184 if (!err) 184 185 err = kctl->info(kctl, info); 185 186 snd_power_unref(card); 186 - up_read(&card->controls_rwsem); 187 187 if (err >= 0) { 188 188 err = info->type; 189 189 *countp = info->count; 190 190 } 191 - kfree(info); 192 191 return err; 193 192 } 194 193 ··· 278 289 static int ctl_elem_read_user(struct snd_card *card, 279 290 void __user *userdata, void __user *valuep) 280 291 { 281 - struct snd_ctl_elem_value *data; 292 + struct snd_ctl_elem_value *data __free(kfree) = NULL; 282 293 int err, type, count; 283 294 284 295 data = kzalloc(sizeof(*data), GFP_KERNEL); ··· 288 299 err = copy_ctl_value_from_user(card, data, userdata, valuep, 289 300 &type, &count); 290 301 if (err < 0) 291 - goto error; 302 + return err; 292 303 293 304 err = snd_ctl_elem_read(card, data); 294 305 if (err < 0) 295 - goto error; 296 - err = copy_ctl_value_to_user(userdata, valuep, data, type, count); 297 - error: 298 - kfree(data); 299 - return err; 306 + return err; 307 + return copy_ctl_value_to_user(userdata, valuep, data, type, count); 300 308 } 301 309 302 310 static int ctl_elem_write_user(struct snd_ctl_file *file, 303 311 void __user *userdata, void __user *valuep) 304 312 { 305 - struct snd_ctl_elem_value *data; 313 + struct snd_ctl_elem_value *data __free(kfree) = NULL; 306 314 struct snd_card *card = file->card; 307 315 int err, type, count; 308 316 ··· 310 324 err = copy_ctl_value_from_user(card, data, userdata, valuep, 311 325 &type, &count); 312 326 if (err < 0) 313 - goto error; 327 + return err; 314 328 315 329 err = snd_ctl_elem_write(card, file, data); 316 330 if (err < 0) 317 - goto error; 318 - err = copy_ctl_value_to_user(userdata, valuep, data, type, count); 319 - error: 320 - kfree(data); 321 - return err; 331 + return err; 332 + return copy_ctl_value_to_user(userdata, valuep, data, type, count); 322 333 } 323 334 324 335 static int snd_ctl_elem_read_user_compat(struct snd_card *card, ··· 349 366 struct snd_ctl_elem_info32 __user *data32, 350 367 int replace) 351 368 { 352 - struct snd_ctl_elem_info *data; 353 - int err; 369 + struct snd_ctl_elem_info *data __free(kfree) = NULL; 354 370 355 371 data = kzalloc(sizeof(*data), GFP_KERNEL); 356 372 if (! data) 357 373 return -ENOMEM; 358 374 359 - err = -EFAULT; 360 375 /* id, type, access, count */ \ 361 376 if (copy_from_user(&data->id, &data32->id, sizeof(data->id)) || 362 377 copy_from_user(&data->type, &data32->type, 3 * sizeof(u32))) 363 - goto error; 378 + return -EFAULT; 364 379 if (get_user(data->owner, &data32->owner)) 365 - goto error; 380 + return -EFAULT; 366 381 switch (data->type) { 367 382 case SNDRV_CTL_ELEM_TYPE_BOOLEAN: 368 383 case SNDRV_CTL_ELEM_TYPE_INTEGER: 369 384 if (get_user(data->value.integer.min, &data32->value.integer.min) || 370 385 get_user(data->value.integer.max, &data32->value.integer.max) || 371 386 get_user(data->value.integer.step, &data32->value.integer.step)) 372 - goto error; 387 + return -EFAULT; 373 388 break; 374 389 case SNDRV_CTL_ELEM_TYPE_INTEGER64: 375 390 if (copy_from_user(&data->value.integer64, 376 391 &data32->value.integer64, 377 392 sizeof(data->value.integer64))) 378 - goto error; 393 + return -EFAULT; 379 394 break; 380 395 case SNDRV_CTL_ELEM_TYPE_ENUMERATED: 381 396 if (copy_from_user(&data->value.enumerated, 382 397 &data32->value.enumerated, 383 398 sizeof(data->value.enumerated))) 384 - goto error; 399 + return -EFAULT; 385 400 data->value.enumerated.names_ptr = 386 401 (uintptr_t)compat_ptr(data->value.enumerated.names_ptr); 387 402 break; 388 403 default: 389 404 break; 390 405 } 391 - err = snd_ctl_elem_add(file, data, replace); 392 - error: 393 - kfree(data); 394 - return err; 406 + return snd_ctl_elem_add(file, data, replace); 395 407 } 396 408 397 409 enum { ··· 446 468 #endif /* CONFIG_X86_X32_ABI */ 447 469 } 448 470 449 - down_read(&snd_ioctl_rwsem); 471 + guard(rwsem_read)(&snd_ioctl_rwsem); 450 472 list_for_each_entry(p, &snd_control_compat_ioctls, list) { 451 473 if (p->fioctl) { 452 474 err = p->fioctl(ctl->card, ctl, cmd, arg); 453 - if (err != -ENOIOCTLCMD) { 454 - up_read(&snd_ioctl_rwsem); 475 + if (err != -ENOIOCTLCMD) 455 476 return err; 456 - } 457 477 } 458 478 } 459 - up_read(&snd_ioctl_rwsem); 460 479 return -ENOIOCTLCMD; 461 480 }
+65 -85
sound/core/control_led.c
··· 147 147 return; 148 148 route = -1; 149 149 found = false; 150 - mutex_lock(&snd_ctl_led_mutex); 151 - /* the card may not be registered (active) at this point */ 152 - if (card && !snd_ctl_led_card_valid[card->number]) { 153 - mutex_unlock(&snd_ctl_led_mutex); 154 - return; 155 - } 156 - list_for_each_entry(lctl, &led->controls, list) { 157 - if (lctl->kctl == kctl && lctl->index_offset == ioff) 158 - found = true; 159 - UPDATE_ROUTE(route, snd_ctl_led_get(lctl)); 160 - } 161 - if (!found && kctl && card) { 162 - lctl = kzalloc(sizeof(*lctl), GFP_KERNEL); 163 - if (lctl) { 164 - lctl->card = card; 165 - lctl->access = access; 166 - lctl->kctl = kctl; 167 - lctl->index_offset = ioff; 168 - list_add(&lctl->list, &led->controls); 150 + scoped_guard(mutex, &snd_ctl_led_mutex) { 151 + /* the card may not be registered (active) at this point */ 152 + if (card && !snd_ctl_led_card_valid[card->number]) 153 + return; 154 + list_for_each_entry(lctl, &led->controls, list) { 155 + if (lctl->kctl == kctl && lctl->index_offset == ioff) 156 + found = true; 169 157 UPDATE_ROUTE(route, snd_ctl_led_get(lctl)); 170 158 } 159 + if (!found && kctl && card) { 160 + lctl = kzalloc(sizeof(*lctl), GFP_KERNEL); 161 + if (lctl) { 162 + lctl->card = card; 163 + lctl->access = access; 164 + lctl->kctl = kctl; 165 + lctl->index_offset = ioff; 166 + list_add(&lctl->list, &led->controls); 167 + UPDATE_ROUTE(route, snd_ctl_led_get(lctl)); 168 + } 169 + } 171 170 } 172 - mutex_unlock(&snd_ctl_led_mutex); 173 171 switch (led->mode) { 174 172 case MODE_OFF: route = 1; break; 175 173 case MODE_ON: route = 0; break; ··· 199 201 struct snd_ctl_led_ctl *lctl; 200 202 unsigned int ret = 0; 201 203 202 - mutex_lock(&snd_ctl_led_mutex); 204 + guard(mutex)(&snd_ctl_led_mutex); 203 205 lctl = snd_ctl_led_find(kctl, ioff); 204 206 if (lctl && (access == 0 || access != lctl->access)) { 205 207 ret = lctl->access; 206 208 list_del(&lctl->list); 207 209 kfree(lctl); 208 210 } 209 - mutex_unlock(&snd_ctl_led_mutex); 210 211 return ret; 211 212 } 212 213 ··· 236 239 } 237 240 } 238 241 242 + DEFINE_FREE(snd_card_unref, struct snd_card *, if (_T) snd_card_unref(_T)) 243 + 239 244 static int snd_ctl_led_set_id(int card_number, struct snd_ctl_elem_id *id, 240 245 unsigned int group, bool set) 241 246 { 242 - struct snd_card *card; 247 + struct snd_card *card __free(snd_card_unref) = NULL; 243 248 struct snd_kcontrol *kctl; 244 249 struct snd_kcontrol_volatile *vd; 245 250 unsigned int ioff, access, new_access; 246 - int err = 0; 247 251 248 252 card = snd_card_ref(card_number); 249 - if (card) { 250 - down_write(&card->controls_rwsem); 251 - kctl = snd_ctl_find_id_locked(card, id); 252 - if (kctl) { 253 - ioff = snd_ctl_get_ioff(kctl, id); 254 - vd = &kctl->vd[ioff]; 255 - access = vd->access & SNDRV_CTL_ELEM_ACCESS_LED_MASK; 256 - if (access != 0 && access != group_to_access(group)) { 257 - err = -EXDEV; 258 - goto unlock; 259 - } 260 - new_access = vd->access & ~SNDRV_CTL_ELEM_ACCESS_LED_MASK; 261 - if (set) 262 - new_access |= group_to_access(group); 263 - if (new_access != vd->access) { 264 - vd->access = new_access; 265 - snd_ctl_led_notify(card, SNDRV_CTL_EVENT_MASK_INFO, kctl, ioff); 266 - } 267 - } else { 268 - err = -ENOENT; 269 - } 270 - unlock: 271 - up_write(&card->controls_rwsem); 272 - snd_card_unref(card); 273 - } else { 274 - err = -ENXIO; 253 + if (!card) 254 + return -ENXIO; 255 + guard(rwsem_write)(&card->controls_rwsem); 256 + kctl = snd_ctl_find_id_locked(card, id); 257 + if (!kctl) 258 + return -ENOENT; 259 + ioff = snd_ctl_get_ioff(kctl, id); 260 + vd = &kctl->vd[ioff]; 261 + access = vd->access & SNDRV_CTL_ELEM_ACCESS_LED_MASK; 262 + if (access != 0 && access != group_to_access(group)) 263 + return -EXDEV; 264 + new_access = vd->access & ~SNDRV_CTL_ELEM_ACCESS_LED_MASK; 265 + if (set) 266 + new_access |= group_to_access(group); 267 + if (new_access != vd->access) { 268 + vd->access = new_access; 269 + snd_ctl_led_notify(card, SNDRV_CTL_EVENT_MASK_INFO, kctl, ioff); 275 270 } 276 - return err; 271 + return 0; 277 272 } 278 273 279 274 static void snd_ctl_led_refresh(void) ··· 301 312 302 313 static int snd_ctl_led_reset(int card_number, unsigned int group) 303 314 { 304 - struct snd_card *card; 315 + struct snd_card *card __free(snd_card_unref) = NULL; 305 316 struct snd_ctl_led *led; 306 317 struct snd_ctl_led_ctl *lctl; 307 318 struct snd_kcontrol_volatile *vd; ··· 311 322 if (!card) 312 323 return -ENXIO; 313 324 314 - mutex_lock(&snd_ctl_led_mutex); 315 - if (!snd_ctl_led_card_valid[card_number]) { 316 - mutex_unlock(&snd_ctl_led_mutex); 317 - snd_card_unref(card); 318 - return -ENXIO; 319 - } 320 - led = &snd_ctl_leds[group]; 325 + scoped_guard(mutex, &snd_ctl_led_mutex) { 326 + if (!snd_ctl_led_card_valid[card_number]) 327 + return -ENXIO; 328 + led = &snd_ctl_leds[group]; 321 329 repeat: 322 - list_for_each_entry(lctl, &led->controls, list) 323 - if (lctl->card == card) { 324 - vd = &lctl->kctl->vd[lctl->index_offset]; 325 - vd->access &= ~group_to_access(group); 326 - snd_ctl_led_ctl_destroy(lctl); 327 - change = true; 328 - goto repeat; 329 - } 330 - mutex_unlock(&snd_ctl_led_mutex); 330 + list_for_each_entry(lctl, &led->controls, list) 331 + if (lctl->card == card) { 332 + vd = &lctl->kctl->vd[lctl->index_offset]; 333 + vd->access &= ~group_to_access(group); 334 + snd_ctl_led_ctl_destroy(lctl); 335 + change = true; 336 + goto repeat; 337 + } 338 + } 331 339 if (change) 332 340 snd_ctl_led_set_state(NULL, group_to_access(group), NULL, 0); 333 - snd_card_unref(card); 334 341 return 0; 335 342 } 336 343 ··· 338 353 if (snd_BUG_ON(card->number < 0 || 339 354 card->number >= ARRAY_SIZE(snd_ctl_led_card_valid))) 340 355 return; 341 - mutex_lock(&snd_ctl_led_mutex); 342 - snd_ctl_led_card_valid[card->number] = true; 343 - mutex_unlock(&snd_ctl_led_mutex); 356 + scoped_guard(mutex, &snd_ctl_led_mutex) 357 + snd_ctl_led_card_valid[card->number] = true; 344 358 /* the register callback is already called with held card->controls_rwsem */ 345 359 list_for_each_entry(kctl, &card->controls, list) 346 360 for (ioff = 0; ioff < kctl->count; ioff++) ··· 351 367 static void snd_ctl_led_disconnect(struct snd_card *card) 352 368 { 353 369 snd_ctl_led_sysfs_remove(card); 354 - mutex_lock(&snd_ctl_led_mutex); 355 - snd_ctl_led_card_valid[card->number] = false; 356 - snd_ctl_led_clean(card); 357 - mutex_unlock(&snd_ctl_led_mutex); 370 + scoped_guard(mutex, &snd_ctl_led_mutex) { 371 + snd_ctl_led_card_valid[card->number] = false; 372 + snd_ctl_led_clean(card); 373 + } 358 374 snd_ctl_led_refresh(); 359 375 } 360 376 ··· 414 430 else 415 431 return count; 416 432 417 - mutex_lock(&snd_ctl_led_mutex); 418 - led->mode = mode; 419 - mutex_unlock(&snd_ctl_led_mutex); 433 + scoped_guard(mutex, &snd_ctl_led_mutex) 434 + led->mode = mode; 420 435 421 436 snd_ctl_led_set_state(NULL, group_to_access(led->group), NULL, 0); 422 437 return count; ··· 598 615 struct device_attribute *attr, char *buf) 599 616 { 600 617 struct snd_ctl_led_card *led_card = container_of(dev, struct snd_ctl_led_card, dev); 601 - struct snd_card *card; 618 + struct snd_card *card __free(snd_card_unref) = NULL; 602 619 struct snd_ctl_led_ctl *lctl; 603 620 size_t l = 0; 604 621 605 622 card = snd_card_ref(led_card->number); 606 623 if (!card) 607 624 return -ENXIO; 608 - down_read(&card->controls_rwsem); 609 - mutex_lock(&snd_ctl_led_mutex); 625 + guard(rwsem_read)(&card->controls_rwsem); 626 + guard(mutex)(&snd_ctl_led_mutex); 610 627 if (snd_ctl_led_card_valid[led_card->number]) { 611 628 list_for_each_entry(lctl, &led_card->led->controls, list) { 612 629 if (lctl->card != card) ··· 617 634 lctl->kctl->id.numid + lctl->index_offset); 618 635 } 619 636 } 620 - mutex_unlock(&snd_ctl_led_mutex); 621 - up_read(&card->controls_rwsem); 622 - snd_card_unref(card); 623 637 return l; 624 638 } 625 639
+11 -13
sound/core/hrtimer.c
··· 35 35 unsigned long ticks; 36 36 enum hrtimer_restart ret = HRTIMER_NORESTART; 37 37 38 - spin_lock(&t->lock); 39 - if (!t->running) 40 - goto out; /* fast path */ 41 - stime->in_callback = true; 42 - ticks = t->sticks; 43 - spin_unlock(&t->lock); 38 + scoped_guard(spinlock, &t->lock) { 39 + if (!t->running) 40 + return HRTIMER_NORESTART; /* fast path */ 41 + stime->in_callback = true; 42 + ticks = t->sticks; 43 + } 44 44 45 45 /* calculate the drift */ 46 46 delta = ktime_sub(hrt->base->get_time(), hrtimer_get_expires(hrt)); ··· 49 49 50 50 snd_timer_interrupt(stime->timer, ticks); 51 51 52 - spin_lock(&t->lock); 52 + guard(spinlock)(&t->lock); 53 53 if (t->running) { 54 54 hrtimer_add_expires_ns(hrt, t->sticks * resolution); 55 55 ret = HRTIMER_RESTART; 56 56 } 57 57 58 58 stime->in_callback = false; 59 - out: 60 - spin_unlock(&t->lock); 61 59 return ret; 62 60 } 63 61 ··· 78 80 struct snd_hrtimer *stime = t->private_data; 79 81 80 82 if (stime) { 81 - spin_lock_irq(&t->lock); 82 - t->running = 0; /* just to be sure */ 83 - stime->in_callback = 1; /* skip start/stop */ 84 - spin_unlock_irq(&t->lock); 83 + scoped_guard(spinlock_irq, &t->lock) { 84 + t->running = 0; /* just to be sure */ 85 + stime->in_callback = 1; /* skip start/stop */ 86 + } 85 87 86 88 hrtimer_cancel(&stime->hrt); 87 89 kfree(stime);
+34 -44
sound/core/hwdep.c
··· 149 149 struct snd_hwdep *hw = file->private_data; 150 150 struct module *mod = hw->card->module; 151 151 152 - mutex_lock(&hw->open_mutex); 153 - if (hw->ops.release) 154 - err = hw->ops.release(hw, file); 155 - if (hw->used > 0) 156 - hw->used--; 157 - mutex_unlock(&hw->open_mutex); 152 + scoped_guard(mutex, &hw->open_mutex) { 153 + if (hw->ops.release) 154 + err = hw->ops.release(hw, file); 155 + if (hw->used > 0) 156 + hw->used--; 157 + } 158 158 wake_up(&hw->open_wait); 159 159 160 160 snd_card_file_remove(hw->card, file); ··· 272 272 273 273 if (get_user(device, (int __user *)arg)) 274 274 return -EFAULT; 275 - mutex_lock(&register_mutex); 276 275 277 - if (device < 0) 278 - device = 0; 279 - else if (device < SNDRV_MINOR_HWDEPS) 280 - device++; 281 - else 282 - device = SNDRV_MINOR_HWDEPS; 276 + scoped_guard(mutex, &register_mutex) { 277 + if (device < 0) 278 + device = 0; 279 + else if (device < SNDRV_MINOR_HWDEPS) 280 + device++; 281 + else 282 + device = SNDRV_MINOR_HWDEPS; 283 283 284 - while (device < SNDRV_MINOR_HWDEPS) { 285 - if (snd_hwdep_search(card, device)) 286 - break; 287 - device++; 284 + while (device < SNDRV_MINOR_HWDEPS) { 285 + if (snd_hwdep_search(card, device)) 286 + break; 287 + device++; 288 + } 289 + if (device >= SNDRV_MINOR_HWDEPS) 290 + device = -1; 288 291 } 289 - if (device >= SNDRV_MINOR_HWDEPS) 290 - device = -1; 291 - mutex_unlock(&register_mutex); 292 292 if (put_user(device, (int __user *)arg)) 293 293 return -EFAULT; 294 294 return 0; ··· 296 296 case SNDRV_CTL_IOCTL_HWDEP_INFO: 297 297 { 298 298 struct snd_hwdep_info __user *info = (struct snd_hwdep_info __user *)arg; 299 - int device, err; 299 + int device; 300 300 struct snd_hwdep *hwdep; 301 301 302 302 if (get_user(device, &info->device)) 303 303 return -EFAULT; 304 - mutex_lock(&register_mutex); 305 - hwdep = snd_hwdep_search(card, device); 306 - if (hwdep) 307 - err = snd_hwdep_info(hwdep, info); 308 - else 309 - err = -ENXIO; 310 - mutex_unlock(&register_mutex); 311 - return err; 304 + scoped_guard(mutex, &register_mutex) { 305 + hwdep = snd_hwdep_search(card, device); 306 + if (!hwdep) 307 + return -ENXIO; 308 + return snd_hwdep_info(hwdep, info); 309 + } 310 + break; 312 311 } 313 312 } 314 313 return -ENOIOCTLCMD; ··· 421 422 struct snd_card *card = hwdep->card; 422 423 int err; 423 424 424 - mutex_lock(&register_mutex); 425 - if (snd_hwdep_search(card, hwdep->device)) { 426 - mutex_unlock(&register_mutex); 425 + guard(mutex)(&register_mutex); 426 + if (snd_hwdep_search(card, hwdep->device)) 427 427 return -EBUSY; 428 - } 429 428 list_add_tail(&hwdep->list, &snd_hwdep_devices); 430 429 err = snd_register_device(SNDRV_DEVICE_TYPE_HWDEP, 431 430 hwdep->card, hwdep->device, ··· 431 434 if (err < 0) { 432 435 dev_err(hwdep->dev, "unable to register\n"); 433 436 list_del(&hwdep->list); 434 - mutex_unlock(&register_mutex); 435 437 return err; 436 438 } 437 439 ··· 450 454 hwdep->ossreg = 1; 451 455 } 452 456 #endif 453 - mutex_unlock(&register_mutex); 454 457 return 0; 455 458 } 456 459 ··· 459 464 460 465 if (snd_BUG_ON(!hwdep)) 461 466 return -ENXIO; 462 - mutex_lock(&register_mutex); 463 - if (snd_hwdep_search(hwdep->card, hwdep->device) != hwdep) { 464 - mutex_unlock(&register_mutex); 467 + guard(mutex)(&register_mutex); 468 + if (snd_hwdep_search(hwdep->card, hwdep->device) != hwdep) 465 469 return -EINVAL; 466 - } 467 - mutex_lock(&hwdep->open_mutex); 470 + guard(mutex)(&hwdep->open_mutex); 468 471 wake_up(&hwdep->open_wait); 469 472 #ifdef CONFIG_SND_OSSEMUL 470 473 if (hwdep->ossreg) ··· 470 477 #endif 471 478 snd_unregister_device(hwdep->dev); 472 479 list_del_init(&hwdep->list); 473 - mutex_unlock(&hwdep->open_mutex); 474 - mutex_unlock(&register_mutex); 475 480 return 0; 476 481 } 477 482 ··· 483 492 { 484 493 struct snd_hwdep *hwdep; 485 494 486 - mutex_lock(&register_mutex); 495 + guard(mutex)(&register_mutex); 487 496 list_for_each_entry(hwdep, &snd_hwdep_devices, list) 488 497 snd_iprintf(buffer, "%02i-%02i: %s\n", 489 498 hwdep->card->number, hwdep->device, hwdep->name); 490 - mutex_unlock(&register_mutex); 491 499 } 492 500 493 501 static struct snd_info_entry *snd_hwdep_proc_entry;
+30 -63
sound/core/info.c
··· 105 105 { 106 106 struct snd_info_private_data *data; 107 107 struct snd_info_entry *entry; 108 - loff_t ret = -EINVAL, size; 108 + loff_t size; 109 109 110 110 data = file->private_data; 111 111 entry = data->entry; 112 - mutex_lock(&entry->access); 113 - if (entry->c.ops->llseek) { 114 - ret = entry->c.ops->llseek(entry, 115 - data->file_private_data, 116 - file, offset, orig); 117 - goto out; 118 - } 112 + guard(mutex)(&entry->access); 113 + if (entry->c.ops->llseek) 114 + return entry->c.ops->llseek(entry, 115 + data->file_private_data, 116 + file, offset, orig); 119 117 120 118 size = entry->size; 121 119 switch (orig) { ··· 124 126 break; 125 127 case SEEK_END: 126 128 if (!size) 127 - goto out; 129 + return -EINVAL; 128 130 offset += size; 129 131 break; 130 132 default: 131 - goto out; 133 + return -EINVAL; 132 134 } 133 135 if (offset < 0) 134 - goto out; 136 + return -EINVAL; 135 137 if (size && offset > size) 136 138 offset = size; 137 139 file->f_pos = offset; 138 - ret = offset; 139 - out: 140 - mutex_unlock(&entry->access); 141 - return ret; 140 + return offset; 142 141 } 143 142 144 143 static ssize_t snd_info_entry_read(struct file *file, char __user *buffer, ··· 233 238 struct snd_info_private_data *data; 234 239 int mode, err; 235 240 236 - mutex_lock(&info_mutex); 241 + guard(mutex)(&info_mutex); 237 242 err = alloc_info_private(entry, &data); 238 243 if (err < 0) 239 - goto unlock; 244 + return err; 240 245 241 246 mode = file->f_flags & O_ACCMODE; 242 247 if (((mode == O_RDONLY || mode == O_RDWR) && !entry->c.ops->read) || ··· 252 257 } 253 258 254 259 file->private_data = data; 255 - mutex_unlock(&info_mutex); 256 260 return 0; 257 261 258 262 error: 259 263 kfree(data); 260 264 module_put(entry->module); 261 - unlock: 262 - mutex_unlock(&info_mutex); 263 265 return err; 264 266 } 265 267 ··· 298 306 struct snd_info_buffer *buf; 299 307 loff_t pos; 300 308 size_t next; 301 - int err = 0; 302 309 303 310 if (!entry->c.text.write) 304 311 return -EIO; ··· 308 317 /* don't handle too large text inputs */ 309 318 if (next > 16 * 1024) 310 319 return -EIO; 311 - mutex_lock(&entry->access); 320 + guard(mutex)(&entry->access); 312 321 buf = data->wbuffer; 313 322 if (!buf) { 314 323 data->wbuffer = buf = kzalloc(sizeof(*buf), GFP_KERNEL); 315 - if (!buf) { 316 - err = -ENOMEM; 317 - goto error; 318 - } 324 + if (!buf) 325 + return -ENOMEM; 319 326 } 320 327 if (next > buf->len) { 321 328 char *nbuf = kvzalloc(PAGE_ALIGN(next), GFP_KERNEL); 322 - if (!nbuf) { 323 - err = -ENOMEM; 324 - goto error; 325 - } 329 + if (!nbuf) 330 + return -ENOMEM; 326 331 kvfree(buf->buffer); 327 332 buf->buffer = nbuf; 328 333 buf->len = PAGE_ALIGN(next); 329 334 } 330 - if (copy_from_user(buf->buffer + pos, buffer, count)) { 331 - err = -EFAULT; 332 - goto error; 333 - } 335 + if (copy_from_user(buf->buffer + pos, buffer, count)) 336 + return -EFAULT; 334 337 buf->size = next; 335 - error: 336 - mutex_unlock(&entry->access); 337 - if (err < 0) 338 - return err; 339 338 *offset = next; 340 339 return count; 341 340 } ··· 350 369 struct snd_info_private_data *data; 351 370 int err; 352 371 353 - mutex_lock(&info_mutex); 372 + guard(mutex)(&info_mutex); 354 373 err = alloc_info_private(entry, &data); 355 374 if (err < 0) 356 - goto unlock; 375 + return err; 357 376 358 377 data->rbuffer = kzalloc(sizeof(*data->rbuffer), GFP_KERNEL); 359 378 if (!data->rbuffer) { ··· 367 386 err = single_open(file, snd_info_seq_show, data); 368 387 if (err < 0) 369 388 goto error; 370 - mutex_unlock(&info_mutex); 371 389 return 0; 372 390 373 391 error: 374 392 kfree(data->rbuffer); 375 393 kfree(data); 376 394 module_put(entry->module); 377 - unlock: 378 - mutex_unlock(&info_mutex); 379 395 return err; 380 396 } 381 397 ··· 527 549 */ 528 550 void snd_info_card_id_change(struct snd_card *card) 529 551 { 530 - mutex_lock(&info_mutex); 552 + guard(mutex)(&info_mutex); 531 553 if (card->proc_root_link) { 532 554 proc_remove(card->proc_root_link); 533 555 card->proc_root_link = NULL; ··· 536 558 card->proc_root_link = proc_symlink(card->id, 537 559 snd_proc_root->p, 538 560 card->proc_root->name); 539 - mutex_unlock(&info_mutex); 540 561 } 541 562 542 563 /* ··· 551 574 if (card->proc_root) 552 575 proc_remove(card->proc_root->p); 553 576 554 - mutex_lock(&info_mutex); 577 + guard(mutex)(&info_mutex); 555 578 if (card->proc_root) 556 579 snd_info_clear_entries(card->proc_root); 557 580 card->proc_root_link = NULL; 558 581 card->proc_root = NULL; 559 - mutex_unlock(&info_mutex); 560 582 } 561 583 562 584 /* ··· 679 703 entry->parent = parent; 680 704 entry->module = module; 681 705 if (parent) { 682 - mutex_lock(&parent->access); 706 + guard(mutex)(&parent->access); 683 707 list_add_tail(&entry->list, &parent->children); 684 - mutex_unlock(&parent->access); 685 708 } 686 709 return entry; 687 710 } ··· 750 775 return; 751 776 if (entry->p) { 752 777 proc_remove(entry->p); 753 - mutex_lock(&info_mutex); 778 + guard(mutex)(&info_mutex); 754 779 snd_info_clear_entries(entry); 755 - mutex_unlock(&info_mutex); 756 780 } 757 781 758 782 /* free all children at first */ ··· 760 786 761 787 p = entry->parent; 762 788 if (p) { 763 - mutex_lock(&p->access); 789 + guard(mutex)(&p->access); 764 790 list_del(&entry->list); 765 - mutex_unlock(&p->access); 766 791 } 767 792 kfree(entry->name); 768 793 if (entry->private_free) ··· 777 804 if (snd_BUG_ON(!entry)) 778 805 return -ENXIO; 779 806 root = entry->parent == NULL ? snd_proc_root->p : entry->parent->p; 780 - mutex_lock(&info_mutex); 807 + guard(mutex)(&info_mutex); 781 808 if (entry->p || !root) 782 - goto unlock; 809 + return 0; 783 810 if (S_ISDIR(entry->mode)) { 784 811 p = proc_mkdir_mode(entry->name, entry->mode, root); 785 - if (!p) { 786 - mutex_unlock(&info_mutex); 812 + if (!p) 787 813 return -ENOMEM; 788 - } 789 814 } else { 790 815 const struct proc_ops *ops; 791 816 if (entry->content == SNDRV_INFO_CONTENT_DATA) ··· 792 821 ops = &snd_info_text_entry_ops; 793 822 p = proc_create_data(entry->name, entry->mode, root, 794 823 ops, entry); 795 - if (!p) { 796 - mutex_unlock(&info_mutex); 824 + if (!p) 797 825 return -ENOMEM; 798 - } 799 826 proc_set_size(p, entry->size); 800 827 } 801 828 entry->p = p; 802 - unlock: 803 - mutex_unlock(&info_mutex); 804 829 return 0; 805 830 } 806 831
+3 -7
sound/core/info_oss.c
··· 29 29 return -ENXIO; 30 30 if (snd_BUG_ON(num < 0 || num >= SNDRV_CARDS)) 31 31 return -ENXIO; 32 - mutex_lock(&strings); 32 + guard(mutex)(&strings); 33 33 if (string == NULL) { 34 34 x = snd_sndstat_strings[num][dev]; 35 35 kfree(x); 36 36 x = NULL; 37 37 } else { 38 38 x = kstrdup(string, GFP_KERNEL); 39 - if (x == NULL) { 40 - mutex_unlock(&strings); 39 + if (x == NULL) 41 40 return -ENOMEM; 42 - } 43 41 } 44 42 snd_sndstat_strings[num][dev] = x; 45 - mutex_unlock(&strings); 46 43 return 0; 47 44 } 48 45 EXPORT_SYMBOL(snd_oss_info_register); ··· 50 53 char *str; 51 54 52 55 snd_iprintf(buf, "\n%s:", id); 53 - mutex_lock(&strings); 56 + guard(mutex)(&strings); 54 57 for (idx = 0; idx < SNDRV_CARDS; idx++) { 55 58 str = snd_sndstat_strings[idx][dev]; 56 59 if (str) { ··· 61 64 snd_iprintf(buf, "%i: %s\n", idx, str); 62 65 } 63 66 } 64 - mutex_unlock(&strings); 65 67 if (ok < 0) 66 68 snd_iprintf(buf, " NOT ENABLED IN CONFIG\n"); 67 69 return ok;
+91 -108
sound/core/init.c
··· 284 284 if (xid) 285 285 strscpy(card->id, xid, sizeof(card->id)); 286 286 err = 0; 287 - mutex_lock(&snd_card_mutex); 288 - if (idx < 0) /* first check the matching module-name slot */ 289 - idx = get_slot_from_bitmask(idx, module_slot_match, module); 290 - if (idx < 0) /* if not matched, assign an empty slot */ 291 - idx = get_slot_from_bitmask(idx, check_empty_slot, module); 292 - if (idx < 0) 293 - err = -ENODEV; 294 - else if (idx < snd_ecards_limit) { 295 - if (test_bit(idx, snd_cards_lock)) 296 - err = -EBUSY; /* invalid */ 297 - } else if (idx >= SNDRV_CARDS) 298 - err = -ENODEV; 287 + scoped_guard(mutex, &snd_card_mutex) { 288 + if (idx < 0) /* first check the matching module-name slot */ 289 + idx = get_slot_from_bitmask(idx, module_slot_match, module); 290 + if (idx < 0) /* if not matched, assign an empty slot */ 291 + idx = get_slot_from_bitmask(idx, check_empty_slot, module); 292 + if (idx < 0) 293 + err = -ENODEV; 294 + else if (idx < snd_ecards_limit) { 295 + if (test_bit(idx, snd_cards_lock)) 296 + err = -EBUSY; /* invalid */ 297 + } else if (idx >= SNDRV_CARDS) 298 + err = -ENODEV; 299 + if (!err) { 300 + set_bit(idx, snd_cards_lock); /* lock it */ 301 + if (idx >= snd_ecards_limit) 302 + snd_ecards_limit = idx + 1; /* increase the limit */ 303 + } 304 + } 299 305 if (err < 0) { 300 - mutex_unlock(&snd_card_mutex); 301 306 dev_err(parent, "cannot find the slot for index %d (range 0-%i), error: %d\n", 302 - idx, snd_ecards_limit - 1, err); 307 + idx, snd_ecards_limit - 1, err); 303 308 if (!card->managed) 304 309 kfree(card); /* manually free here, as no destructor called */ 305 310 return err; 306 311 } 307 - set_bit(idx, snd_cards_lock); /* lock it */ 308 - if (idx >= snd_ecards_limit) 309 - snd_ecards_limit = idx + 1; /* increase the limit */ 310 - mutex_unlock(&snd_card_mutex); 311 312 card->dev = parent; 312 313 card->number = idx; 313 314 #ifdef MODULE ··· 387 386 { 388 387 struct snd_card *card; 389 388 390 - mutex_lock(&snd_card_mutex); 389 + guard(mutex)(&snd_card_mutex); 391 390 card = snd_cards[idx]; 392 391 if (card) 393 392 get_device(&card->card_dev); 394 - mutex_unlock(&snd_card_mutex); 395 393 return card; 396 394 } 397 395 EXPORT_SYMBOL_GPL(snd_card_ref); ··· 398 398 /* return non-zero if a card is already locked */ 399 399 int snd_card_locked(int card) 400 400 { 401 - int locked; 402 - 403 - mutex_lock(&snd_card_mutex); 404 - locked = test_bit(card, snd_cards_lock); 405 - mutex_unlock(&snd_card_mutex); 406 - return locked; 401 + guard(mutex)(&snd_card_mutex); 402 + return test_bit(card, snd_cards_lock); 407 403 } 408 404 409 405 static loff_t snd_disconnect_llseek(struct file *file, loff_t offset, int orig) ··· 423 427 { 424 428 struct snd_monitor_file *df = NULL, *_df; 425 429 426 - spin_lock(&shutdown_lock); 427 - list_for_each_entry(_df, &shutdown_files, shutdown_list) { 428 - if (_df->file == file) { 429 - df = _df; 430 - list_del_init(&df->shutdown_list); 431 - break; 430 + scoped_guard(spinlock, &shutdown_lock) { 431 + list_for_each_entry(_df, &shutdown_files, shutdown_list) { 432 + if (_df->file == file) { 433 + df = _df; 434 + list_del_init(&df->shutdown_list); 435 + break; 436 + } 432 437 } 433 438 } 434 - spin_unlock(&shutdown_lock); 435 439 436 440 if (likely(df)) { 437 441 if ((file->f_flags & FASYNC) && df->disconnected_f_op->fasync) ··· 497 501 if (!card) 498 502 return; 499 503 500 - spin_lock(&card->files_lock); 501 - if (card->shutdown) { 502 - spin_unlock(&card->files_lock); 503 - return; 504 + scoped_guard(spinlock, &card->files_lock) { 505 + if (card->shutdown) 506 + return; 507 + card->shutdown = 1; 508 + 509 + /* replace file->f_op with special dummy operations */ 510 + list_for_each_entry(mfile, &card->files_list, list) { 511 + /* it's critical part, use endless loop */ 512 + /* we have no room to fail */ 513 + mfile->disconnected_f_op = mfile->file->f_op; 514 + 515 + scoped_guard(spinlock, &shutdown_lock) 516 + list_add(&mfile->shutdown_list, &shutdown_files); 517 + 518 + mfile->file->f_op = &snd_shutdown_f_ops; 519 + fops_get(mfile->file->f_op); 520 + } 504 521 } 505 - card->shutdown = 1; 506 - 507 - /* replace file->f_op with special dummy operations */ 508 - list_for_each_entry(mfile, &card->files_list, list) { 509 - /* it's critical part, use endless loop */ 510 - /* we have no room to fail */ 511 - mfile->disconnected_f_op = mfile->file->f_op; 512 - 513 - spin_lock(&shutdown_lock); 514 - list_add(&mfile->shutdown_list, &shutdown_files); 515 - spin_unlock(&shutdown_lock); 516 - 517 - mfile->file->f_op = &snd_shutdown_f_ops; 518 - fops_get(mfile->file->f_op); 519 - } 520 - spin_unlock(&card->files_lock); 521 522 522 523 /* notify all connected devices about disconnection */ 523 524 /* at this point, they cannot respond to any calls except release() */ ··· 537 544 } 538 545 539 546 /* disable fops (user space) operations for ALSA API */ 540 - mutex_lock(&snd_card_mutex); 541 - snd_cards[card->number] = NULL; 542 - clear_bit(card->number, snd_cards_lock); 543 - mutex_unlock(&snd_card_mutex); 547 + scoped_guard(mutex, &snd_card_mutex) { 548 + snd_cards[card->number] = NULL; 549 + clear_bit(card->number, snd_cards_lock); 550 + } 544 551 545 552 #ifdef CONFIG_PM 546 553 wake_up(&card->power_sleep); ··· 562 569 { 563 570 snd_card_disconnect(card); 564 571 565 - spin_lock_irq(&card->files_lock); 572 + guard(spinlock_irq)(&card->files_lock); 566 573 wait_event_lock_irq(card->remove_sleep, 567 574 list_empty(&card->files_list), 568 575 card->files_lock); 569 - spin_unlock_irq(&card->files_lock); 570 576 } 571 577 EXPORT_SYMBOL_GPL(snd_card_disconnect_sync); 572 578 ··· 759 767 /* check if user specified own card->id */ 760 768 if (card->id[0] != '\0') 761 769 return; 762 - mutex_lock(&snd_card_mutex); 770 + guard(mutex)(&snd_card_mutex); 763 771 snd_card_set_id_no_lock(card, nid, nid); 764 - mutex_unlock(&snd_card_mutex); 765 772 } 766 773 EXPORT_SYMBOL(snd_card_set_id); 767 774 ··· 788 797 } 789 798 memcpy(buf1, buf, copy); 790 799 buf1[copy] = '\0'; 791 - mutex_lock(&snd_card_mutex); 792 - if (!card_id_ok(NULL, buf1)) { 793 - mutex_unlock(&snd_card_mutex); 800 + guard(mutex)(&snd_card_mutex); 801 + if (!card_id_ok(NULL, buf1)) 794 802 return -EEXIST; 795 - } 796 803 strcpy(card->id, buf1); 797 804 snd_info_card_id_change(card); 798 - mutex_unlock(&snd_card_mutex); 799 805 800 806 return count; 801 807 } ··· 885 897 err = snd_device_register_all(card); 886 898 if (err < 0) 887 899 return err; 888 - mutex_lock(&snd_card_mutex); 889 - if (snd_cards[card->number]) { 890 - /* already registered */ 891 - mutex_unlock(&snd_card_mutex); 892 - return snd_info_card_register(card); /* register pending info */ 900 + scoped_guard(mutex, &snd_card_mutex) { 901 + if (snd_cards[card->number]) { 902 + /* already registered */ 903 + return snd_info_card_register(card); /* register pending info */ 904 + } 905 + if (*card->id) { 906 + /* make a unique id name from the given string */ 907 + char tmpid[sizeof(card->id)]; 908 + 909 + memcpy(tmpid, card->id, sizeof(card->id)); 910 + snd_card_set_id_no_lock(card, tmpid, tmpid); 911 + } else { 912 + /* create an id from either shortname or longname */ 913 + const char *src; 914 + 915 + src = *card->shortname ? card->shortname : card->longname; 916 + snd_card_set_id_no_lock(card, src, 917 + retrieve_id_from_card_name(src)); 918 + } 919 + snd_cards[card->number] = card; 893 920 } 894 - if (*card->id) { 895 - /* make a unique id name from the given string */ 896 - char tmpid[sizeof(card->id)]; 897 - memcpy(tmpid, card->id, sizeof(card->id)); 898 - snd_card_set_id_no_lock(card, tmpid, tmpid); 899 - } else { 900 - /* create an id from either shortname or longname */ 901 - const char *src; 902 - src = *card->shortname ? card->shortname : card->longname; 903 - snd_card_set_id_no_lock(card, src, 904 - retrieve_id_from_card_name(src)); 905 - } 906 - snd_cards[card->number] = card; 907 - mutex_unlock(&snd_card_mutex); 908 921 err = snd_info_card_register(card); 909 922 if (err < 0) 910 923 return err; ··· 926 937 struct snd_card *card; 927 938 928 939 for (idx = count = 0; idx < SNDRV_CARDS; idx++) { 929 - mutex_lock(&snd_card_mutex); 940 + guard(mutex)(&snd_card_mutex); 930 941 card = snd_cards[idx]; 931 942 if (card) { 932 943 count++; ··· 938 949 snd_iprintf(buffer, " %s\n", 939 950 card->longname); 940 951 } 941 - mutex_unlock(&snd_card_mutex); 942 952 } 943 953 if (!count) 944 954 snd_iprintf(buffer, "--- no soundcards ---\n"); ··· 950 962 struct snd_card *card; 951 963 952 964 for (idx = count = 0; idx < SNDRV_CARDS; idx++) { 953 - mutex_lock(&snd_card_mutex); 965 + guard(mutex)(&snd_card_mutex); 954 966 card = snd_cards[idx]; 955 967 if (card) { 956 968 count++; 957 969 snd_iprintf(buffer, "%s\n", card->longname); 958 970 } 959 - mutex_unlock(&snd_card_mutex); 960 971 } 961 972 if (!count) { 962 973 snd_iprintf(buffer, "--- no soundcards ---\n"); ··· 972 985 struct snd_card *card; 973 986 974 987 for (idx = 0; idx < SNDRV_CARDS; idx++) { 975 - mutex_lock(&snd_card_mutex); 988 + guard(mutex)(&snd_card_mutex); 976 989 card = snd_cards[idx]; 977 990 if (card) 978 991 snd_iprintf(buffer, "%2i %s\n", 979 992 idx, card->module->name); 980 - mutex_unlock(&snd_card_mutex); 981 993 } 982 994 } 983 995 #endif ··· 1058 1072 mfile->file = file; 1059 1073 mfile->disconnected_f_op = NULL; 1060 1074 INIT_LIST_HEAD(&mfile->shutdown_list); 1061 - spin_lock(&card->files_lock); 1075 + guard(spinlock)(&card->files_lock); 1062 1076 if (card->shutdown) { 1063 - spin_unlock(&card->files_lock); 1064 1077 kfree(mfile); 1065 1078 return -ENODEV; 1066 1079 } 1067 1080 list_add(&mfile->list, &card->files_list); 1068 1081 get_device(&card->card_dev); 1069 - spin_unlock(&card->files_lock); 1070 1082 return 0; 1071 1083 } 1072 1084 EXPORT_SYMBOL(snd_card_file_add); ··· 1086 1102 { 1087 1103 struct snd_monitor_file *mfile, *found = NULL; 1088 1104 1089 - spin_lock(&card->files_lock); 1090 - list_for_each_entry(mfile, &card->files_list, list) { 1091 - if (mfile->file == file) { 1092 - list_del(&mfile->list); 1093 - spin_lock(&shutdown_lock); 1094 - list_del(&mfile->shutdown_list); 1095 - spin_unlock(&shutdown_lock); 1096 - if (mfile->disconnected_f_op) 1097 - fops_put(mfile->disconnected_f_op); 1098 - found = mfile; 1099 - break; 1105 + scoped_guard(spinlock, &card->files_lock) { 1106 + list_for_each_entry(mfile, &card->files_list, list) { 1107 + if (mfile->file == file) { 1108 + list_del(&mfile->list); 1109 + scoped_guard(spinlock, &shutdown_lock) 1110 + list_del(&mfile->shutdown_list); 1111 + if (mfile->disconnected_f_op) 1112 + fops_put(mfile->disconnected_f_op); 1113 + found = mfile; 1114 + break; 1115 + } 1100 1116 } 1117 + if (list_empty(&card->files_list)) 1118 + wake_up_all(&card->remove_sleep); 1101 1119 } 1102 - if (list_empty(&card->files_list)) 1103 - wake_up_all(&card->remove_sleep); 1104 - spin_unlock(&card->files_lock); 1105 1120 if (!found) { 1106 1121 dev_err(card->dev, "card file remove problem (%p)\n", file); 1107 1122 return -ENOENT;
+7 -18
sound/core/jack.c
··· 42 42 #ifdef CONFIG_SND_JACK_INPUT_DEV 43 43 struct snd_jack *jack = device->device_data; 44 44 45 - mutex_lock(&jack->input_dev_lock); 46 - if (!jack->input_dev) { 47 - mutex_unlock(&jack->input_dev_lock); 45 + guard(mutex)(&jack->input_dev_lock); 46 + if (!jack->input_dev) 48 47 return 0; 49 - } 50 48 51 49 /* If the input device is registered with the input subsystem 52 50 * then we need to use a different deallocator. */ ··· 53 55 else 54 56 input_free_device(jack->input_dev); 55 57 jack->input_dev = NULL; 56 - mutex_unlock(&jack->input_dev_lock); 57 58 #endif /* CONFIG_SND_JACK_INPUT_DEV */ 58 59 return 0; 59 60 } ··· 89 92 snprintf(jack->name, sizeof(jack->name), "%s %s", 90 93 card->shortname, jack->id); 91 94 92 - mutex_lock(&jack->input_dev_lock); 93 - if (!jack->input_dev) { 94 - mutex_unlock(&jack->input_dev_lock); 95 + guard(mutex)(&jack->input_dev_lock); 96 + if (!jack->input_dev) 95 97 return 0; 96 - } 97 98 98 99 jack->input_dev->name = jack->name; 99 100 ··· 116 121 if (err == 0) 117 122 jack->registered = 1; 118 123 119 - mutex_unlock(&jack->input_dev_lock); 120 124 return err; 121 125 } 122 126 #endif /* CONFIG_SND_JACK_INPUT_DEV */ ··· 580 586 void snd_jack_set_parent(struct snd_jack *jack, struct device *parent) 581 587 { 582 588 WARN_ON(jack->registered); 583 - mutex_lock(&jack->input_dev_lock); 584 - if (!jack->input_dev) { 585 - mutex_unlock(&jack->input_dev_lock); 586 - return; 587 - } 588 - 589 - jack->input_dev->dev.parent = parent; 590 - mutex_unlock(&jack->input_dev_lock); 589 + guard(mutex)(&jack->input_dev_lock); 590 + if (jack->input_dev) 591 + jack->input_dev->dev.parent = parent; 591 592 } 592 593 EXPORT_SYMBOL(snd_jack_set_parent); 593 594
+104 -183
sound/core/oss/mixer_oss.c
··· 130 130 131 131 if (mixer == NULL) 132 132 return -EIO; 133 - mutex_lock(&mixer->reg_mutex); 133 + guard(mutex)(&mixer->reg_mutex); 134 134 for (chn = 0; chn < 31; chn++) { 135 135 pslot = &mixer->slots[chn]; 136 136 if (pslot->put_volume || pslot->put_recsrc) 137 137 result |= 1 << chn; 138 138 } 139 - mutex_unlock(&mixer->reg_mutex); 140 139 return result; 141 140 } 142 141 ··· 147 148 148 149 if (mixer == NULL) 149 150 return -EIO; 150 - mutex_lock(&mixer->reg_mutex); 151 + guard(mutex)(&mixer->reg_mutex); 151 152 for (chn = 0; chn < 31; chn++) { 152 153 pslot = &mixer->slots[chn]; 153 154 if (pslot->put_volume && pslot->stereo) 154 155 result |= 1 << chn; 155 156 } 156 - mutex_unlock(&mixer->reg_mutex); 157 157 return result; 158 158 } 159 159 ··· 163 165 164 166 if (mixer == NULL) 165 167 return -EIO; 166 - mutex_lock(&mixer->reg_mutex); 168 + guard(mutex)(&mixer->reg_mutex); 167 169 if (mixer->put_recsrc && mixer->get_recsrc) { /* exclusive */ 168 170 result = mixer->mask_recsrc; 169 171 } else { ··· 175 177 result |= 1 << chn; 176 178 } 177 179 } 178 - mutex_unlock(&mixer->reg_mutex); 179 180 return result; 180 181 } 181 182 ··· 185 188 186 189 if (mixer == NULL) 187 190 return -EIO; 188 - mutex_lock(&mixer->reg_mutex); 191 + guard(mutex)(&mixer->reg_mutex); 189 192 if (mixer->put_recsrc && mixer->get_recsrc) { /* exclusive */ 190 193 unsigned int index; 191 194 result = mixer->get_recsrc(fmixer, &index); 192 195 if (result < 0) 193 - goto unlock; 196 + return result; 194 197 result = 1 << index; 195 198 } else { 196 199 struct snd_mixer_oss_slot *pslot; ··· 206 209 } 207 210 } 208 211 mixer->oss_recsrc = result; 209 - unlock: 210 - mutex_unlock(&mixer->reg_mutex); 211 212 return result; 212 213 } 213 214 ··· 219 224 220 225 if (mixer == NULL) 221 226 return -EIO; 222 - mutex_lock(&mixer->reg_mutex); 227 + guard(mutex)(&mixer->reg_mutex); 223 228 if (mixer->get_recsrc && mixer->put_recsrc) { /* exclusive input */ 224 229 if (recsrc & ~mixer->oss_recsrc) 225 230 recsrc &= ~mixer->oss_recsrc; ··· 245 250 } 246 251 } 247 252 } 248 - mutex_unlock(&mixer->reg_mutex); 249 253 return result; 250 254 } 251 255 ··· 256 262 257 263 if (mixer == NULL || slot > 30) 258 264 return -EIO; 259 - mutex_lock(&mixer->reg_mutex); 265 + guard(mutex)(&mixer->reg_mutex); 260 266 pslot = &mixer->slots[slot]; 261 267 left = pslot->volume[0]; 262 268 right = pslot->volume[1]; ··· 264 270 result = pslot->get_volume(fmixer, pslot, &left, &right); 265 271 if (!pslot->stereo) 266 272 right = left; 267 - if (snd_BUG_ON(left < 0 || left > 100)) { 268 - result = -EIO; 269 - goto unlock; 270 - } 271 - if (snd_BUG_ON(right < 0 || right > 100)) { 272 - result = -EIO; 273 - goto unlock; 274 - } 273 + if (snd_BUG_ON(left < 0 || left > 100)) 274 + return -EIO; 275 + if (snd_BUG_ON(right < 0 || right > 100)) 276 + return -EIO; 275 277 if (result >= 0) { 276 278 pslot->volume[0] = left; 277 279 pslot->volume[1] = right; 278 280 result = (left & 0xff) | ((right & 0xff) << 8); 279 281 } 280 - unlock: 281 - mutex_unlock(&mixer->reg_mutex); 282 282 return result; 283 283 } 284 284 ··· 285 297 286 298 if (mixer == NULL || slot > 30) 287 299 return -EIO; 288 - mutex_lock(&mixer->reg_mutex); 300 + guard(mutex)(&mixer->reg_mutex); 289 301 pslot = &mixer->slots[slot]; 290 302 if (left > 100) 291 303 left = 100; ··· 296 308 if (pslot->put_volume) 297 309 result = pslot->put_volume(fmixer, pslot, left, right); 298 310 if (result < 0) 299 - goto unlock; 311 + return result; 300 312 pslot->volume[0] = left; 301 313 pslot->volume[1] = right; 302 314 result = (left & 0xff) | ((right & 0xff) << 8); 303 - unlock: 304 - mutex_unlock(&mixer->reg_mutex); 305 315 return result; 306 316 } 307 317 ··· 518 532 unsigned int numid, 519 533 int *left, int *right) 520 534 { 521 - struct snd_ctl_elem_info *uinfo; 522 - struct snd_ctl_elem_value *uctl; 535 + struct snd_ctl_elem_info *uinfo __free(kfree) = NULL; 536 + struct snd_ctl_elem_value *uctl __free(kfree) = NULL; 523 537 struct snd_kcontrol *kctl; 524 538 struct snd_card *card = fmixer->card; 525 539 526 540 if (numid == ID_UNKNOWN) 527 541 return; 528 - down_read(&card->controls_rwsem); 542 + guard(rwsem_read)(&card->controls_rwsem); 529 543 kctl = snd_ctl_find_numid_locked(card, numid); 530 - if (!kctl) { 531 - up_read(&card->controls_rwsem); 544 + if (!kctl) 532 545 return; 533 - } 534 546 uinfo = kzalloc(sizeof(*uinfo), GFP_KERNEL); 535 547 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL); 536 548 if (uinfo == NULL || uctl == NULL) 537 - goto __unalloc; 549 + return; 538 550 if (kctl->info(kctl, uinfo)) 539 - goto __unalloc; 551 + return; 540 552 if (kctl->get(kctl, uctl)) 541 - goto __unalloc; 553 + return; 542 554 if (uinfo->type == SNDRV_CTL_ELEM_TYPE_BOOLEAN && 543 555 uinfo->value.integer.min == 0 && uinfo->value.integer.max == 1) 544 - goto __unalloc; 556 + return; 545 557 *left = snd_mixer_oss_conv1(uctl->value.integer.value[0], uinfo->value.integer.min, uinfo->value.integer.max, &pslot->volume[0]); 546 558 if (uinfo->count > 1) 547 559 *right = snd_mixer_oss_conv1(uctl->value.integer.value[1], uinfo->value.integer.min, uinfo->value.integer.max, &pslot->volume[1]); 548 - __unalloc: 549 - up_read(&card->controls_rwsem); 550 - kfree(uctl); 551 - kfree(uinfo); 552 560 } 553 561 554 562 static void snd_mixer_oss_get_volume1_sw(struct snd_mixer_oss_file *fmixer, ··· 551 571 int *left, int *right, 552 572 int route) 553 573 { 554 - struct snd_ctl_elem_info *uinfo; 555 - struct snd_ctl_elem_value *uctl; 574 + struct snd_ctl_elem_info *uinfo __free(kfree) = NULL; 575 + struct snd_ctl_elem_value *uctl __free(kfree) = NULL; 556 576 struct snd_kcontrol *kctl; 557 577 struct snd_card *card = fmixer->card; 558 578 559 579 if (numid == ID_UNKNOWN) 560 580 return; 561 - down_read(&card->controls_rwsem); 581 + guard(rwsem_read)(&card->controls_rwsem); 562 582 kctl = snd_ctl_find_numid_locked(card, numid); 563 - if (!kctl) { 564 - up_read(&card->controls_rwsem); 583 + if (!kctl) 565 584 return; 566 - } 567 585 uinfo = kzalloc(sizeof(*uinfo), GFP_KERNEL); 568 586 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL); 569 587 if (uinfo == NULL || uctl == NULL) 570 - goto __unalloc; 588 + return; 571 589 if (kctl->info(kctl, uinfo)) 572 - goto __unalloc; 590 + return; 573 591 if (kctl->get(kctl, uctl)) 574 - goto __unalloc; 592 + return; 575 593 if (!uctl->value.integer.value[0]) { 576 594 *left = 0; 577 595 if (uinfo->count == 1) ··· 577 599 } 578 600 if (uinfo->count > 1 && !uctl->value.integer.value[route ? 3 : 1]) 579 601 *right = 0; 580 - __unalloc: 581 - up_read(&card->controls_rwsem); 582 - kfree(uctl); 583 - kfree(uinfo); 584 602 } 585 603 586 604 static int snd_mixer_oss_get_volume1(struct snd_mixer_oss_file *fmixer, ··· 610 636 unsigned int numid, 611 637 int left, int right) 612 638 { 613 - struct snd_ctl_elem_info *uinfo; 614 - struct snd_ctl_elem_value *uctl; 639 + struct snd_ctl_elem_info *uinfo __free(kfree) = NULL; 640 + struct snd_ctl_elem_value *uctl __free(kfree) = NULL; 615 641 struct snd_kcontrol *kctl; 616 642 struct snd_card *card = fmixer->card; 617 643 int res; 618 644 619 645 if (numid == ID_UNKNOWN) 620 646 return; 621 - down_read(&card->controls_rwsem); 647 + guard(rwsem_read)(&card->controls_rwsem); 622 648 kctl = snd_ctl_find_numid_locked(card, numid); 623 - if (!kctl) { 624 - up_read(&card->controls_rwsem); 649 + if (!kctl) 625 650 return; 626 - } 627 651 uinfo = kzalloc(sizeof(*uinfo), GFP_KERNEL); 628 652 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL); 629 653 if (uinfo == NULL || uctl == NULL) 630 - goto __unalloc; 654 + return; 631 655 if (kctl->info(kctl, uinfo)) 632 - goto __unalloc; 656 + return; 633 657 if (uinfo->type == SNDRV_CTL_ELEM_TYPE_BOOLEAN && 634 658 uinfo->value.integer.min == 0 && uinfo->value.integer.max == 1) 635 - goto __unalloc; 659 + return; 636 660 uctl->value.integer.value[0] = snd_mixer_oss_conv2(left, uinfo->value.integer.min, uinfo->value.integer.max); 637 661 if (uinfo->count > 1) 638 662 uctl->value.integer.value[1] = snd_mixer_oss_conv2(right, uinfo->value.integer.min, uinfo->value.integer.max); 639 663 res = kctl->put(kctl, uctl); 640 664 if (res < 0) 641 - goto __unalloc; 665 + return; 642 666 if (res > 0) 643 667 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id); 644 - __unalloc: 645 - up_read(&card->controls_rwsem); 646 - kfree(uctl); 647 - kfree(uinfo); 648 668 } 649 669 650 670 static void snd_mixer_oss_put_volume1_sw(struct snd_mixer_oss_file *fmixer, ··· 647 679 int left, int right, 648 680 int route) 649 681 { 650 - struct snd_ctl_elem_info *uinfo; 651 - struct snd_ctl_elem_value *uctl; 682 + struct snd_ctl_elem_info *uinfo __free(kfree) = NULL; 683 + struct snd_ctl_elem_value *uctl __free(kfree) = NULL; 652 684 struct snd_kcontrol *kctl; 653 685 struct snd_card *card = fmixer->card; 654 686 int res; 655 687 656 688 if (numid == ID_UNKNOWN) 657 689 return; 658 - down_read(&card->controls_rwsem); 690 + guard(rwsem_read)(&card->controls_rwsem); 659 691 kctl = snd_ctl_find_numid_locked(card, numid); 660 - if (!kctl) { 661 - up_read(&card->controls_rwsem); 692 + if (!kctl) 662 693 return; 663 - } 664 694 uinfo = kzalloc(sizeof(*uinfo), GFP_KERNEL); 665 695 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL); 666 696 if (uinfo == NULL || uctl == NULL) 667 - goto __unalloc; 697 + return; 668 698 if (kctl->info(kctl, uinfo)) 669 - goto __unalloc; 699 + return; 670 700 if (uinfo->count > 1) { 671 701 uctl->value.integer.value[0] = left > 0 ? 1 : 0; 672 702 uctl->value.integer.value[route ? 3 : 1] = right > 0 ? 1 : 0; ··· 677 711 } 678 712 res = kctl->put(kctl, uctl); 679 713 if (res < 0) 680 - goto __unalloc; 714 + return; 681 715 if (res > 0) 682 716 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id); 683 - __unalloc: 684 - up_read(&card->controls_rwsem); 685 - kfree(uctl); 686 - kfree(uinfo); 687 717 } 688 718 689 719 static int snd_mixer_oss_put_volume1(struct snd_mixer_oss_file *fmixer, ··· 784 822 struct snd_kcontrol *kctl; 785 823 struct snd_mixer_oss_slot *pslot; 786 824 struct slot *slot; 787 - struct snd_ctl_elem_info *uinfo; 788 - struct snd_ctl_elem_value *uctl; 825 + struct snd_ctl_elem_info *uinfo __free(kfree) = NULL; 826 + struct snd_ctl_elem_value *uctl __free(kfree) = NULL; 789 827 int err, idx; 790 828 791 829 uinfo = kzalloc(sizeof(*uinfo), GFP_KERNEL); 792 830 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL); 793 - if (uinfo == NULL || uctl == NULL) { 794 - err = -ENOMEM; 795 - goto __free_only; 796 - } 797 - down_read(&card->controls_rwsem); 831 + if (uinfo == NULL || uctl == NULL) 832 + return -ENOMEM; 833 + guard(rwsem_read)(&card->controls_rwsem); 798 834 kctl = snd_mixer_oss_test_id(mixer, "Capture Source", 0); 799 - if (! kctl) { 800 - err = -ENOENT; 801 - goto __unlock; 802 - } 835 + if (!kctl) 836 + return -ENOENT; 803 837 err = kctl->info(kctl, uinfo); 804 838 if (err < 0) 805 - goto __unlock; 839 + return err; 806 840 err = kctl->get(kctl, uctl); 807 841 if (err < 0) 808 - goto __unlock; 842 + return err; 809 843 for (idx = 0; idx < 32; idx++) { 810 844 if (!(mixer->mask_recsrc & (1 << idx))) 811 845 continue; ··· 816 858 break; 817 859 } 818 860 } 819 - err = 0; 820 - __unlock: 821 - up_read(&card->controls_rwsem); 822 - __free_only: 823 - kfree(uctl); 824 - kfree(uinfo); 825 - return err; 861 + return 0; 826 862 } 827 863 828 864 static int snd_mixer_oss_put_recsrc2(struct snd_mixer_oss_file *fmixer, unsigned int active_index) ··· 826 874 struct snd_kcontrol *kctl; 827 875 struct snd_mixer_oss_slot *pslot; 828 876 struct slot *slot = NULL; 829 - struct snd_ctl_elem_info *uinfo; 830 - struct snd_ctl_elem_value *uctl; 877 + struct snd_ctl_elem_info *uinfo __free(kfree) = NULL; 878 + struct snd_ctl_elem_value *uctl __free(kfree) = NULL; 831 879 int err; 832 880 unsigned int idx; 833 881 834 882 uinfo = kzalloc(sizeof(*uinfo), GFP_KERNEL); 835 883 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL); 836 - if (uinfo == NULL || uctl == NULL) { 837 - err = -ENOMEM; 838 - goto __free_only; 839 - } 840 - down_read(&card->controls_rwsem); 884 + if (uinfo == NULL || uctl == NULL) 885 + return -ENOMEM; 886 + guard(rwsem_read)(&card->controls_rwsem); 841 887 kctl = snd_mixer_oss_test_id(mixer, "Capture Source", 0); 842 - if (! kctl) { 843 - err = -ENOENT; 844 - goto __unlock; 845 - } 888 + if (!kctl) 889 + return -ENOENT; 846 890 err = kctl->info(kctl, uinfo); 847 891 if (err < 0) 848 - goto __unlock; 892 + return err; 849 893 for (idx = 0; idx < 32; idx++) { 850 894 if (!(mixer->mask_recsrc & (1 << idx))) 851 895 continue; ··· 855 907 break; 856 908 slot = NULL; 857 909 } 858 - if (! slot) 859 - goto __unlock; 910 + if (!slot) 911 + return 0; 860 912 for (idx = 0; idx < uinfo->count; idx++) 861 913 uctl->value.enumerated.item[idx] = slot->capture_item; 862 914 err = kctl->put(kctl, uctl); 863 915 if (err > 0) 864 916 snd_ctl_notify(fmixer->card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id); 865 - err = 0; 866 - __unlock: 867 - up_read(&card->controls_rwsem); 868 - __free_only: 869 - kfree(uctl); 870 - kfree(uinfo); 871 - return err; 917 + return 0; 872 918 } 873 919 874 920 struct snd_mixer_oss_assign_table { ··· 873 931 874 932 static int snd_mixer_oss_build_test(struct snd_mixer_oss *mixer, struct slot *slot, const char *name, int index, int item) 875 933 { 876 - struct snd_ctl_elem_info *info; 934 + struct snd_ctl_elem_info *info __free(kfree) = NULL; 877 935 struct snd_kcontrol *kcontrol; 878 936 struct snd_card *card = mixer->card; 879 937 int err; 880 938 881 - down_read(&card->controls_rwsem); 882 - kcontrol = snd_mixer_oss_test_id(mixer, name, index); 883 - if (kcontrol == NULL) { 884 - up_read(&card->controls_rwsem); 885 - return 0; 939 + scoped_guard(rwsem_read, &card->controls_rwsem) { 940 + kcontrol = snd_mixer_oss_test_id(mixer, name, index); 941 + if (kcontrol == NULL) 942 + return 0; 943 + info = kmalloc(sizeof(*info), GFP_KERNEL); 944 + if (!info) 945 + return -ENOMEM; 946 + err = kcontrol->info(kcontrol, info); 947 + if (err < 0) 948 + return err; 949 + slot->numid[item] = kcontrol->id.numid; 886 950 } 887 - info = kmalloc(sizeof(*info), GFP_KERNEL); 888 - if (! info) { 889 - up_read(&card->controls_rwsem); 890 - return -ENOMEM; 891 - } 892 - err = kcontrol->info(kcontrol, info); 893 - if (err < 0) { 894 - up_read(&card->controls_rwsem); 895 - kfree(info); 896 - return err; 897 - } 898 - slot->numid[item] = kcontrol->id.numid; 899 - up_read(&card->controls_rwsem); 900 951 if (info->count > slot->channels) 901 952 slot->channels = info->count; 902 953 slot->present |= 1 << item; 903 - kfree(info); 904 954 return 0; 905 955 } 906 956 ··· 1002 1068 memset(slot.numid, 0xff, sizeof(slot.numid)); /* ID_UNKNOWN */ 1003 1069 if (snd_mixer_oss_build_test_all(mixer, ptr, &slot)) 1004 1070 return 0; 1005 - down_read(&mixer->card->controls_rwsem); 1071 + guard(rwsem_read)(&mixer->card->controls_rwsem); 1006 1072 kctl = NULL; 1007 1073 if (!ptr->index) 1008 1074 kctl = snd_mixer_oss_test_id(mixer, "Capture Source", 0); 1009 1075 if (kctl) { 1010 - struct snd_ctl_elem_info *uinfo; 1076 + struct snd_ctl_elem_info *uinfo __free(kfree) = NULL; 1011 1077 1012 1078 uinfo = kzalloc(sizeof(*uinfo), GFP_KERNEL); 1013 - if (! uinfo) { 1014 - up_read(&mixer->card->controls_rwsem); 1079 + if (!uinfo) 1015 1080 return -ENOMEM; 1016 - } 1017 1081 1018 - if (kctl->info(kctl, uinfo)) { 1019 - up_read(&mixer->card->controls_rwsem); 1020 - kfree(uinfo); 1082 + if (kctl->info(kctl, uinfo)) 1021 1083 return 0; 1022 - } 1023 1084 strcpy(str, ptr->name); 1024 1085 if (!strcmp(str, "Master")) 1025 1086 strcpy(str, "Mix"); ··· 1026 1097 } else { 1027 1098 for (slot.capture_item = 1; slot.capture_item < uinfo->value.enumerated.items; slot.capture_item++) { 1028 1099 uinfo->value.enumerated.item = slot.capture_item; 1029 - if (kctl->info(kctl, uinfo)) { 1030 - up_read(&mixer->card->controls_rwsem); 1031 - kfree(uinfo); 1100 + if (kctl->info(kctl, uinfo)) 1032 1101 return 0; 1033 - } 1034 1102 if (!strcmp(uinfo->value.enumerated.name, str)) { 1035 1103 slot.present |= SNDRV_MIXER_OSS_PRESENT_CAPTURE; 1036 1104 break; 1037 1105 } 1038 1106 } 1039 1107 } 1040 - kfree(uinfo); 1041 1108 } 1042 - up_read(&mixer->card->controls_rwsem); 1043 1109 if (slot.present != 0) { 1044 1110 pslot = kmalloc(sizeof(slot), GFP_KERNEL); 1045 1111 if (! pslot) ··· 1107 1183 struct snd_mixer_oss *mixer = entry->private_data; 1108 1184 int i; 1109 1185 1110 - mutex_lock(&mixer->reg_mutex); 1186 + guard(mutex)(&mixer->reg_mutex); 1111 1187 for (i = 0; i < SNDRV_OSS_MAX_MIXERS; i++) { 1112 1188 struct slot *p; 1113 1189 ··· 1122 1198 else 1123 1199 snd_iprintf(buffer, "\"\" 0\n"); 1124 1200 } 1125 - mutex_unlock(&mixer->reg_mutex); 1126 1201 } 1127 1202 1128 1203 static void snd_mixer_oss_proc_write(struct snd_info_entry *entry, ··· 1148 1225 cptr = snd_info_get_str(str, cptr, sizeof(str)); 1149 1226 if (! *str) { 1150 1227 /* remove the entry */ 1151 - mutex_lock(&mixer->reg_mutex); 1152 - mixer_slot_clear(&mixer->slots[ch]); 1153 - mutex_unlock(&mixer->reg_mutex); 1228 + scoped_guard(mutex, &mixer->reg_mutex) 1229 + mixer_slot_clear(&mixer->slots[ch]); 1154 1230 continue; 1155 1231 } 1156 1232 snd_info_get_str(idxstr, cptr, sizeof(idxstr)); ··· 1158 1236 pr_err("ALSA: mixer_oss: invalid index %d\n", idx); 1159 1237 continue; 1160 1238 } 1161 - mutex_lock(&mixer->reg_mutex); 1162 - slot = (struct slot *)mixer->slots[ch].private_data; 1163 - if (slot && slot->assigned && 1164 - slot->assigned->index == idx && ! strcmp(slot->assigned->name, str)) 1165 - /* not changed */ 1166 - goto __unlock; 1167 - tbl = kmalloc(sizeof(*tbl), GFP_KERNEL); 1168 - if (!tbl) 1169 - goto __unlock; 1170 - tbl->oss_id = ch; 1171 - tbl->name = kstrdup(str, GFP_KERNEL); 1172 - if (! tbl->name) { 1173 - kfree(tbl); 1174 - goto __unlock; 1239 + scoped_guard(mutex, &mixer->reg_mutex) { 1240 + slot = (struct slot *)mixer->slots[ch].private_data; 1241 + if (slot && slot->assigned && 1242 + slot->assigned->index == idx && !strcmp(slot->assigned->name, str)) 1243 + /* not changed */ 1244 + break; 1245 + tbl = kmalloc(sizeof(*tbl), GFP_KERNEL); 1246 + if (!tbl) 1247 + break; 1248 + tbl->oss_id = ch; 1249 + tbl->name = kstrdup(str, GFP_KERNEL); 1250 + if (!tbl->name) { 1251 + kfree(tbl); 1252 + break; 1253 + } 1254 + tbl->index = idx; 1255 + if (snd_mixer_oss_build_input(mixer, tbl, 1, 1) <= 0) { 1256 + kfree(tbl->name); 1257 + kfree(tbl); 1258 + } 1175 1259 } 1176 - tbl->index = idx; 1177 - if (snd_mixer_oss_build_input(mixer, tbl, 1, 1) <= 0) { 1178 - kfree(tbl->name); 1179 - kfree(tbl); 1180 - } 1181 - __unlock: 1182 - mutex_unlock(&mixer->reg_mutex); 1183 1260 } 1184 1261 } 1185 1262
+27 -47
sound/core/oss/pcm_oss.c
··· 377 377 snd_pcm_hw_param_t var, unsigned int best, 378 378 int *dir) 379 379 { 380 - struct snd_pcm_hw_params *save = NULL; 380 + struct snd_pcm_hw_params *save __free(kfree) = NULL; 381 381 int v; 382 382 unsigned int saved_min; 383 383 int last = 0; ··· 404 404 saved_min = min; 405 405 min = snd_pcm_hw_param_min(pcm, params, var, min, &mindir); 406 406 if (min >= 0) { 407 - struct snd_pcm_hw_params *params1; 407 + struct snd_pcm_hw_params *params1 __free(kfree) = NULL; 408 408 if (max < 0) 409 409 goto _end; 410 410 if ((unsigned int)min == saved_min && mindir == valdir) 411 411 goto _end; 412 412 params1 = kmalloc(sizeof(*params1), GFP_KERNEL); 413 - if (params1 == NULL) { 414 - kfree(save); 413 + if (params1 == NULL) 415 414 return -ENOMEM; 416 - } 417 415 *params1 = *save; 418 416 max = snd_pcm_hw_param_max(pcm, params1, var, max, &maxdir); 419 - if (max < 0) { 420 - kfree(params1); 417 + if (max < 0) 421 418 goto _end; 422 - } 423 419 if (boundary_nearer(max, maxdir, best, valdir, min, mindir)) { 424 420 *params = *params1; 425 421 last = 1; 426 422 } 427 - kfree(params1); 428 423 } else { 429 424 *params = *save; 430 425 max = snd_pcm_hw_param_max(pcm, params, var, max, &maxdir); 431 - if (max < 0) { 432 - kfree(save); 426 + if (max < 0) 433 427 return max; 434 - } 435 428 last = 1; 436 429 } 437 430 _end: 438 - kfree(save); 439 431 if (last) 440 432 v = snd_pcm_hw_param_last(pcm, params, var, dir); 441 433 else ··· 781 789 struct snd_pcm_hw_params *params, unsigned int best_rate) 782 790 { 783 791 const struct snd_interval *it; 784 - struct snd_pcm_hw_params *save; 792 + struct snd_pcm_hw_params *save __free(kfree) = NULL; 785 793 unsigned int rate, prev; 786 794 787 795 save = kmalloc(sizeof(*save), GFP_KERNEL); ··· 800 808 ret = snd_pcm_hw_param_set(substream, params, 801 809 SNDRV_PCM_HW_PARAM_RATE, 802 810 rate, 0); 803 - if (ret == (int)rate) { 804 - kfree(save); 811 + if (ret == (int)rate) 805 812 return rate; 806 - } 807 813 *params = *save; 808 814 } 809 815 prev = rate; ··· 811 821 } 812 822 813 823 /* not found, use the nearest rate */ 814 - kfree(save); 815 824 return snd_pcm_hw_param_near(substream, params, SNDRV_PCM_HW_PARAM_RATE, best_rate, NULL); 816 825 } 817 826 ··· 1623 1634 break; 1624 1635 result = 0; 1625 1636 set_current_state(TASK_INTERRUPTIBLE); 1626 - snd_pcm_stream_lock_irq(substream); 1627 - state = runtime->state; 1628 - snd_pcm_stream_unlock_irq(substream); 1637 + scoped_guard(pcm_stream_lock_irq, substream) 1638 + state = runtime->state; 1629 1639 if (state != SNDRV_PCM_STATE_RUNNING) { 1630 1640 set_current_state(TASK_RUNNING); 1631 1641 break; ··· 1835 1847 struct snd_pcm_substream *substream; 1836 1848 int err; 1837 1849 int direct; 1838 - struct snd_pcm_hw_params *params; 1850 + struct snd_pcm_hw_params *params __free(kfree) = NULL; 1839 1851 unsigned int formats = 0; 1840 1852 const struct snd_mask *format_mask; 1841 1853 int fmt; ··· 1861 1873 _snd_pcm_hw_params_any(params); 1862 1874 err = snd_pcm_hw_refine(substream, params); 1863 1875 if (err < 0) 1864 - goto error; 1876 + return err; 1865 1877 format_mask = hw_param_mask_c(params, SNDRV_PCM_HW_PARAM_FORMAT); 1866 1878 for (fmt = 0; fmt < 32; ++fmt) { 1867 1879 if (snd_mask_test(format_mask, fmt)) { ··· 1871 1883 } 1872 1884 } 1873 1885 1874 - error: 1875 - kfree(params); 1876 - return err < 0 ? err : formats; 1886 + return formats; 1877 1887 } 1878 1888 1879 1889 static int snd_pcm_oss_set_format(struct snd_pcm_oss_file *pcm_oss_file, int format) ··· 2333 2347 { 2334 2348 struct snd_pcm_oss_setup *setup; 2335 2349 2336 - mutex_lock(&pcm->streams[stream].oss.setup_mutex); 2350 + guard(mutex)(&pcm->streams[stream].oss.setup_mutex); 2337 2351 do { 2338 2352 for (setup = pcm->streams[stream].oss.setup_list; setup; 2339 2353 setup = setup->next) { ··· 2344 2358 out: 2345 2359 if (setup) 2346 2360 *rsetup = *setup; 2347 - mutex_unlock(&pcm->streams[stream].oss.setup_mutex); 2348 2361 } 2349 2362 2350 2363 static void snd_pcm_oss_release_substream(struct snd_pcm_substream *substream) ··· 2838 2853 if (psubstream != NULL) { 2839 2854 struct snd_pcm_runtime *runtime = psubstream->runtime; 2840 2855 poll_wait(file, &runtime->sleep, wait); 2841 - snd_pcm_stream_lock_irq(psubstream); 2842 - if (runtime->state != SNDRV_PCM_STATE_DRAINING && 2843 - (runtime->state != SNDRV_PCM_STATE_RUNNING || 2844 - snd_pcm_oss_playback_ready(psubstream))) 2845 - mask |= EPOLLOUT | EPOLLWRNORM; 2846 - snd_pcm_stream_unlock_irq(psubstream); 2856 + scoped_guard(pcm_stream_lock_irq, psubstream) { 2857 + if (runtime->state != SNDRV_PCM_STATE_DRAINING && 2858 + (runtime->state != SNDRV_PCM_STATE_RUNNING || 2859 + snd_pcm_oss_playback_ready(psubstream))) 2860 + mask |= EPOLLOUT | EPOLLWRNORM; 2861 + } 2847 2862 } 2848 2863 if (csubstream != NULL) { 2849 2864 struct snd_pcm_runtime *runtime = csubstream->runtime; 2850 2865 snd_pcm_state_t ostate; 2851 2866 poll_wait(file, &runtime->sleep, wait); 2852 - snd_pcm_stream_lock_irq(csubstream); 2853 - ostate = runtime->state; 2854 - if (ostate != SNDRV_PCM_STATE_RUNNING || 2855 - snd_pcm_oss_capture_ready(csubstream)) 2856 - mask |= EPOLLIN | EPOLLRDNORM; 2857 - snd_pcm_stream_unlock_irq(csubstream); 2867 + scoped_guard(pcm_stream_lock_irq, csubstream) { 2868 + ostate = runtime->state; 2869 + if (ostate != SNDRV_PCM_STATE_RUNNING || 2870 + snd_pcm_oss_capture_ready(csubstream)) 2871 + mask |= EPOLLIN | EPOLLRDNORM; 2872 + } 2858 2873 if (ostate != SNDRV_PCM_STATE_RUNNING && runtime->oss.trigger) { 2859 2874 struct snd_pcm_oss_file ofile; 2860 2875 memset(&ofile, 0, sizeof(ofile)); ··· 2949 2964 { 2950 2965 struct snd_pcm_str *pstr = entry->private_data; 2951 2966 struct snd_pcm_oss_setup *setup = pstr->oss.setup_list; 2952 - mutex_lock(&pstr->oss.setup_mutex); 2967 + guard(mutex)(&pstr->oss.setup_mutex); 2953 2968 while (setup) { 2954 2969 snd_iprintf(buffer, "%s %u %u%s%s%s%s%s%s\n", 2955 2970 setup->task_name, ··· 2963 2978 setup->nosilence ? " no-silence" : ""); 2964 2979 setup = setup->next; 2965 2980 } 2966 - mutex_unlock(&pstr->oss.setup_mutex); 2967 2981 } 2968 2982 2969 2983 static void snd_pcm_oss_proc_free_setup_list(struct snd_pcm_str * pstr) ··· 2988 3004 struct snd_pcm_oss_setup *setup, *setup1, template; 2989 3005 2990 3006 while (!snd_info_get_line(buffer, line, sizeof(line))) { 2991 - mutex_lock(&pstr->oss.setup_mutex); 3007 + guard(mutex)(&pstr->oss.setup_mutex); 2992 3008 memset(&template, 0, sizeof(template)); 2993 3009 ptr = snd_info_get_str(task_name, line, sizeof(task_name)); 2994 3010 if (!strcmp(task_name, "clear") || !strcmp(task_name, "erase")) { 2995 3011 snd_pcm_oss_proc_free_setup_list(pstr); 2996 - mutex_unlock(&pstr->oss.setup_mutex); 2997 3012 continue; 2998 3013 } 2999 3014 for (setup = pstr->oss.setup_list; setup; setup = setup->next) { ··· 3032 3049 setup = kmalloc(sizeof(*setup), GFP_KERNEL); 3033 3050 if (! setup) { 3034 3051 buffer->error = -ENOMEM; 3035 - mutex_unlock(&pstr->oss.setup_mutex); 3036 3052 return; 3037 3053 } 3038 3054 if (pstr->oss.setup_list == NULL) ··· 3045 3063 if (! template.task_name) { 3046 3064 kfree(setup); 3047 3065 buffer->error = -ENOMEM; 3048 - mutex_unlock(&pstr->oss.setup_mutex); 3049 3066 return; 3050 3067 } 3051 3068 } 3052 3069 *setup = template; 3053 - mutex_unlock(&pstr->oss.setup_mutex); 3054 3070 } 3055 3071 } 3056 3072
+36 -64
sound/core/pcm.c
··· 91 91 92 92 if (get_user(device, (int __user *)arg)) 93 93 return -EFAULT; 94 - mutex_lock(&register_mutex); 95 - device = snd_pcm_next(card, device); 96 - mutex_unlock(&register_mutex); 94 + scoped_guard(mutex, &register_mutex) 95 + device = snd_pcm_next(card, device); 97 96 if (put_user(device, (int __user *)arg)) 98 97 return -EFAULT; 99 98 return 0; ··· 105 106 struct snd_pcm *pcm; 106 107 struct snd_pcm_str *pstr; 107 108 struct snd_pcm_substream *substream; 108 - int err; 109 109 110 110 info = (struct snd_pcm_info __user *)arg; 111 111 if (get_user(device, &info->device)) ··· 116 118 stream = array_index_nospec(stream, 2); 117 119 if (get_user(subdevice, &info->subdevice)) 118 120 return -EFAULT; 119 - mutex_lock(&register_mutex); 121 + guard(mutex)(&register_mutex); 120 122 pcm = snd_pcm_get(card, device); 121 - if (pcm == NULL) { 122 - err = -ENXIO; 123 - goto _error; 124 - } 123 + if (pcm == NULL) 124 + return -ENXIO; 125 125 pstr = &pcm->streams[stream]; 126 - if (pstr->substream_count == 0) { 127 - err = -ENOENT; 128 - goto _error; 129 - } 130 - if (subdevice >= pstr->substream_count) { 131 - err = -ENXIO; 132 - goto _error; 133 - } 126 + if (pstr->substream_count == 0) 127 + return -ENOENT; 128 + if (subdevice >= pstr->substream_count) 129 + return -ENXIO; 134 130 for (substream = pstr->substream; substream; 135 131 substream = substream->next) 136 132 if (substream->number == (int)subdevice) 137 133 break; 138 - if (substream == NULL) { 139 - err = -ENXIO; 140 - goto _error; 141 - } 142 - mutex_lock(&pcm->open_mutex); 143 - err = snd_pcm_info_user(substream, info); 144 - mutex_unlock(&pcm->open_mutex); 145 - _error: 146 - mutex_unlock(&register_mutex); 147 - return err; 134 + if (substream == NULL) 135 + return -ENXIO; 136 + guard(mutex)(&pcm->open_mutex); 137 + return snd_pcm_info_user(substream, info); 148 138 } 149 139 case SNDRV_CTL_IOCTL_PCM_PREFER_SUBDEVICE: 150 140 { ··· 211 225 */ 212 226 const char *snd_pcm_format_name(snd_pcm_format_t format) 213 227 { 214 - if ((__force unsigned int)format >= ARRAY_SIZE(snd_pcm_format_names)) 228 + unsigned int format_num = (__force unsigned int)format; 229 + 230 + if (format_num >= ARRAY_SIZE(snd_pcm_format_names) || !snd_pcm_format_names[format_num]) 215 231 return "Unknown"; 216 - return snd_pcm_format_names[(__force unsigned int)format]; 232 + return snd_pcm_format_names[format_num]; 217 233 } 218 234 EXPORT_SYMBOL_GPL(snd_pcm_format_name); 219 235 ··· 328 340 static void snd_pcm_proc_info_read(struct snd_pcm_substream *substream, 329 341 struct snd_info_buffer *buffer) 330 342 { 331 - struct snd_pcm_info *info; 343 + struct snd_pcm_info *info __free(kfree) = NULL; 332 344 int err; 333 345 334 346 if (! substream) ··· 341 353 err = snd_pcm_info(substream, info); 342 354 if (err < 0) { 343 355 snd_iprintf(buffer, "error %d\n", err); 344 - kfree(info); 345 356 return; 346 357 } 347 358 snd_iprintf(buffer, "card: %d\n", info->card); ··· 354 367 snd_iprintf(buffer, "subclass: %d\n", info->dev_subclass); 355 368 snd_iprintf(buffer, "subdevices_count: %d\n", info->subdevices_count); 356 369 snd_iprintf(buffer, "subdevices_avail: %d\n", info->subdevices_avail); 357 - kfree(info); 358 370 } 359 371 360 372 static void snd_pcm_stream_proc_info_read(struct snd_info_entry *entry, ··· 375 389 struct snd_pcm_substream *substream = entry->private_data; 376 390 struct snd_pcm_runtime *runtime; 377 391 378 - mutex_lock(&substream->pcm->open_mutex); 392 + guard(mutex)(&substream->pcm->open_mutex); 379 393 runtime = substream->runtime; 380 394 if (!runtime) { 381 395 snd_iprintf(buffer, "closed\n"); 382 - goto unlock; 396 + return; 383 397 } 384 398 if (runtime->state == SNDRV_PCM_STATE_OPEN) { 385 399 snd_iprintf(buffer, "no setup\n"); 386 - goto unlock; 400 + return; 387 401 } 388 402 snd_iprintf(buffer, "access: %s\n", snd_pcm_access_name(runtime->access)); 389 403 snd_iprintf(buffer, "format: %s\n", snd_pcm_format_name(runtime->format)); ··· 402 416 snd_iprintf(buffer, "OSS period frames: %lu\n", (unsigned long)runtime->oss.period_frames); 403 417 } 404 418 #endif 405 - unlock: 406 - mutex_unlock(&substream->pcm->open_mutex); 407 419 } 408 420 409 421 static void snd_pcm_substream_proc_sw_params_read(struct snd_info_entry *entry, ··· 410 426 struct snd_pcm_substream *substream = entry->private_data; 411 427 struct snd_pcm_runtime *runtime; 412 428 413 - mutex_lock(&substream->pcm->open_mutex); 429 + guard(mutex)(&substream->pcm->open_mutex); 414 430 runtime = substream->runtime; 415 431 if (!runtime) { 416 432 snd_iprintf(buffer, "closed\n"); 417 - goto unlock; 433 + return; 418 434 } 419 435 if (runtime->state == SNDRV_PCM_STATE_OPEN) { 420 436 snd_iprintf(buffer, "no setup\n"); 421 - goto unlock; 437 + return; 422 438 } 423 439 snd_iprintf(buffer, "tstamp_mode: %s\n", snd_pcm_tstamp_mode_name(runtime->tstamp_mode)); 424 440 snd_iprintf(buffer, "period_step: %u\n", runtime->period_step); ··· 428 444 snd_iprintf(buffer, "silence_threshold: %lu\n", runtime->silence_threshold); 429 445 snd_iprintf(buffer, "silence_size: %lu\n", runtime->silence_size); 430 446 snd_iprintf(buffer, "boundary: %lu\n", runtime->boundary); 431 - unlock: 432 - mutex_unlock(&substream->pcm->open_mutex); 433 447 } 434 448 435 449 static void snd_pcm_substream_proc_status_read(struct snd_info_entry *entry, ··· 438 456 struct snd_pcm_status64 status; 439 457 int err; 440 458 441 - mutex_lock(&substream->pcm->open_mutex); 459 + guard(mutex)(&substream->pcm->open_mutex); 442 460 runtime = substream->runtime; 443 461 if (!runtime) { 444 462 snd_iprintf(buffer, "closed\n"); 445 - goto unlock; 463 + return; 446 464 } 447 465 memset(&status, 0, sizeof(status)); 448 466 err = snd_pcm_status64(substream, &status); 449 467 if (err < 0) { 450 468 snd_iprintf(buffer, "error %d\n", err); 451 - goto unlock; 469 + return; 452 470 } 453 471 snd_iprintf(buffer, "state: %s\n", snd_pcm_state_name(status.state)); 454 472 snd_iprintf(buffer, "owner_pid : %d\n", pid_vnr(substream->pid)); ··· 462 480 snd_iprintf(buffer, "-----\n"); 463 481 snd_iprintf(buffer, "hw_ptr : %ld\n", runtime->status->hw_ptr); 464 482 snd_iprintf(buffer, "appl_ptr : %ld\n", runtime->control->appl_ptr); 465 - unlock: 466 - mutex_unlock(&substream->pcm->open_mutex); 467 483 } 468 484 469 485 #ifdef CONFIG_SND_PCM_XRUN_DEBUG ··· 989 1009 kfree(runtime->hw_constraints.rules); 990 1010 /* Avoid concurrent access to runtime via PCM timer interface */ 991 1011 if (substream->timer) { 992 - spin_lock_irq(&substream->timer->lock); 993 - substream->runtime = NULL; 994 - spin_unlock_irq(&substream->timer->lock); 1012 + scoped_guard(spinlock_irq, &substream->timer->lock) 1013 + substream->runtime = NULL; 995 1014 } else { 996 1015 substream->runtime = NULL; 997 1016 } ··· 1047 1068 return -ENXIO; 1048 1069 pcm = device->device_data; 1049 1070 1050 - mutex_lock(&register_mutex); 1071 + guard(mutex)(&register_mutex); 1051 1072 err = snd_pcm_add(pcm); 1052 1073 if (err) 1053 - goto unlock; 1074 + return err; 1054 1075 for (cidx = 0; cidx < 2; cidx++) { 1055 1076 int devtype = -1; 1056 1077 if (pcm->streams[cidx].substream == NULL) ··· 1069 1090 pcm->streams[cidx].dev); 1070 1091 if (err < 0) { 1071 1092 list_del_init(&pcm->list); 1072 - goto unlock; 1093 + return err; 1073 1094 } 1074 1095 1075 1096 for (substream = pcm->streams[cidx].substream; substream; substream = substream->next) ··· 1077 1098 } 1078 1099 1079 1100 pcm_call_notify(pcm, n_register); 1080 - 1081 - unlock: 1082 - mutex_unlock(&register_mutex); 1083 1101 return err; 1084 1102 } 1085 1103 ··· 1086 1110 struct snd_pcm_substream *substream; 1087 1111 int cidx; 1088 1112 1089 - mutex_lock(&register_mutex); 1090 - mutex_lock(&pcm->open_mutex); 1113 + guard(mutex)(&register_mutex); 1114 + guard(mutex)(&pcm->open_mutex); 1091 1115 wake_up(&pcm->open_wait); 1092 1116 list_del_init(&pcm->list); 1093 1117 ··· 1114 1138 snd_unregister_device(pcm->streams[cidx].dev); 1115 1139 free_chmap(&pcm->streams[cidx]); 1116 1140 } 1117 - mutex_unlock(&pcm->open_mutex); 1118 - mutex_unlock(&register_mutex); 1119 1141 return 0; 1120 1142 } 1121 1143 ··· 1138 1164 !notify->n_unregister || 1139 1165 !notify->n_disconnect)) 1140 1166 return -EINVAL; 1141 - mutex_lock(&register_mutex); 1167 + guard(mutex)(&register_mutex); 1142 1168 if (nfree) { 1143 1169 list_del(&notify->list); 1144 1170 list_for_each_entry(pcm, &snd_pcm_devices, list) ··· 1148 1174 list_for_each_entry(pcm, &snd_pcm_devices, list) 1149 1175 notify->n_register(pcm); 1150 1176 } 1151 - mutex_unlock(&register_mutex); 1152 1177 return 0; 1153 1178 } 1154 1179 EXPORT_SYMBOL(snd_pcm_notify); ··· 1163 1190 { 1164 1191 struct snd_pcm *pcm; 1165 1192 1166 - mutex_lock(&register_mutex); 1193 + guard(mutex)(&register_mutex); 1167 1194 list_for_each_entry(pcm, &snd_pcm_devices, list) { 1168 1195 snd_iprintf(buffer, "%02i-%02i: %s : %s", 1169 1196 pcm->card->number, pcm->device, pcm->id, pcm->name); ··· 1175 1202 pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream_count); 1176 1203 snd_iprintf(buffer, "\n"); 1177 1204 } 1178 - mutex_unlock(&register_mutex); 1179 1205 } 1180 1206 1181 1207 static struct snd_info_entry *snd_pcm_proc_entry;
+42 -53
sound/core/pcm_compat.c
··· 235 235 int refine, 236 236 struct snd_pcm_hw_params32 __user *data32) 237 237 { 238 - struct snd_pcm_hw_params *data; 238 + struct snd_pcm_hw_params *data __free(kfree) = NULL; 239 239 struct snd_pcm_runtime *runtime; 240 240 int err; 241 241 ··· 248 248 return -ENOMEM; 249 249 250 250 /* only fifo_size (RO from userspace) is different, so just copy all */ 251 - if (copy_from_user(data, data32, sizeof(*data32))) { 252 - err = -EFAULT; 253 - goto error; 254 - } 251 + if (copy_from_user(data, data32, sizeof(*data32))) 252 + return -EFAULT; 255 253 256 254 if (refine) { 257 255 err = snd_pcm_hw_refine(substream, data); 258 256 if (err < 0) 259 - goto error; 257 + return err; 260 258 err = fixup_unreferenced_params(substream, data); 261 259 } else { 262 260 err = snd_pcm_hw_params(substream, data); 263 261 } 264 262 if (err < 0) 265 - goto error; 263 + return err; 266 264 if (copy_to_user(data32, data, sizeof(*data32)) || 267 - put_user(data->fifo_size, &data32->fifo_size)) { 268 - err = -EFAULT; 269 - goto error; 270 - } 265 + put_user(data->fifo_size, &data32->fifo_size)) 266 + return -EFAULT; 271 267 272 268 if (! refine) { 273 269 unsigned int new_boundary = recalculate_boundary(runtime); 274 270 if (new_boundary) 275 271 runtime->boundary = new_boundary; 276 272 } 277 - error: 278 - kfree(data); 279 273 return err; 280 274 } 281 275 ··· 332 338 compat_caddr_t buf; 333 339 compat_caddr_t __user *bufptr; 334 340 u32 frames; 335 - void __user **bufs; 341 + void __user **bufs __free(kfree) = NULL; 336 342 int err, ch, i; 337 343 338 344 if (! substream->runtime) ··· 354 360 return -ENOMEM; 355 361 for (i = 0; i < ch; i++) { 356 362 u32 ptr; 357 - if (get_user(ptr, bufptr)) { 358 - kfree(bufs); 363 + if (get_user(ptr, bufptr)) 359 364 return -EFAULT; 360 - } 361 365 bufs[i] = compat_ptr(ptr); 362 366 bufptr++; 363 367 } ··· 365 373 err = snd_pcm_lib_readv(substream, bufs, frames); 366 374 if (err >= 0) { 367 375 if (put_user(err, &data32->result)) 368 - err = -EFAULT; 376 + return -EFAULT; 369 377 } 370 - kfree(bufs); 371 378 return err; 372 379 } 373 380 ··· 432 441 boundary = recalculate_boundary(runtime); 433 442 if (!boundary) 434 443 boundary = 0x7fffffff; 435 - snd_pcm_stream_lock_irq(substream); 436 - /* FIXME: we should consider the boundary for the sync from app */ 437 - if (!(sflags & SNDRV_PCM_SYNC_PTR_APPL)) 438 - control->appl_ptr = scontrol.appl_ptr; 439 - else 440 - scontrol.appl_ptr = control->appl_ptr % boundary; 441 - if (!(sflags & SNDRV_PCM_SYNC_PTR_AVAIL_MIN)) 442 - control->avail_min = scontrol.avail_min; 443 - else 444 - scontrol.avail_min = control->avail_min; 445 - sstatus.state = status->state; 446 - sstatus.hw_ptr = status->hw_ptr % boundary; 447 - sstatus.tstamp = status->tstamp; 448 - sstatus.suspended_state = status->suspended_state; 449 - sstatus.audio_tstamp = status->audio_tstamp; 450 - snd_pcm_stream_unlock_irq(substream); 444 + scoped_guard(pcm_stream_lock_irq, substream) { 445 + /* FIXME: we should consider the boundary for the sync from app */ 446 + if (!(sflags & SNDRV_PCM_SYNC_PTR_APPL)) 447 + control->appl_ptr = scontrol.appl_ptr; 448 + else 449 + scontrol.appl_ptr = control->appl_ptr % boundary; 450 + if (!(sflags & SNDRV_PCM_SYNC_PTR_AVAIL_MIN)) 451 + control->avail_min = scontrol.avail_min; 452 + else 453 + scontrol.avail_min = control->avail_min; 454 + sstatus.state = status->state; 455 + sstatus.hw_ptr = status->hw_ptr % boundary; 456 + sstatus.tstamp = status->tstamp; 457 + sstatus.suspended_state = status->suspended_state; 458 + sstatus.audio_tstamp = status->audio_tstamp; 459 + } 451 460 if (!(sflags & SNDRV_PCM_SYNC_PTR_APPL)) 452 461 snd_pcm_dma_buffer_sync(substream, SNDRV_DMA_SYNC_DEVICE); 453 462 if (put_user(sstatus.state, &src->s.status.state) || ··· 510 519 if (err < 0) 511 520 return err; 512 521 } 513 - snd_pcm_stream_lock_irq(substream); 514 - if (!(sync_ptr.flags & SNDRV_PCM_SYNC_PTR_APPL)) { 515 - err = pcm_lib_apply_appl_ptr(substream, sync_cp->appl_ptr); 516 - if (err < 0) { 517 - snd_pcm_stream_unlock_irq(substream); 518 - return err; 522 + scoped_guard(pcm_stream_lock_irq, substream) { 523 + if (!(sync_ptr.flags & SNDRV_PCM_SYNC_PTR_APPL)) { 524 + err = pcm_lib_apply_appl_ptr(substream, sync_cp->appl_ptr); 525 + if (err < 0) 526 + return err; 527 + } else { 528 + sync_cp->appl_ptr = control->appl_ptr; 519 529 } 520 - } else { 521 - sync_cp->appl_ptr = control->appl_ptr; 530 + if (!(sync_ptr.flags & SNDRV_PCM_SYNC_PTR_AVAIL_MIN)) 531 + control->avail_min = sync_cp->avail_min; 532 + else 533 + sync_cp->avail_min = control->avail_min; 534 + sync_ptr.s.status.state = status->state; 535 + sync_ptr.s.status.hw_ptr = status->hw_ptr; 536 + sync_ptr.s.status.tstamp = status->tstamp; 537 + sync_ptr.s.status.suspended_state = status->suspended_state; 538 + sync_ptr.s.status.audio_tstamp = status->audio_tstamp; 522 539 } 523 - if (!(sync_ptr.flags & SNDRV_PCM_SYNC_PTR_AVAIL_MIN)) 524 - control->avail_min = sync_cp->avail_min; 525 - else 526 - sync_cp->avail_min = control->avail_min; 527 - sync_ptr.s.status.state = status->state; 528 - sync_ptr.s.status.hw_ptr = status->hw_ptr; 529 - sync_ptr.s.status.tstamp = status->tstamp; 530 - sync_ptr.s.status.suspended_state = status->suspended_state; 531 - sync_ptr.s.status.audio_tstamp = status->audio_tstamp; 532 - snd_pcm_stream_unlock_irq(substream); 533 540 if (!(sync_ptr.flags & SNDRV_PCM_SYNC_PTR_APPL)) 534 541 snd_pcm_dma_buffer_sync(substream, SNDRV_DMA_SYNC_DEVICE); 535 542 if (copy_to_user(_sync_ptr, &sync_ptr, sizeof(sync_ptr)))
+3 -7
sound/core/pcm_lib.c
··· 1744 1744 void *arg) 1745 1745 { 1746 1746 struct snd_pcm_runtime *runtime = substream->runtime; 1747 - unsigned long flags; 1748 - snd_pcm_stream_lock_irqsave(substream, flags); 1747 + 1748 + guard(pcm_stream_lock_irqsave)(substream); 1749 1749 if (snd_pcm_running(substream) && 1750 1750 snd_pcm_update_hw_ptr(substream) >= 0) 1751 1751 runtime->status->hw_ptr %= runtime->buffer_size; ··· 1753 1753 runtime->status->hw_ptr = 0; 1754 1754 runtime->hw_ptr_wrap = 0; 1755 1755 } 1756 - snd_pcm_stream_unlock_irqrestore(substream, flags); 1757 1756 return 0; 1758 1757 } 1759 1758 ··· 1898 1899 */ 1899 1900 void snd_pcm_period_elapsed(struct snd_pcm_substream *substream) 1900 1901 { 1901 - unsigned long flags; 1902 - 1903 1902 if (snd_BUG_ON(!substream)) 1904 1903 return; 1905 1904 1906 - snd_pcm_stream_lock_irqsave(substream, flags); 1905 + guard(pcm_stream_lock_irqsave)(substream); 1907 1906 snd_pcm_period_elapsed_under_stream_lock(substream); 1908 - snd_pcm_stream_unlock_irqrestore(substream, flags); 1909 1907 } 1910 1908 EXPORT_SYMBOL(snd_pcm_period_elapsed); 1911 1909
+12 -18
sound/core/pcm_memory.c
··· 38 38 39 39 static void update_allocated_size(struct snd_card *card, ssize_t bytes) 40 40 { 41 - mutex_lock(&card->memory_mutex); 41 + guard(mutex)(&card->memory_mutex); 42 42 __update_allocated_size(card, bytes); 43 - mutex_unlock(&card->memory_mutex); 44 43 } 45 44 46 45 static void decrease_allocated_size(struct snd_card *card, size_t bytes) 47 46 { 48 - mutex_lock(&card->memory_mutex); 47 + guard(mutex)(&card->memory_mutex); 49 48 WARN_ON(card->total_pcm_alloc_bytes < bytes); 50 49 __update_allocated_size(card, -(ssize_t)bytes); 51 - mutex_unlock(&card->memory_mutex); 52 50 } 53 51 54 52 static int do_alloc_pages(struct snd_card *card, int type, struct device *dev, ··· 56 58 int err; 57 59 58 60 /* check and reserve the requested size */ 59 - mutex_lock(&card->memory_mutex); 60 - if (max_alloc_per_card && 61 - card->total_pcm_alloc_bytes + size > max_alloc_per_card) { 62 - mutex_unlock(&card->memory_mutex); 63 - return -ENOMEM; 61 + scoped_guard(mutex, &card->memory_mutex) { 62 + if (max_alloc_per_card && 63 + card->total_pcm_alloc_bytes + size > max_alloc_per_card) 64 + return -ENOMEM; 65 + __update_allocated_size(card, size); 64 66 } 65 - __update_allocated_size(card, size); 66 - mutex_unlock(&card->memory_mutex); 67 67 68 68 if (str == SNDRV_PCM_STREAM_PLAYBACK) 69 69 dir = DMA_TO_DEVICE; ··· 187 191 size_t size; 188 192 struct snd_dma_buffer new_dmab; 189 193 190 - mutex_lock(&substream->pcm->open_mutex); 194 + guard(mutex)(&substream->pcm->open_mutex); 191 195 if (substream->runtime) { 192 196 buffer->error = -EBUSY; 193 - goto unlock; 197 + return; 194 198 } 195 199 if (!snd_info_get_line(buffer, line, sizeof(line))) { 196 200 snd_info_get_str(str, line, sizeof(str)); 197 201 size = simple_strtoul(str, NULL, 10) * 1024; 198 202 if ((size != 0 && size < 8192) || size > substream->dma_max) { 199 203 buffer->error = -EINVAL; 200 - goto unlock; 204 + return; 201 205 } 202 206 if (substream->dma_buffer.bytes == size) 203 - goto unlock; 207 + return; 204 208 memset(&new_dmab, 0, sizeof(new_dmab)); 205 209 new_dmab.dev = substream->dma_buffer.dev; 206 210 if (size > 0) { ··· 214 218 substream->pcm->card->number, substream->pcm->device, 215 219 substream->stream ? 'c' : 'p', substream->number, 216 220 substream->pcm->name, size); 217 - goto unlock; 221 + return; 218 222 } 219 223 substream->buffer_bytes_max = size; 220 224 } else { ··· 226 230 } else { 227 231 buffer->error = -EINVAL; 228 232 } 229 - unlock: 230 - mutex_unlock(&substream->pcm->open_mutex); 231 233 } 232 234 233 235 static inline void preallocate_info_init(struct snd_pcm_substream *substream)
+189 -268
sound/core/pcm_native.c
··· 236 236 int snd_pcm_info_user(struct snd_pcm_substream *substream, 237 237 struct snd_pcm_info __user * _info) 238 238 { 239 - struct snd_pcm_info *info; 239 + struct snd_pcm_info *info __free(kfree) = NULL; 240 240 int err; 241 241 242 242 info = kmalloc(sizeof(*info), GFP_KERNEL); ··· 247 247 if (copy_to_user(_info, info, sizeof(*info))) 248 248 err = -EFAULT; 249 249 } 250 - kfree(info); 251 250 return err; 252 251 } 253 252 ··· 358 359 struct snd_pcm_hw_constraints *constrs = 359 360 &substream->runtime->hw_constraints; 360 361 unsigned int k; 361 - unsigned int *rstamps; 362 + unsigned int *rstamps __free(kfree) = NULL; 362 363 unsigned int vstamps[SNDRV_PCM_HW_PARAM_LAST_INTERVAL + 1]; 363 364 unsigned int stamp; 364 365 struct snd_pcm_hw_rule *r; ··· 434 435 } 435 436 436 437 changed = r->func(params, r); 437 - if (changed < 0) { 438 - err = changed; 439 - goto out; 440 - } 438 + if (changed < 0) 439 + return changed; 441 440 442 441 /* 443 442 * When the parameter is changed, notify it to the caller ··· 466 469 if (again) 467 470 goto retry; 468 471 469 - out: 470 - kfree(rstamps); 471 472 return err; 472 473 } 473 474 ··· 571 576 static int snd_pcm_hw_refine_user(struct snd_pcm_substream *substream, 572 577 struct snd_pcm_hw_params __user * _params) 573 578 { 574 - struct snd_pcm_hw_params *params; 579 + struct snd_pcm_hw_params *params __free(kfree) = NULL; 575 580 int err; 576 581 577 582 params = memdup_user(_params, sizeof(*params)); 578 583 if (IS_ERR(params)) 579 - return PTR_ERR(params); 584 + return PTR_ERR(no_free_ptr(params)); 580 585 581 586 err = snd_pcm_hw_refine(substream, params); 582 587 if (err < 0) 583 - goto end; 588 + return err; 584 589 585 590 err = fixup_unreferenced_params(substream, params); 586 591 if (err < 0) 587 - goto end; 592 + return err; 588 593 589 594 if (copy_to_user(_params, params, sizeof(*params))) 590 - err = -EFAULT; 591 - end: 592 - kfree(params); 593 - return err; 595 + return -EFAULT; 596 + return 0; 594 597 } 595 598 596 599 static int period_to_usecs(struct snd_pcm_runtime *runtime) ··· 609 616 static void snd_pcm_set_state(struct snd_pcm_substream *substream, 610 617 snd_pcm_state_t state) 611 618 { 612 - snd_pcm_stream_lock_irq(substream); 619 + guard(pcm_stream_lock_irq)(substream); 613 620 if (substream->runtime->state != SNDRV_PCM_STATE_DISCONNECTED) 614 621 __snd_pcm_set_state(substream->runtime, state); 615 - snd_pcm_stream_unlock_irq(substream); 616 622 } 617 623 618 624 static inline void snd_pcm_timer_notify(struct snd_pcm_substream *substream, ··· 737 745 err = snd_pcm_buffer_access_lock(runtime); 738 746 if (err < 0) 739 747 return err; 740 - snd_pcm_stream_lock_irq(substream); 741 - switch (runtime->state) { 742 - case SNDRV_PCM_STATE_OPEN: 743 - case SNDRV_PCM_STATE_SETUP: 744 - case SNDRV_PCM_STATE_PREPARED: 745 - if (!is_oss_stream(substream) && 746 - atomic_read(&substream->mmap_count)) 748 + scoped_guard(pcm_stream_lock_irq, substream) { 749 + switch (runtime->state) { 750 + case SNDRV_PCM_STATE_OPEN: 751 + case SNDRV_PCM_STATE_SETUP: 752 + case SNDRV_PCM_STATE_PREPARED: 753 + if (!is_oss_stream(substream) && 754 + atomic_read(&substream->mmap_count)) 755 + err = -EBADFD; 756 + break; 757 + default: 747 758 err = -EBADFD; 748 - break; 749 - default: 750 - err = -EBADFD; 751 - break; 759 + break; 760 + } 752 761 } 753 - snd_pcm_stream_unlock_irq(substream); 754 762 if (err) 755 763 goto unlock; 756 764 ··· 861 869 static int snd_pcm_hw_params_user(struct snd_pcm_substream *substream, 862 870 struct snd_pcm_hw_params __user * _params) 863 871 { 864 - struct snd_pcm_hw_params *params; 872 + struct snd_pcm_hw_params *params __free(kfree) = NULL; 865 873 int err; 866 874 867 875 params = memdup_user(_params, sizeof(*params)); 868 876 if (IS_ERR(params)) 869 - return PTR_ERR(params); 877 + return PTR_ERR(no_free_ptr(params)); 870 878 871 879 err = snd_pcm_hw_params(substream, params); 872 880 if (err < 0) 873 - goto end; 881 + return err; 874 882 875 883 if (copy_to_user(_params, params, sizeof(*params))) 876 - err = -EFAULT; 877 - end: 878 - kfree(params); 884 + return -EFAULT; 879 885 return err; 880 886 } 881 887 ··· 900 910 result = snd_pcm_buffer_access_lock(runtime); 901 911 if (result < 0) 902 912 return result; 903 - snd_pcm_stream_lock_irq(substream); 904 - switch (runtime->state) { 905 - case SNDRV_PCM_STATE_SETUP: 906 - case SNDRV_PCM_STATE_PREPARED: 907 - if (atomic_read(&substream->mmap_count)) 913 + scoped_guard(pcm_stream_lock_irq, substream) { 914 + switch (runtime->state) { 915 + case SNDRV_PCM_STATE_SETUP: 916 + case SNDRV_PCM_STATE_PREPARED: 917 + if (atomic_read(&substream->mmap_count)) 918 + result = -EBADFD; 919 + break; 920 + default: 908 921 result = -EBADFD; 909 - break; 910 - default: 911 - result = -EBADFD; 912 - break; 922 + break; 923 + } 913 924 } 914 - snd_pcm_stream_unlock_irq(substream); 915 925 if (result) 916 926 goto unlock; 917 927 result = do_hw_free(substream); ··· 931 941 if (PCM_RUNTIME_CHECK(substream)) 932 942 return -ENXIO; 933 943 runtime = substream->runtime; 934 - snd_pcm_stream_lock_irq(substream); 935 - if (runtime->state == SNDRV_PCM_STATE_OPEN) { 936 - snd_pcm_stream_unlock_irq(substream); 937 - return -EBADFD; 944 + scoped_guard(pcm_stream_lock_irq, substream) { 945 + if (runtime->state == SNDRV_PCM_STATE_OPEN) 946 + return -EBADFD; 938 947 } 939 - snd_pcm_stream_unlock_irq(substream); 940 948 941 949 if (params->tstamp_mode < 0 || 942 950 params->tstamp_mode > SNDRV_PCM_TSTAMP_LAST) ··· 954 966 return -EINVAL; 955 967 } 956 968 err = 0; 957 - snd_pcm_stream_lock_irq(substream); 958 - runtime->tstamp_mode = params->tstamp_mode; 959 - if (params->proto >= SNDRV_PROTOCOL_VERSION(2, 0, 12)) 960 - runtime->tstamp_type = params->tstamp_type; 961 - runtime->period_step = params->period_step; 962 - runtime->control->avail_min = params->avail_min; 963 - runtime->start_threshold = params->start_threshold; 964 - runtime->stop_threshold = params->stop_threshold; 965 - runtime->silence_threshold = params->silence_threshold; 966 - runtime->silence_size = params->silence_size; 967 - params->boundary = runtime->boundary; 968 - if (snd_pcm_running(substream)) { 969 - if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && 970 - runtime->silence_size > 0) 971 - snd_pcm_playback_silence(substream, ULONG_MAX); 972 - err = snd_pcm_update_state(substream, runtime); 969 + scoped_guard(pcm_stream_lock_irq, substream) { 970 + runtime->tstamp_mode = params->tstamp_mode; 971 + if (params->proto >= SNDRV_PROTOCOL_VERSION(2, 0, 12)) 972 + runtime->tstamp_type = params->tstamp_type; 973 + runtime->period_step = params->period_step; 974 + runtime->control->avail_min = params->avail_min; 975 + runtime->start_threshold = params->start_threshold; 976 + runtime->stop_threshold = params->stop_threshold; 977 + runtime->silence_threshold = params->silence_threshold; 978 + runtime->silence_size = params->silence_size; 979 + params->boundary = runtime->boundary; 980 + if (snd_pcm_running(substream)) { 981 + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && 982 + runtime->silence_size > 0) 983 + snd_pcm_playback_silence(substream, ULONG_MAX); 984 + err = snd_pcm_update_state(substream, runtime); 985 + } 973 986 } 974 - snd_pcm_stream_unlock_irq(substream); 975 987 return err; 976 988 } 977 989 ··· 1005 1017 { 1006 1018 struct snd_pcm_runtime *runtime = substream->runtime; 1007 1019 1008 - snd_pcm_stream_lock_irq(substream); 1020 + guard(pcm_stream_lock_irq)(substream); 1009 1021 1010 1022 snd_pcm_unpack_audio_tstamp_config(status->audio_tstamp_data, 1011 1023 &runtime->audio_tstamp_config); ··· 1026 1038 status->state = runtime->state; 1027 1039 status->suspended_state = runtime->suspended_state; 1028 1040 if (status->state == SNDRV_PCM_STATE_OPEN) 1029 - goto _end; 1041 + return 0; 1030 1042 status->trigger_tstamp_sec = runtime->trigger_tstamp.tv_sec; 1031 1043 status->trigger_tstamp_nsec = runtime->trigger_tstamp.tv_nsec; 1032 1044 if (snd_pcm_running(substream)) { ··· 1071 1083 status->overrange = runtime->overrange; 1072 1084 runtime->avail_max = 0; 1073 1085 runtime->overrange = 0; 1074 - _end: 1075 - snd_pcm_stream_unlock_irq(substream); 1076 1086 return 0; 1077 1087 } 1078 1088 ··· 1155 1169 1156 1170 channel = info->channel; 1157 1171 runtime = substream->runtime; 1158 - snd_pcm_stream_lock_irq(substream); 1159 - if (runtime->state == SNDRV_PCM_STATE_OPEN) { 1160 - snd_pcm_stream_unlock_irq(substream); 1161 - return -EBADFD; 1172 + scoped_guard(pcm_stream_lock_irq, substream) { 1173 + if (runtime->state == SNDRV_PCM_STATE_OPEN) 1174 + return -EBADFD; 1162 1175 } 1163 - snd_pcm_stream_unlock_irq(substream); 1164 1176 if (channel >= runtime->channels) 1165 1177 return -EINVAL; 1166 1178 memset(info, 0, sizeof(*info)); ··· 1379 1395 struct snd_pcm_substream *substream, 1380 1396 snd_pcm_state_t state) 1381 1397 { 1382 - int res; 1383 - 1384 - snd_pcm_stream_lock_irq(substream); 1385 - res = snd_pcm_action(ops, substream, state); 1386 - snd_pcm_stream_unlock_irq(substream); 1387 - return res; 1398 + guard(pcm_stream_lock_irq)(substream); 1399 + return snd_pcm_action(ops, substream, state); 1388 1400 } 1389 1401 1390 1402 /* ··· 1392 1412 int res; 1393 1413 1394 1414 /* Guarantee the group members won't change during non-atomic action */ 1395 - down_read(&snd_pcm_link_rwsem); 1415 + guard(rwsem_read)(&snd_pcm_link_rwsem); 1396 1416 res = snd_pcm_buffer_access_lock(substream->runtime); 1397 1417 if (res < 0) 1398 - goto unlock; 1418 + return res; 1399 1419 if (snd_pcm_stream_linked(substream)) 1400 1420 res = snd_pcm_action_group(ops, substream, state, false); 1401 1421 else 1402 1422 res = snd_pcm_action_single(ops, substream, state); 1403 1423 snd_pcm_buffer_access_unlock(substream->runtime); 1404 - unlock: 1405 - up_read(&snd_pcm_link_rwsem); 1406 1424 return res; 1407 1425 } 1408 1426 ··· 1570 1592 */ 1571 1593 int snd_pcm_stop_xrun(struct snd_pcm_substream *substream) 1572 1594 { 1573 - unsigned long flags; 1574 - 1575 - snd_pcm_stream_lock_irqsave(substream, flags); 1595 + guard(pcm_stream_lock_irqsave)(substream); 1576 1596 if (substream->runtime && snd_pcm_running(substream)) 1577 1597 __snd_pcm_xrun(substream); 1578 - snd_pcm_stream_unlock_irqrestore(substream, flags); 1579 1598 return 0; 1580 1599 } 1581 1600 EXPORT_SYMBOL_GPL(snd_pcm_stop_xrun); ··· 1724 1749 */ 1725 1750 static int snd_pcm_suspend(struct snd_pcm_substream *substream) 1726 1751 { 1727 - int err; 1728 - unsigned long flags; 1729 - 1730 - snd_pcm_stream_lock_irqsave(substream, flags); 1731 - err = snd_pcm_action(&snd_pcm_action_suspend, substream, 1732 - ACTION_ARG_IGNORE); 1733 - snd_pcm_stream_unlock_irqrestore(substream, flags); 1734 - return err; 1752 + guard(pcm_stream_lock_irqsave)(substream); 1753 + return snd_pcm_action(&snd_pcm_action_suspend, substream, 1754 + ACTION_ARG_IGNORE); 1735 1755 } 1736 1756 1737 1757 /** ··· 1842 1872 static int snd_pcm_xrun(struct snd_pcm_substream *substream) 1843 1873 { 1844 1874 struct snd_pcm_runtime *runtime = substream->runtime; 1845 - int result; 1846 1875 1847 - snd_pcm_stream_lock_irq(substream); 1876 + guard(pcm_stream_lock_irq)(substream); 1848 1877 switch (runtime->state) { 1849 1878 case SNDRV_PCM_STATE_XRUN: 1850 - result = 0; /* already there */ 1851 - break; 1879 + return 0; /* already there */ 1852 1880 case SNDRV_PCM_STATE_RUNNING: 1853 1881 __snd_pcm_xrun(substream); 1854 - result = 0; 1855 - break; 1882 + return 0; 1856 1883 default: 1857 - result = -EBADFD; 1884 + return -EBADFD; 1858 1885 } 1859 - snd_pcm_stream_unlock_irq(substream); 1860 - return result; 1861 1886 } 1862 1887 1863 1888 /* ··· 1881 1916 int err = snd_pcm_ops_ioctl(substream, SNDRV_PCM_IOCTL1_RESET, NULL); 1882 1917 if (err < 0) 1883 1918 return err; 1884 - snd_pcm_stream_lock_irq(substream); 1919 + guard(pcm_stream_lock_irq)(substream); 1885 1920 runtime->hw_ptr_base = 0; 1886 1921 runtime->hw_ptr_interrupt = runtime->status->hw_ptr - 1887 1922 runtime->status->hw_ptr % runtime->period_size; 1888 1923 runtime->silence_start = runtime->status->hw_ptr; 1889 1924 runtime->silence_filled = 0; 1890 - snd_pcm_stream_unlock_irq(substream); 1891 1925 return 0; 1892 1926 } 1893 1927 ··· 1894 1930 snd_pcm_state_t state) 1895 1931 { 1896 1932 struct snd_pcm_runtime *runtime = substream->runtime; 1897 - snd_pcm_stream_lock_irq(substream); 1933 + guard(pcm_stream_lock_irq)(substream); 1898 1934 runtime->control->appl_ptr = runtime->status->hw_ptr; 1899 1935 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && 1900 1936 runtime->silence_size > 0) 1901 1937 snd_pcm_playback_silence(substream, ULONG_MAX); 1902 - snd_pcm_stream_unlock_irq(substream); 1903 1938 } 1904 1939 1905 1940 static const struct action_ops snd_pcm_action_reset = { ··· 1974 2011 else 1975 2012 f_flags = substream->f_flags; 1976 2013 1977 - snd_pcm_stream_lock_irq(substream); 1978 - switch (substream->runtime->state) { 1979 - case SNDRV_PCM_STATE_PAUSED: 1980 - snd_pcm_pause(substream, false); 1981 - fallthrough; 1982 - case SNDRV_PCM_STATE_SUSPENDED: 1983 - snd_pcm_stop(substream, SNDRV_PCM_STATE_SETUP); 1984 - break; 2014 + scoped_guard(pcm_stream_lock_irq, substream) { 2015 + switch (substream->runtime->state) { 2016 + case SNDRV_PCM_STATE_PAUSED: 2017 + snd_pcm_pause(substream, false); 2018 + fallthrough; 2019 + case SNDRV_PCM_STATE_SUSPENDED: 2020 + snd_pcm_stop(substream, SNDRV_PCM_STATE_SETUP); 2021 + break; 2022 + } 1985 2023 } 1986 - snd_pcm_stream_unlock_irq(substream); 1987 2024 1988 2025 return snd_pcm_action_nonatomic(&snd_pcm_action_prepare, 1989 2026 substream, ··· 2200 2237 runtime->state == SNDRV_PCM_STATE_DISCONNECTED) 2201 2238 return -EBADFD; 2202 2239 2203 - snd_pcm_stream_lock_irq(substream); 2240 + guard(pcm_stream_lock_irq)(substream); 2204 2241 /* resume pause */ 2205 2242 if (runtime->state == SNDRV_PCM_STATE_PAUSED) 2206 2243 snd_pcm_pause(substream, false); 2207 2244 2208 2245 snd_pcm_stop(substream, SNDRV_PCM_STATE_SETUP); 2209 2246 /* runtime->control->appl_ptr = runtime->status->hw_ptr; */ 2210 - snd_pcm_stream_unlock_irq(substream); 2211 2247 2212 2248 return result; 2213 2249 } ··· 2235 2273 */ 2236 2274 static int snd_pcm_link(struct snd_pcm_substream *substream, int fd) 2237 2275 { 2238 - int res = 0; 2239 2276 struct snd_pcm_file *pcm_file; 2240 2277 struct snd_pcm_substream *substream1; 2241 - struct snd_pcm_group *group, *target_group; 2278 + struct snd_pcm_group *group __free(kfree) = NULL; 2279 + struct snd_pcm_group *target_group; 2242 2280 bool nonatomic = substream->pcm->nonatomic; 2243 - struct fd f = fdget(fd); 2281 + CLASS(fd, f)(fd); 2244 2282 2245 2283 if (!f.file) 2246 2284 return -EBADFD; 2247 - if (!is_pcm_file(f.file)) { 2248 - res = -EBADFD; 2249 - goto _badf; 2250 - } 2285 + if (!is_pcm_file(f.file)) 2286 + return -EBADFD; 2287 + 2251 2288 pcm_file = f.file->private_data; 2252 2289 substream1 = pcm_file->substream; 2253 2290 2254 - if (substream == substream1) { 2255 - res = -EINVAL; 2256 - goto _badf; 2257 - } 2291 + if (substream == substream1) 2292 + return -EINVAL; 2258 2293 2259 2294 group = kzalloc(sizeof(*group), GFP_KERNEL); 2260 - if (!group) { 2261 - res = -ENOMEM; 2262 - goto _nolock; 2263 - } 2295 + if (!group) 2296 + return -ENOMEM; 2264 2297 snd_pcm_group_init(group); 2265 2298 2266 - down_write(&snd_pcm_link_rwsem); 2299 + guard(rwsem_write)(&snd_pcm_link_rwsem); 2267 2300 if (substream->runtime->state == SNDRV_PCM_STATE_OPEN || 2268 2301 substream->runtime->state != substream1->runtime->state || 2269 - substream->pcm->nonatomic != substream1->pcm->nonatomic) { 2270 - res = -EBADFD; 2271 - goto _end; 2272 - } 2273 - if (snd_pcm_stream_linked(substream1)) { 2274 - res = -EALREADY; 2275 - goto _end; 2276 - } 2302 + substream->pcm->nonatomic != substream1->pcm->nonatomic) 2303 + return -EBADFD; 2304 + if (snd_pcm_stream_linked(substream1)) 2305 + return -EALREADY; 2277 2306 2278 - snd_pcm_stream_lock_irq(substream); 2279 - if (!snd_pcm_stream_linked(substream)) { 2280 - snd_pcm_group_assign(substream, group); 2281 - group = NULL; /* assigned, don't free this one below */ 2307 + scoped_guard(pcm_stream_lock_irq, substream) { 2308 + if (!snd_pcm_stream_linked(substream)) { 2309 + snd_pcm_group_assign(substream, group); 2310 + group = NULL; /* assigned, don't free this one below */ 2311 + } 2312 + target_group = substream->group; 2282 2313 } 2283 - target_group = substream->group; 2284 - snd_pcm_stream_unlock_irq(substream); 2285 2314 2286 2315 snd_pcm_group_lock_irq(target_group, nonatomic); 2287 2316 snd_pcm_stream_lock_nested(substream1); ··· 2280 2327 refcount_inc(&target_group->refs); 2281 2328 snd_pcm_stream_unlock(substream1); 2282 2329 snd_pcm_group_unlock_irq(target_group, nonatomic); 2283 - _end: 2284 - up_write(&snd_pcm_link_rwsem); 2285 - _nolock: 2286 - kfree(group); 2287 - _badf: 2288 - fdput(f); 2289 - return res; 2330 + return 0; 2290 2331 } 2291 2332 2292 2333 static void relink_to_local(struct snd_pcm_substream *substream) ··· 2295 2348 struct snd_pcm_group *group; 2296 2349 bool nonatomic = substream->pcm->nonatomic; 2297 2350 bool do_free = false; 2298 - int res = 0; 2299 2351 2300 - down_write(&snd_pcm_link_rwsem); 2352 + guard(rwsem_write)(&snd_pcm_link_rwsem); 2301 2353 2302 - if (!snd_pcm_stream_linked(substream)) { 2303 - res = -EALREADY; 2304 - goto _end; 2305 - } 2354 + if (!snd_pcm_stream_linked(substream)) 2355 + return -EALREADY; 2306 2356 2307 2357 group = substream->group; 2308 2358 snd_pcm_group_lock_irq(group, nonatomic); ··· 2318 2374 snd_pcm_group_unlock_irq(group, nonatomic); 2319 2375 if (do_free) 2320 2376 kfree(group); 2321 - 2322 - _end: 2323 - up_write(&snd_pcm_link_rwsem); 2324 - return res; 2377 + return 0; 2325 2378 } 2326 2379 2327 2380 /* ··· 2891 2950 /* block until the device gets woken up as it may touch the hardware */ 2892 2951 snd_power_wait(pcm->card); 2893 2952 2894 - mutex_lock(&pcm->open_mutex); 2895 - snd_pcm_release_substream(substream); 2896 - kfree(pcm_file); 2897 - mutex_unlock(&pcm->open_mutex); 2953 + scoped_guard(mutex, &pcm->open_mutex) { 2954 + snd_pcm_release_substream(substream); 2955 + kfree(pcm_file); 2956 + } 2898 2957 wake_up(&pcm->open_wait); 2899 2958 module_put(pcm->card->module); 2900 2959 snd_card_file_remove(pcm->card, file); ··· 2978 3037 if (frames == 0) 2979 3038 return 0; 2980 3039 2981 - snd_pcm_stream_lock_irq(substream); 2982 - ret = do_pcm_hwsync(substream); 2983 - if (!ret) 2984 - ret = rewind_appl_ptr(substream, frames, 2985 - snd_pcm_hw_avail(substream)); 2986 - snd_pcm_stream_unlock_irq(substream); 3040 + scoped_guard(pcm_stream_lock_irq, substream) { 3041 + ret = do_pcm_hwsync(substream); 3042 + if (!ret) 3043 + ret = rewind_appl_ptr(substream, frames, 3044 + snd_pcm_hw_avail(substream)); 3045 + } 2987 3046 if (ret >= 0) 2988 3047 snd_pcm_dma_buffer_sync(substream, SNDRV_DMA_SYNC_DEVICE); 2989 3048 return ret; ··· 2997 3056 if (frames == 0) 2998 3057 return 0; 2999 3058 3000 - snd_pcm_stream_lock_irq(substream); 3001 - ret = do_pcm_hwsync(substream); 3002 - if (!ret) 3003 - ret = forward_appl_ptr(substream, frames, 3004 - snd_pcm_avail(substream)); 3005 - snd_pcm_stream_unlock_irq(substream); 3059 + scoped_guard(pcm_stream_lock_irq, substream) { 3060 + ret = do_pcm_hwsync(substream); 3061 + if (!ret) 3062 + ret = forward_appl_ptr(substream, frames, 3063 + snd_pcm_avail(substream)); 3064 + } 3006 3065 if (ret >= 0) 3007 3066 snd_pcm_dma_buffer_sync(substream, SNDRV_DMA_SYNC_DEVICE); 3008 3067 return ret; ··· 3013 3072 { 3014 3073 int err; 3015 3074 3016 - snd_pcm_stream_lock_irq(substream); 3017 - err = do_pcm_hwsync(substream); 3018 - if (delay && !err) 3019 - *delay = snd_pcm_calc_delay(substream); 3020 - snd_pcm_stream_unlock_irq(substream); 3075 + scoped_guard(pcm_stream_lock_irq, substream) { 3076 + err = do_pcm_hwsync(substream); 3077 + if (delay && !err) 3078 + *delay = snd_pcm_calc_delay(substream); 3079 + } 3021 3080 snd_pcm_dma_buffer_sync(substream, SNDRV_DMA_SYNC_CPU); 3022 3081 3023 3082 return err; ··· 3049 3108 if (err < 0) 3050 3109 return err; 3051 3110 } 3052 - snd_pcm_stream_lock_irq(substream); 3053 - if (!(sync_ptr.flags & SNDRV_PCM_SYNC_PTR_APPL)) { 3054 - err = pcm_lib_apply_appl_ptr(substream, 3055 - sync_ptr.c.control.appl_ptr); 3056 - if (err < 0) { 3057 - snd_pcm_stream_unlock_irq(substream); 3058 - return err; 3111 + scoped_guard(pcm_stream_lock_irq, substream) { 3112 + if (!(sync_ptr.flags & SNDRV_PCM_SYNC_PTR_APPL)) { 3113 + err = pcm_lib_apply_appl_ptr(substream, 3114 + sync_ptr.c.control.appl_ptr); 3115 + if (err < 0) 3116 + return err; 3117 + } else { 3118 + sync_ptr.c.control.appl_ptr = control->appl_ptr; 3059 3119 } 3060 - } else { 3061 - sync_ptr.c.control.appl_ptr = control->appl_ptr; 3120 + if (!(sync_ptr.flags & SNDRV_PCM_SYNC_PTR_AVAIL_MIN)) 3121 + control->avail_min = sync_ptr.c.control.avail_min; 3122 + else 3123 + sync_ptr.c.control.avail_min = control->avail_min; 3124 + sync_ptr.s.status.state = status->state; 3125 + sync_ptr.s.status.hw_ptr = status->hw_ptr; 3126 + sync_ptr.s.status.tstamp = status->tstamp; 3127 + sync_ptr.s.status.suspended_state = status->suspended_state; 3128 + sync_ptr.s.status.audio_tstamp = status->audio_tstamp; 3062 3129 } 3063 - if (!(sync_ptr.flags & SNDRV_PCM_SYNC_PTR_AVAIL_MIN)) 3064 - control->avail_min = sync_ptr.c.control.avail_min; 3065 - else 3066 - sync_ptr.c.control.avail_min = control->avail_min; 3067 - sync_ptr.s.status.state = status->state; 3068 - sync_ptr.s.status.hw_ptr = status->hw_ptr; 3069 - sync_ptr.s.status.tstamp = status->tstamp; 3070 - sync_ptr.s.status.suspended_state = status->suspended_state; 3071 - sync_ptr.s.status.audio_tstamp = status->audio_tstamp; 3072 - snd_pcm_stream_unlock_irq(substream); 3073 3130 if (!(sync_ptr.flags & SNDRV_PCM_SYNC_PTR_APPL)) 3074 3131 snd_pcm_dma_buffer_sync(substream, SNDRV_DMA_SYNC_DEVICE); 3075 3132 if (copy_to_user(_sync_ptr, &sync_ptr, sizeof(sync_ptr))) ··· 3145 3206 boundary = recalculate_boundary(runtime); 3146 3207 if (! boundary) 3147 3208 boundary = 0x7fffffff; 3148 - snd_pcm_stream_lock_irq(substream); 3149 - /* FIXME: we should consider the boundary for the sync from app */ 3150 - if (!(sflags & SNDRV_PCM_SYNC_PTR_APPL)) { 3151 - err = pcm_lib_apply_appl_ptr(substream, 3152 - scontrol.appl_ptr); 3153 - if (err < 0) { 3154 - snd_pcm_stream_unlock_irq(substream); 3155 - return err; 3156 - } 3157 - } else 3158 - scontrol.appl_ptr = control->appl_ptr % boundary; 3159 - if (!(sflags & SNDRV_PCM_SYNC_PTR_AVAIL_MIN)) 3160 - control->avail_min = scontrol.avail_min; 3161 - else 3162 - scontrol.avail_min = control->avail_min; 3163 - sstatus.state = status->state; 3164 - sstatus.hw_ptr = status->hw_ptr % boundary; 3165 - sstatus.tstamp = status->tstamp; 3166 - sstatus.suspended_state = status->suspended_state; 3167 - sstatus.audio_tstamp = status->audio_tstamp; 3168 - snd_pcm_stream_unlock_irq(substream); 3209 + scoped_guard(pcm_stream_lock_irq, substream) { 3210 + /* FIXME: we should consider the boundary for the sync from app */ 3211 + if (!(sflags & SNDRV_PCM_SYNC_PTR_APPL)) { 3212 + err = pcm_lib_apply_appl_ptr(substream, 3213 + scontrol.appl_ptr); 3214 + if (err < 0) 3215 + return err; 3216 + } else 3217 + scontrol.appl_ptr = control->appl_ptr % boundary; 3218 + if (!(sflags & SNDRV_PCM_SYNC_PTR_AVAIL_MIN)) 3219 + control->avail_min = scontrol.avail_min; 3220 + else 3221 + scontrol.avail_min = control->avail_min; 3222 + sstatus.state = status->state; 3223 + sstatus.hw_ptr = status->hw_ptr % boundary; 3224 + sstatus.tstamp = status->tstamp; 3225 + sstatus.suspended_state = status->suspended_state; 3226 + sstatus.audio_tstamp = status->audio_tstamp; 3227 + } 3169 3228 if (!(sflags & SNDRV_PCM_SYNC_PTR_APPL)) 3170 3229 snd_pcm_dma_buffer_sync(substream, SNDRV_DMA_SYNC_DEVICE); 3171 3230 if (put_user(sstatus.state, &src->s.status.state) || ··· 3221 3284 { 3222 3285 struct snd_xfern xfern; 3223 3286 struct snd_pcm_runtime *runtime = substream->runtime; 3224 - void *bufs; 3287 + void *bufs __free(kfree) = NULL; 3225 3288 snd_pcm_sframes_t result; 3226 3289 3227 3290 if (runtime->state == SNDRV_PCM_STATE_OPEN) ··· 3235 3298 3236 3299 bufs = memdup_user(xfern.bufs, sizeof(void *) * runtime->channels); 3237 3300 if (IS_ERR(bufs)) 3238 - return PTR_ERR(bufs); 3301 + return PTR_ERR(no_free_ptr(bufs)); 3239 3302 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 3240 3303 result = snd_pcm_lib_writev(substream, bufs, xfern.frames); 3241 3304 else 3242 3305 result = snd_pcm_lib_readv(substream, bufs, xfern.frames); 3243 - kfree(bufs); 3244 3306 if (put_user(result, &_xfern->result)) 3245 3307 return -EFAULT; 3246 3308 return result < 0 ? result : 0; ··· 3507 3571 struct snd_pcm_runtime *runtime; 3508 3572 snd_pcm_sframes_t result; 3509 3573 unsigned long i; 3510 - void __user **bufs; 3574 + void __user **bufs __free(kfree) = NULL; 3511 3575 snd_pcm_uframes_t frames; 3512 3576 const struct iovec *iov = iter_iov(to); 3513 3577 ··· 3536 3600 result = snd_pcm_lib_readv(substream, bufs, frames); 3537 3601 if (result > 0) 3538 3602 result = frames_to_bytes(runtime, result); 3539 - kfree(bufs); 3540 3603 return result; 3541 3604 } 3542 3605 ··· 3546 3611 struct snd_pcm_runtime *runtime; 3547 3612 snd_pcm_sframes_t result; 3548 3613 unsigned long i; 3549 - void __user **bufs; 3614 + void __user **bufs __free(kfree) = NULL; 3550 3615 snd_pcm_uframes_t frames; 3551 3616 const struct iovec *iov = iter_iov(from); 3552 3617 ··· 3574 3639 result = snd_pcm_lib_writev(substream, bufs, frames); 3575 3640 if (result > 0) 3576 3641 result = frames_to_bytes(runtime, result); 3577 - kfree(bufs); 3578 3642 return result; 3579 3643 } 3580 3644 ··· 3602 3668 poll_wait(file, &runtime->sleep, wait); 3603 3669 3604 3670 mask = 0; 3605 - snd_pcm_stream_lock_irq(substream); 3671 + guard(pcm_stream_lock_irq)(substream); 3606 3672 avail = snd_pcm_avail(substream); 3607 3673 switch (runtime->state) { 3608 3674 case SNDRV_PCM_STATE_RUNNING: ··· 3622 3688 mask = ok | EPOLLERR; 3623 3689 break; 3624 3690 } 3625 - snd_pcm_stream_unlock_irq(substream); 3626 3691 return mask; 3627 3692 } 3628 3693 ··· 4014 4081 static int snd_pcm_hw_refine_old_user(struct snd_pcm_substream *substream, 4015 4082 struct snd_pcm_hw_params_old __user * _oparams) 4016 4083 { 4017 - struct snd_pcm_hw_params *params; 4018 - struct snd_pcm_hw_params_old *oparams = NULL; 4084 + struct snd_pcm_hw_params *params __free(kfree) = NULL; 4085 + struct snd_pcm_hw_params_old *oparams __free(kfree) = NULL; 4019 4086 int err; 4020 4087 4021 4088 params = kmalloc(sizeof(*params), GFP_KERNEL); ··· 4023 4090 return -ENOMEM; 4024 4091 4025 4092 oparams = memdup_user(_oparams, sizeof(*oparams)); 4026 - if (IS_ERR(oparams)) { 4027 - err = PTR_ERR(oparams); 4028 - goto out; 4029 - } 4093 + if (IS_ERR(oparams)) 4094 + return PTR_ERR(no_free_ptr(oparams)); 4030 4095 snd_pcm_hw_convert_from_old_params(params, oparams); 4031 4096 err = snd_pcm_hw_refine(substream, params); 4032 4097 if (err < 0) 4033 - goto out_old; 4098 + return err; 4034 4099 4035 4100 err = fixup_unreferenced_params(substream, params); 4036 4101 if (err < 0) 4037 - goto out_old; 4102 + return err; 4038 4103 4039 4104 snd_pcm_hw_convert_to_old_params(oparams, params); 4040 4105 if (copy_to_user(_oparams, oparams, sizeof(*oparams))) 4041 - err = -EFAULT; 4042 - out_old: 4043 - kfree(oparams); 4044 - out: 4045 - kfree(params); 4046 - return err; 4106 + return -EFAULT; 4107 + return 0; 4047 4108 } 4048 4109 4049 4110 static int snd_pcm_hw_params_old_user(struct snd_pcm_substream *substream, 4050 4111 struct snd_pcm_hw_params_old __user * _oparams) 4051 4112 { 4052 - struct snd_pcm_hw_params *params; 4053 - struct snd_pcm_hw_params_old *oparams = NULL; 4113 + struct snd_pcm_hw_params *params __free(kfree) = NULL; 4114 + struct snd_pcm_hw_params_old *oparams __free(kfree) = NULL; 4054 4115 int err; 4055 4116 4056 4117 params = kmalloc(sizeof(*params), GFP_KERNEL); ··· 4052 4125 return -ENOMEM; 4053 4126 4054 4127 oparams = memdup_user(_oparams, sizeof(*oparams)); 4055 - if (IS_ERR(oparams)) { 4056 - err = PTR_ERR(oparams); 4057 - goto out; 4058 - } 4128 + if (IS_ERR(oparams)) 4129 + return PTR_ERR(no_free_ptr(oparams)); 4059 4130 4060 4131 snd_pcm_hw_convert_from_old_params(params, oparams); 4061 4132 err = snd_pcm_hw_params(substream, params); 4062 4133 if (err < 0) 4063 - goto out_old; 4134 + return err; 4064 4135 4065 4136 snd_pcm_hw_convert_to_old_params(oparams, params); 4066 4137 if (copy_to_user(_oparams, oparams, sizeof(*oparams))) 4067 - err = -EFAULT; 4068 - out_old: 4069 - kfree(oparams); 4070 - out: 4071 - kfree(params); 4072 - return err; 4138 + return -EFAULT; 4139 + return 0; 4073 4140 } 4074 4141 #endif /* CONFIG_SND_SUPPORT_OLD_API */ 4075 4142
+93 -160
sound/core/rawmidi.c
··· 105 105 106 106 static bool snd_rawmidi_ready(struct snd_rawmidi_substream *substream) 107 107 { 108 - unsigned long flags; 109 - bool ready; 110 - 111 - spin_lock_irqsave(&substream->lock, flags); 112 - ready = __snd_rawmidi_ready(substream->runtime); 113 - spin_unlock_irqrestore(&substream->lock, flags); 114 - return ready; 108 + guard(spinlock_irqsave)(&substream->lock); 109 + return __snd_rawmidi_ready(substream->runtime); 115 110 } 116 111 117 112 static inline int snd_rawmidi_ready_append(struct snd_rawmidi_substream *substream, ··· 233 238 static void reset_runtime_ptrs(struct snd_rawmidi_substream *substream, 234 239 bool is_input) 235 240 { 236 - unsigned long flags; 237 - 238 - spin_lock_irqsave(&substream->lock, flags); 241 + guard(spinlock_irqsave)(&substream->lock); 239 242 if (substream->opened && substream->runtime) 240 243 __reset_runtime_ptrs(substream->runtime, is_input); 241 - spin_unlock_irqrestore(&substream->lock, flags); 242 244 } 243 245 244 246 int snd_rawmidi_drop_output(struct snd_rawmidi_substream *substream) ··· 252 260 long timeout; 253 261 struct snd_rawmidi_runtime *runtime; 254 262 255 - spin_lock_irq(&substream->lock); 256 - runtime = substream->runtime; 257 - if (!substream->opened || !runtime || !runtime->buffer) { 258 - err = -EINVAL; 259 - } else { 263 + scoped_guard(spinlock_irq, &substream->lock) { 264 + runtime = substream->runtime; 265 + if (!substream->opened || !runtime || !runtime->buffer) 266 + return -EINVAL; 260 267 snd_rawmidi_buffer_ref(runtime); 261 268 runtime->drain = 1; 262 269 } 263 - spin_unlock_irq(&substream->lock); 264 - if (err < 0) 265 - return err; 266 270 267 271 timeout = wait_event_interruptible_timeout(runtime->sleep, 268 272 (runtime->avail >= runtime->buffer_size), 269 273 10*HZ); 270 274 271 - spin_lock_irq(&substream->lock); 272 - if (signal_pending(current)) 273 - err = -ERESTARTSYS; 274 - if (runtime->avail < runtime->buffer_size && !timeout) { 275 - rmidi_warn(substream->rmidi, 276 - "rawmidi drain error (avail = %li, buffer_size = %li)\n", 277 - (long)runtime->avail, (long)runtime->buffer_size); 278 - err = -EIO; 275 + scoped_guard(spinlock_irq, &substream->lock) { 276 + if (signal_pending(current)) 277 + err = -ERESTARTSYS; 278 + if (runtime->avail < runtime->buffer_size && !timeout) { 279 + rmidi_warn(substream->rmidi, 280 + "rawmidi drain error (avail = %li, buffer_size = %li)\n", 281 + (long)runtime->avail, (long)runtime->buffer_size); 282 + err = -EIO; 283 + } 284 + runtime->drain = 0; 279 285 } 280 - runtime->drain = 0; 281 - spin_unlock_irq(&substream->lock); 282 286 283 287 if (err != -ERESTARTSYS) { 284 288 /* we need wait a while to make sure that Tx FIFOs are empty */ ··· 285 297 snd_rawmidi_drop_output(substream); 286 298 } 287 299 288 - spin_lock_irq(&substream->lock); 289 - snd_rawmidi_buffer_unref(runtime); 290 - spin_unlock_irq(&substream->lock); 300 + scoped_guard(spinlock_irq, &substream->lock) 301 + snd_rawmidi_buffer_unref(runtime); 291 302 292 303 return err; 293 304 } ··· 350 363 snd_rawmidi_runtime_free(substream); 351 364 return err; 352 365 } 353 - spin_lock_irq(&substream->lock); 366 + guard(spinlock_irq)(&substream->lock); 354 367 substream->opened = 1; 355 368 substream->active_sensing = 0; 356 369 if (mode & SNDRV_RAWMIDI_LFLG_APPEND) 357 370 substream->append = 1; 358 371 substream->pid = get_pid(task_pid(current)); 359 372 rmidi->streams[substream->stream].substream_opened++; 360 - spin_unlock_irq(&substream->lock); 361 373 } 362 374 substream->use_count++; 363 375 return 0; ··· 419 433 if (!try_module_get(rmidi->card->module)) 420 434 return -ENXIO; 421 435 422 - mutex_lock(&rmidi->open_mutex); 436 + guard(mutex)(&rmidi->open_mutex); 423 437 err = rawmidi_open_priv(rmidi, subdevice, mode, rfile); 424 - mutex_unlock(&rmidi->open_mutex); 425 438 if (err < 0) 426 439 module_put(rmidi->card->module); 427 440 return err; ··· 553 568 } 554 569 snd_rawmidi_buffer_ref_sync(substream); 555 570 } 556 - spin_lock_irq(&substream->lock); 557 - substream->opened = 0; 558 - substream->append = 0; 559 - spin_unlock_irq(&substream->lock); 571 + scoped_guard(spinlock_irq, &substream->lock) { 572 + substream->opened = 0; 573 + substream->append = 0; 574 + } 560 575 substream->ops->close(substream); 561 576 if (substream->runtime->private_free) 562 577 substream->runtime->private_free(substream); ··· 571 586 struct snd_rawmidi *rmidi; 572 587 573 588 rmidi = rfile->rmidi; 574 - mutex_lock(&rmidi->open_mutex); 589 + guard(mutex)(&rmidi->open_mutex); 575 590 if (rfile->input) { 576 591 close_substream(rmidi, rfile->input, 1); 577 592 rfile->input = NULL; ··· 581 596 rfile->output = NULL; 582 597 } 583 598 rfile->rmidi = NULL; 584 - mutex_unlock(&rmidi->open_mutex); 585 599 wake_up(&rmidi->open_wait); 586 600 } 587 601 ··· 679 695 680 696 int snd_rawmidi_info_select(struct snd_card *card, struct snd_rawmidi_info *info) 681 697 { 682 - int ret; 683 - 684 - mutex_lock(&register_mutex); 685 - ret = __snd_rawmidi_info_select(card, info); 686 - mutex_unlock(&register_mutex); 687 - return ret; 698 + guard(mutex)(&register_mutex); 699 + return __snd_rawmidi_info_select(card, info); 688 700 } 689 701 EXPORT_SYMBOL(snd_rawmidi_info_select); 690 702 ··· 724 744 newbuf = kvzalloc(params->buffer_size, GFP_KERNEL); 725 745 if (!newbuf) 726 746 return -ENOMEM; 727 - spin_lock_irq(&substream->lock); 747 + guard(spinlock_irq)(&substream->lock); 728 748 if (runtime->buffer_ref) { 729 - spin_unlock_irq(&substream->lock); 730 749 kvfree(newbuf); 731 750 return -EBUSY; 732 751 } ··· 733 754 runtime->buffer = newbuf; 734 755 runtime->buffer_size = params->buffer_size; 735 756 __reset_runtime_ptrs(runtime, is_input); 736 - spin_unlock_irq(&substream->lock); 737 757 kvfree(oldbuf); 738 758 } 739 759 runtime->avail_min = params->avail_min; ··· 745 767 int err; 746 768 747 769 snd_rawmidi_drain_output(substream); 748 - mutex_lock(&substream->rmidi->open_mutex); 770 + guard(mutex)(&substream->rmidi->open_mutex); 749 771 if (substream->append && substream->use_count > 1) 750 - err = -EBUSY; 751 - else 752 - err = resize_runtime_buffer(substream, params, false); 753 - 772 + return -EBUSY; 773 + err = resize_runtime_buffer(substream, params, false); 754 774 if (!err) 755 775 substream->active_sensing = !params->no_active_sensing; 756 - mutex_unlock(&substream->rmidi->open_mutex); 757 776 return err; 758 777 } 759 778 EXPORT_SYMBOL(snd_rawmidi_output_params); ··· 763 788 int err; 764 789 765 790 snd_rawmidi_drain_input(substream); 766 - mutex_lock(&substream->rmidi->open_mutex); 791 + guard(mutex)(&substream->rmidi->open_mutex); 767 792 if (framing == SNDRV_RAWMIDI_MODE_FRAMING_NONE && clock_type != SNDRV_RAWMIDI_MODE_CLOCK_NONE) 768 793 err = -EINVAL; 769 794 else if (clock_type > SNDRV_RAWMIDI_MODE_CLOCK_MONOTONIC_RAW) ··· 777 802 substream->framing = framing; 778 803 substream->clock_type = clock_type; 779 804 } 780 - mutex_unlock(&substream->rmidi->open_mutex); 781 805 return 0; 782 806 } 783 807 EXPORT_SYMBOL(snd_rawmidi_input_params); ··· 788 814 789 815 memset(status, 0, sizeof(*status)); 790 816 status->stream = SNDRV_RAWMIDI_STREAM_OUTPUT; 791 - spin_lock_irq(&substream->lock); 817 + guard(spinlock_irq)(&substream->lock); 792 818 status->avail = runtime->avail; 793 - spin_unlock_irq(&substream->lock); 794 819 return 0; 795 820 } 796 821 ··· 800 827 801 828 memset(status, 0, sizeof(*status)); 802 829 status->stream = SNDRV_RAWMIDI_STREAM_INPUT; 803 - spin_lock_irq(&substream->lock); 830 + guard(spinlock_irq)(&substream->lock); 804 831 status->avail = runtime->avail; 805 832 status->xruns = runtime->xruns; 806 833 runtime->xruns = 0; 807 - spin_unlock_irq(&substream->lock); 808 834 return 0; 809 835 } 810 836 ··· 997 1025 return -EFAULT; 998 1026 if (device >= SNDRV_RAWMIDI_DEVICES) /* next device is -1 */ 999 1027 device = SNDRV_RAWMIDI_DEVICES - 1; 1000 - mutex_lock(&register_mutex); 1001 - device = device < 0 ? 0 : device + 1; 1002 - for (; device < SNDRV_RAWMIDI_DEVICES; device++) { 1003 - rmidi = snd_rawmidi_search(card, device); 1004 - if (!rmidi) 1005 - continue; 1006 - is_ump = rawmidi_is_ump(rmidi); 1007 - if (find_ump == is_ump) 1008 - break; 1028 + scoped_guard(mutex, &register_mutex) { 1029 + device = device < 0 ? 0 : device + 1; 1030 + for (; device < SNDRV_RAWMIDI_DEVICES; device++) { 1031 + rmidi = snd_rawmidi_search(card, device); 1032 + if (!rmidi) 1033 + continue; 1034 + is_ump = rawmidi_is_ump(rmidi); 1035 + if (find_ump == is_ump) 1036 + break; 1037 + } 1038 + if (device == SNDRV_RAWMIDI_DEVICES) 1039 + device = -1; 1009 1040 } 1010 - if (device == SNDRV_RAWMIDI_DEVICES) 1011 - device = -1; 1012 - mutex_unlock(&register_mutex); 1013 1041 if (put_user(device, argp)) 1014 1042 return -EFAULT; 1015 1043 return 0; ··· 1022 1050 { 1023 1051 struct snd_ump_endpoint_info __user *info = argp; 1024 1052 struct snd_rawmidi *rmidi; 1025 - int device, ret; 1053 + int device; 1026 1054 1027 1055 if (get_user(device, &info->device)) 1028 1056 return -EFAULT; 1029 - mutex_lock(&register_mutex); 1057 + guard(mutex)(&register_mutex); 1030 1058 rmidi = snd_rawmidi_search(card, device); 1031 1059 if (rmidi && rmidi->ops && rmidi->ops->ioctl) 1032 - ret = rmidi->ops->ioctl(rmidi, cmd, argp); 1060 + return rmidi->ops->ioctl(rmidi, cmd, argp); 1033 1061 else 1034 - ret = -ENXIO; 1035 - mutex_unlock(&register_mutex); 1036 - return ret; 1062 + return -ENXIO; 1037 1063 } 1038 1064 #endif 1039 1065 ··· 1138 1168 int snd_rawmidi_receive(struct snd_rawmidi_substream *substream, 1139 1169 const unsigned char *buffer, int count) 1140 1170 { 1141 - unsigned long flags; 1142 1171 struct timespec64 ts64 = get_framing_tstamp(substream); 1143 1172 int result = 0, count1; 1144 1173 struct snd_rawmidi_runtime *runtime; 1145 1174 1146 - spin_lock_irqsave(&substream->lock, flags); 1147 - if (!substream->opened) { 1148 - result = -EBADFD; 1149 - goto unlock; 1150 - } 1175 + guard(spinlock_irqsave)(&substream->lock); 1176 + if (!substream->opened) 1177 + return -EBADFD; 1151 1178 runtime = substream->runtime; 1152 1179 if (!runtime || !runtime->buffer) { 1153 1180 rmidi_dbg(substream->rmidi, 1154 1181 "snd_rawmidi_receive: input is not active!!!\n"); 1155 - result = -EINVAL; 1156 - goto unlock; 1182 + return -EINVAL; 1157 1183 } 1158 1184 1159 1185 count = get_aligned_size(runtime, count); 1160 1186 if (!count) 1161 - goto unlock; 1187 + return result; 1162 1188 1163 1189 if (substream->framing == SNDRV_RAWMIDI_MODE_FRAMING_TSTAMP) { 1164 1190 result = receive_with_tstamp_framing(substream, buffer, count, &ts64); ··· 1177 1211 count1 = runtime->buffer_size - runtime->avail; 1178 1212 count1 = get_aligned_size(runtime, count1); 1179 1213 if (!count1) 1180 - goto unlock; 1214 + return result; 1181 1215 memcpy(runtime->buffer + runtime->hw_ptr, buffer, count1); 1182 1216 runtime->hw_ptr += count1; 1183 1217 runtime->hw_ptr %= runtime->buffer_size; ··· 1205 1239 else if (__snd_rawmidi_ready(runtime)) 1206 1240 wake_up(&runtime->sleep); 1207 1241 } 1208 - unlock: 1209 - spin_unlock_irqrestore(&substream->lock, flags); 1210 1242 return result; 1211 1243 } 1212 1244 EXPORT_SYMBOL(snd_rawmidi_receive); ··· 1326 1362 int snd_rawmidi_transmit_empty(struct snd_rawmidi_substream *substream) 1327 1363 { 1328 1364 struct snd_rawmidi_runtime *runtime; 1329 - int result; 1330 - unsigned long flags; 1331 1365 1332 - spin_lock_irqsave(&substream->lock, flags); 1366 + guard(spinlock_irqsave)(&substream->lock); 1333 1367 runtime = substream->runtime; 1334 1368 if (!substream->opened || !runtime || !runtime->buffer) { 1335 1369 rmidi_dbg(substream->rmidi, 1336 1370 "snd_rawmidi_transmit_empty: output is not active!!!\n"); 1337 - result = 1; 1338 - } else { 1339 - result = runtime->avail >= runtime->buffer_size; 1371 + return 1; 1340 1372 } 1341 - spin_unlock_irqrestore(&substream->lock, flags); 1342 - return result; 1373 + return (runtime->avail >= runtime->buffer_size); 1343 1374 } 1344 1375 EXPORT_SYMBOL(snd_rawmidi_transmit_empty); 1345 1376 ··· 1408 1449 int snd_rawmidi_transmit_peek(struct snd_rawmidi_substream *substream, 1409 1450 unsigned char *buffer, int count) 1410 1451 { 1411 - int result; 1412 - unsigned long flags; 1413 - 1414 - spin_lock_irqsave(&substream->lock, flags); 1452 + guard(spinlock_irqsave)(&substream->lock); 1415 1453 if (!substream->opened || !substream->runtime) 1416 - result = -EBADFD; 1417 - else 1418 - result = __snd_rawmidi_transmit_peek(substream, buffer, count); 1419 - spin_unlock_irqrestore(&substream->lock, flags); 1420 - return result; 1454 + return -EBADFD; 1455 + return __snd_rawmidi_transmit_peek(substream, buffer, count); 1421 1456 } 1422 1457 EXPORT_SYMBOL(snd_rawmidi_transmit_peek); 1423 1458 ··· 1458 1505 */ 1459 1506 int snd_rawmidi_transmit_ack(struct snd_rawmidi_substream *substream, int count) 1460 1507 { 1461 - int result; 1462 - unsigned long flags; 1463 - 1464 - spin_lock_irqsave(&substream->lock, flags); 1508 + guard(spinlock_irqsave)(&substream->lock); 1465 1509 if (!substream->opened || !substream->runtime) 1466 - result = -EBADFD; 1467 - else 1468 - result = __snd_rawmidi_transmit_ack(substream, count); 1469 - spin_unlock_irqrestore(&substream->lock, flags); 1470 - return result; 1510 + return -EBADFD; 1511 + return __snd_rawmidi_transmit_ack(substream, count); 1471 1512 } 1472 1513 EXPORT_SYMBOL(snd_rawmidi_transmit_ack); 1473 1514 ··· 1478 1531 int snd_rawmidi_transmit(struct snd_rawmidi_substream *substream, 1479 1532 unsigned char *buffer, int count) 1480 1533 { 1481 - int result; 1482 - unsigned long flags; 1483 - 1484 - spin_lock_irqsave(&substream->lock, flags); 1534 + guard(spinlock_irqsave)(&substream->lock); 1485 1535 if (!substream->opened) 1486 - result = -EBADFD; 1487 - else { 1488 - count = __snd_rawmidi_transmit_peek(substream, buffer, count); 1489 - if (count <= 0) 1490 - result = count; 1491 - else 1492 - result = __snd_rawmidi_transmit_ack(substream, count); 1493 - } 1494 - spin_unlock_irqrestore(&substream->lock, flags); 1495 - return result; 1536 + return -EBADFD; 1537 + count = __snd_rawmidi_transmit_peek(substream, buffer, count); 1538 + if (count <= 0) 1539 + return count; 1540 + return __snd_rawmidi_transmit_ack(substream, count); 1496 1541 } 1497 1542 EXPORT_SYMBOL(snd_rawmidi_transmit); 1498 1543 ··· 1497 1558 int snd_rawmidi_proceed(struct snd_rawmidi_substream *substream) 1498 1559 { 1499 1560 struct snd_rawmidi_runtime *runtime; 1500 - unsigned long flags; 1501 1561 int count = 0; 1502 1562 1503 - spin_lock_irqsave(&substream->lock, flags); 1563 + guard(spinlock_irqsave)(&substream->lock); 1504 1564 runtime = substream->runtime; 1505 1565 if (substream->opened && runtime && 1506 1566 runtime->avail < runtime->buffer_size) { 1507 1567 count = runtime->buffer_size - runtime->avail; 1508 1568 __snd_rawmidi_transmit_ack(substream, count); 1509 1569 } 1510 - spin_unlock_irqrestore(&substream->lock, flags); 1511 1570 return count; 1512 1571 } 1513 1572 EXPORT_SYMBOL(snd_rawmidi_proceed); ··· 1709 1772 rawmidi_is_ump(rmidi) ? "UMP" : "Legacy"); 1710 1773 if (rmidi->ops && rmidi->ops->proc_read) 1711 1774 rmidi->ops->proc_read(entry, buffer); 1712 - mutex_lock(&rmidi->open_mutex); 1775 + guard(mutex)(&rmidi->open_mutex); 1713 1776 if (rmidi->info_flags & SNDRV_RAWMIDI_INFO_OUTPUT) { 1714 1777 list_for_each_entry(substream, 1715 1778 &rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT].substreams, ··· 1724 1787 " Owner PID : %d\n", 1725 1788 pid_vnr(substream->pid)); 1726 1789 runtime = substream->runtime; 1727 - spin_lock_irq(&substream->lock); 1728 - buffer_size = runtime->buffer_size; 1729 - avail = runtime->avail; 1730 - spin_unlock_irq(&substream->lock); 1790 + scoped_guard(spinlock_irq, &substream->lock) { 1791 + buffer_size = runtime->buffer_size; 1792 + avail = runtime->avail; 1793 + } 1731 1794 snd_iprintf(buffer, 1732 1795 " Mode : %s\n" 1733 1796 " Buffer size : %lu\n" ··· 1751 1814 " Owner PID : %d\n", 1752 1815 pid_vnr(substream->pid)); 1753 1816 runtime = substream->runtime; 1754 - spin_lock_irq(&substream->lock); 1755 - buffer_size = runtime->buffer_size; 1756 - avail = runtime->avail; 1757 - xruns = runtime->xruns; 1758 - spin_unlock_irq(&substream->lock); 1817 + scoped_guard(spinlock_irq, &substream->lock) { 1818 + buffer_size = runtime->buffer_size; 1819 + avail = runtime->avail; 1820 + xruns = runtime->xruns; 1821 + } 1759 1822 snd_iprintf(buffer, 1760 1823 " Buffer size : %lu\n" 1761 1824 " Avail : %lu\n" ··· 1772 1835 } 1773 1836 } 1774 1837 } 1775 - mutex_unlock(&rmidi->open_mutex); 1776 1838 } 1777 1839 1778 1840 /* ··· 1960 2024 if (rmidi->device >= SNDRV_RAWMIDI_DEVICES) 1961 2025 return -ENOMEM; 1962 2026 err = 0; 1963 - mutex_lock(&register_mutex); 1964 - if (snd_rawmidi_search(rmidi->card, rmidi->device)) 1965 - err = -EBUSY; 1966 - else 1967 - list_add_tail(&rmidi->list, &snd_rawmidi_devices); 1968 - mutex_unlock(&register_mutex); 2027 + scoped_guard(mutex, &register_mutex) { 2028 + if (snd_rawmidi_search(rmidi->card, rmidi->device)) 2029 + err = -EBUSY; 2030 + else 2031 + list_add_tail(&rmidi->list, &snd_rawmidi_devices); 2032 + } 1969 2033 if (err < 0) 1970 2034 return err; 1971 2035 ··· 2038 2102 error_unregister: 2039 2103 snd_unregister_device(rmidi->dev); 2040 2104 error: 2041 - mutex_lock(&register_mutex); 2042 - list_del(&rmidi->list); 2043 - mutex_unlock(&register_mutex); 2105 + scoped_guard(mutex, &register_mutex) 2106 + list_del(&rmidi->list); 2044 2107 return err; 2045 2108 } 2046 2109 ··· 2048 2113 struct snd_rawmidi *rmidi = device->device_data; 2049 2114 int dir; 2050 2115 2051 - mutex_lock(&register_mutex); 2052 - mutex_lock(&rmidi->open_mutex); 2116 + guard(mutex)(&register_mutex); 2117 + guard(mutex)(&rmidi->open_mutex); 2053 2118 wake_up(&rmidi->open_wait); 2054 2119 list_del_init(&rmidi->list); 2055 2120 for (dir = 0; dir < 2; dir++) { ··· 2075 2140 } 2076 2141 #endif /* CONFIG_SND_OSSEMUL */ 2077 2142 snd_unregister_device(rmidi->dev); 2078 - mutex_unlock(&rmidi->open_mutex); 2079 - mutex_unlock(&register_mutex); 2080 2143 return 0; 2081 2144 } 2082 2145
-1
sound/core/seq/Kconfig
··· 71 71 among legacy and UMP clients. 72 72 73 73 config SND_SEQ_UMP_CLIENT 74 - tristate 75 74 def_tristate SND_UMP 76 75 77 76 endif # SND_SEQUENCER
+1 -1
sound/core/seq/oss/seq_oss_device.h
··· 163 163 164 164 165 165 /* misc. functions for proc interface */ 166 - char *enabled_str(int bool); 166 + char *enabled_str(bool b); 167 167 168 168 #endif /* __SEQ_OSS_DEVICE_H */
+7 -12
sound/core/seq/oss/seq_oss_init.c
··· 63 63 snd_seq_oss_create_client(void) 64 64 { 65 65 int rc; 66 - struct snd_seq_port_info *port; 66 + struct snd_seq_port_info *port __free(kfree) = NULL; 67 67 struct snd_seq_port_callback port_callback; 68 68 69 69 port = kzalloc(sizeof(*port), GFP_KERNEL); 70 - if (!port) { 71 - rc = -ENOMEM; 72 - goto __error; 73 - } 70 + if (!port) 71 + return -ENOMEM; 74 72 75 73 /* create ALSA client */ 76 74 rc = snd_seq_create_kernel_client(NULL, SNDRV_SEQ_CLIENT_OSS, 77 75 "OSS sequencer"); 78 76 if (rc < 0) 79 - goto __error; 77 + return rc; 80 78 81 79 system_client = rc; 82 80 ··· 102 104 subs.dest.port = system_port; 103 105 call_ctl(SNDRV_SEQ_IOCTL_SUBSCRIBE_PORT, &subs); 104 106 } 105 - rc = 0; 106 107 107 108 /* look up midi devices */ 108 109 schedule_work(&async_lookup_work); 109 110 110 - __error: 111 - kfree(port); 112 - return rc; 111 + return 0; 113 112 } 114 113 115 114 ··· 450 455 * misc. functions for proc interface 451 456 */ 452 457 char * 453 - enabled_str(int bool) 458 + enabled_str(bool b) 454 459 { 455 - return bool ? "enabled" : "disabled"; 460 + return b ? "enabled" : "disabled"; 456 461 } 457 462 458 463 static const char *
+3 -8
sound/core/seq/oss/seq_oss_midi.c
··· 64 64 int 65 65 snd_seq_oss_midi_lookup_ports(int client) 66 66 { 67 - struct snd_seq_client_info *clinfo; 68 - struct snd_seq_port_info *pinfo; 67 + struct snd_seq_client_info *clinfo __free(kfree) = NULL; 68 + struct snd_seq_port_info *pinfo __free(kfree) = NULL; 69 69 70 70 clinfo = kzalloc(sizeof(*clinfo), GFP_KERNEL); 71 71 pinfo = kzalloc(sizeof(*pinfo), GFP_KERNEL); 72 - if (! clinfo || ! pinfo) { 73 - kfree(clinfo); 74 - kfree(pinfo); 72 + if (!clinfo || !pinfo) 75 73 return -ENOMEM; 76 - } 77 74 clinfo->client = -1; 78 75 while (snd_seq_kernel_client_ctl(client, SNDRV_SEQ_IOCTL_QUERY_NEXT_CLIENT, clinfo) == 0) { 79 76 if (clinfo->client == client) ··· 80 83 while (snd_seq_kernel_client_ctl(client, SNDRV_SEQ_IOCTL_QUERY_NEXT_PORT, pinfo) == 0) 81 84 snd_seq_oss_midi_check_new_port(pinfo); 82 85 } 83 - kfree(clinfo); 84 - kfree(pinfo); 85 86 return 0; 86 87 } 87 88
+5 -7
sound/core/seq/seq_compat.c
··· 31 31 static int snd_seq_call_port_info_ioctl(struct snd_seq_client *client, unsigned int cmd, 32 32 struct snd_seq_port_info32 __user *data32) 33 33 { 34 - int err = -EFAULT; 35 - struct snd_seq_port_info *data; 34 + struct snd_seq_port_info *data __free(kfree) = NULL; 35 + int err; 36 36 37 37 data = kmalloc(sizeof(*data), GFP_KERNEL); 38 38 if (!data) ··· 41 41 if (copy_from_user(data, data32, sizeof(*data32)) || 42 42 get_user(data->flags, &data32->flags) || 43 43 get_user(data->time_queue, &data32->time_queue)) 44 - goto error; 44 + return -EFAULT; 45 45 data->kernel = NULL; 46 46 47 47 err = snd_seq_kernel_client_ctl(client->number, cmd, data); 48 48 if (err < 0) 49 - goto error; 49 + return err; 50 50 51 51 if (copy_to_user(data32, data, sizeof(*data32)) || 52 52 put_user(data->flags, &data32->flags) || 53 53 put_user(data->time_queue, &data32->time_queue)) 54 - err = -EFAULT; 54 + return -EFAULT; 55 55 56 - error: 57 - kfree(data); 58 56 return err; 59 57 } 60 58
+24 -31
sound/core/seq/seq_fifo.c
··· 88 88 atomic_set(&f->overflow, 0); 89 89 90 90 snd_use_lock_sync(&f->use_lock); 91 - spin_lock_irq(&f->lock); 91 + guard(spinlock_irq)(&f->lock); 92 92 /* drain the fifo */ 93 93 while ((cell = fifo_cell_out(f)) != NULL) { 94 94 snd_seq_cell_free(cell); 95 95 } 96 - spin_unlock_irq(&f->lock); 97 96 } 98 97 99 98 ··· 101 102 struct snd_seq_event *event) 102 103 { 103 104 struct snd_seq_event_cell *cell; 104 - unsigned long flags; 105 105 int err; 106 106 107 107 if (snd_BUG_ON(!f)) ··· 116 118 } 117 119 118 120 /* append new cells to fifo */ 119 - spin_lock_irqsave(&f->lock, flags); 120 - if (f->tail != NULL) 121 - f->tail->next = cell; 122 - f->tail = cell; 123 - if (f->head == NULL) 124 - f->head = cell; 125 - cell->next = NULL; 126 - f->cells++; 127 - spin_unlock_irqrestore(&f->lock, flags); 121 + scoped_guard(spinlock_irqsave, &f->lock) { 122 + if (f->tail != NULL) 123 + f->tail->next = cell; 124 + f->tail = cell; 125 + if (f->head == NULL) 126 + f->head = cell; 127 + cell->next = NULL; 128 + f->cells++; 129 + } 128 130 129 131 /* wakeup client */ 130 132 if (waitqueue_active(&f->input_sleep)) ··· 197 199 void snd_seq_fifo_cell_putback(struct snd_seq_fifo *f, 198 200 struct snd_seq_event_cell *cell) 199 201 { 200 - unsigned long flags; 201 - 202 202 if (cell) { 203 - spin_lock_irqsave(&f->lock, flags); 203 + guard(spinlock_irqsave)(&f->lock); 204 204 cell->next = f->head; 205 205 f->head = cell; 206 206 if (!f->tail) 207 207 f->tail = cell; 208 208 f->cells++; 209 - spin_unlock_irqrestore(&f->lock, flags); 210 209 } 211 210 } 212 211 ··· 234 239 return -ENOMEM; 235 240 } 236 241 237 - spin_lock_irq(&f->lock); 238 - /* remember old pool */ 239 - oldpool = f->pool; 240 - oldhead = f->head; 241 - /* exchange pools */ 242 - f->pool = newpool; 243 - f->head = NULL; 244 - f->tail = NULL; 245 - f->cells = 0; 246 - /* NOTE: overflow flag is not cleared */ 247 - spin_unlock_irq(&f->lock); 242 + scoped_guard(spinlock_irq, &f->lock) { 243 + /* remember old pool */ 244 + oldpool = f->pool; 245 + oldhead = f->head; 246 + /* exchange pools */ 247 + f->pool = newpool; 248 + f->head = NULL; 249 + f->tail = NULL; 250 + f->cells = 0; 251 + /* NOTE: overflow flag is not cleared */ 252 + } 248 253 249 254 /* close the old pool and wait until all users are gone */ 250 255 snd_seq_pool_mark_closing(oldpool); ··· 263 268 /* get the number of unused cells safely */ 264 269 int snd_seq_fifo_unused_cells(struct snd_seq_fifo *f) 265 270 { 266 - unsigned long flags; 267 271 int cells; 268 272 269 273 if (!f) 270 274 return 0; 271 275 272 276 snd_use_lock_use(&f->use_lock); 273 - spin_lock_irqsave(&f->lock, flags); 274 - cells = snd_seq_unused_cells(f->pool); 275 - spin_unlock_irqrestore(&f->lock, flags); 277 + scoped_guard(spinlock_irqsave, &f->lock) 278 + cells = snd_seq_unused_cells(f->pool); 276 279 snd_use_lock_free(&f->use_lock); 277 280 return cells; 278 281 }
+10 -18
sound/core/seq/seq_memory.c
··· 232 232 233 233 void snd_seq_cell_free(struct snd_seq_event_cell * cell) 234 234 { 235 - unsigned long flags; 236 235 struct snd_seq_pool *pool; 237 236 238 237 if (snd_BUG_ON(!cell)) ··· 240 241 if (snd_BUG_ON(!pool)) 241 242 return; 242 243 243 - spin_lock_irqsave(&pool->lock, flags); 244 + guard(spinlock_irqsave)(&pool->lock); 244 245 free_cell(pool, cell); 245 246 if (snd_seq_ev_is_variable(&cell->event)) { 246 247 if (cell->event.data.ext.len & SNDRV_SEQ_EXT_CHAINED) { ··· 258 259 if (snd_seq_output_ok(pool)) 259 260 wake_up(&pool->output_sleep); 260 261 } 261 - spin_unlock_irqrestore(&pool->lock, flags); 262 262 } 263 263 264 264 ··· 447 449 return -ENOMEM; 448 450 449 451 /* add new cells to the free cell list */ 450 - spin_lock_irq(&pool->lock); 452 + guard(spinlock_irq)(&pool->lock); 451 453 if (pool->ptr) { 452 - spin_unlock_irq(&pool->lock); 453 454 kvfree(cellptr); 454 455 return 0; 455 456 } ··· 467 470 /* init statistics */ 468 471 pool->max_used = 0; 469 472 pool->total_elements = pool->size; 470 - spin_unlock_irq(&pool->lock); 471 473 return 0; 472 474 } 473 475 474 476 /* refuse the further insertion to the pool */ 475 477 void snd_seq_pool_mark_closing(struct snd_seq_pool *pool) 476 478 { 477 - unsigned long flags; 478 - 479 479 if (snd_BUG_ON(!pool)) 480 480 return; 481 - spin_lock_irqsave(&pool->lock, flags); 481 + guard(spinlock_irqsave)(&pool->lock); 482 482 pool->closing = 1; 483 - spin_unlock_irqrestore(&pool->lock, flags); 484 483 } 485 484 486 485 /* remove events */ ··· 495 502 schedule_timeout_uninterruptible(1); 496 503 497 504 /* release all resources */ 498 - spin_lock_irq(&pool->lock); 499 - ptr = pool->ptr; 500 - pool->ptr = NULL; 501 - pool->free = NULL; 502 - pool->total_elements = 0; 503 - spin_unlock_irq(&pool->lock); 505 + scoped_guard(spinlock_irq, &pool->lock) { 506 + ptr = pool->ptr; 507 + pool->ptr = NULL; 508 + pool->free = NULL; 509 + pool->total_elements = 0; 510 + } 504 511 505 512 kvfree(ptr); 506 513 507 - spin_lock_irq(&pool->lock); 514 + guard(spinlock_irq)(&pool->lock); 508 515 pool->closing = 0; 509 - spin_unlock_irq(&pool->lock); 510 516 511 517 return 0; 512 518 }
+14 -24
sound/core/seq/seq_midi.c
··· 113 113 return 0; 114 114 } 115 115 116 + /* callback for snd_seq_dump_var_event(), bridging to dump_midi() */ 117 + static int __dump_midi(void *ptr, void *buf, int count) 118 + { 119 + return dump_midi(ptr, buf, count); 120 + } 121 + 116 122 static int event_process_midi(struct snd_seq_event *ev, int direct, 117 123 void *private_data, int atomic, int hop) 118 124 { ··· 138 132 pr_debug("ALSA: seq_midi: invalid sysex event flags = 0x%x\n", ev->flags); 139 133 return 0; 140 134 } 141 - snd_seq_dump_var_event(ev, (snd_seq_dump_func_t)dump_midi, substream); 135 + snd_seq_dump_var_event(ev, __dump_midi, substream); 142 136 snd_midi_event_reset_decode(msynth->parser); 143 137 } else { 144 138 if (msynth->parser == NULL) ··· 270 264 struct snd_seq_device *dev = to_seq_dev(_dev); 271 265 struct seq_midisynth_client *client; 272 266 struct seq_midisynth *msynth, *ms; 273 - struct snd_seq_port_info *port; 274 - struct snd_rawmidi_info *info; 267 + struct snd_seq_port_info *port __free(kfree) = NULL; 268 + struct snd_rawmidi_info *info __free(kfree) = NULL; 275 269 struct snd_rawmidi *rmidi = dev->private_data; 276 270 int newclient = 0; 277 271 unsigned int p, ports; ··· 297 291 ports = output_count; 298 292 if (ports < input_count) 299 293 ports = input_count; 300 - if (ports == 0) { 301 - kfree(info); 294 + if (ports == 0) 302 295 return -ENODEV; 303 - } 304 296 if (ports > (256 / SNDRV_RAWMIDI_DEVICES)) 305 297 ports = 256 / SNDRV_RAWMIDI_DEVICES; 306 298 307 - mutex_lock(&register_mutex); 299 + guard(mutex)(&register_mutex); 308 300 client = synths[card->number]; 309 301 if (client == NULL) { 310 302 newclient = 1; 311 303 client = kzalloc(sizeof(*client), GFP_KERNEL); 312 - if (client == NULL) { 313 - mutex_unlock(&register_mutex); 314 - kfree(info); 304 + if (client == NULL) 315 305 return -ENOMEM; 316 - } 317 306 client->seq_client = 318 307 snd_seq_create_kernel_client( 319 308 card, 0, "%s", card->shortname[0] ? 320 309 (const char *)card->shortname : "External MIDI"); 321 310 if (client->seq_client < 0) { 322 311 kfree(client); 323 - mutex_unlock(&register_mutex); 324 - kfree(info); 325 312 return -ENOMEM; 326 313 } 327 314 } ··· 395 396 client->num_ports++; 396 397 if (newclient) 397 398 synths[card->number] = client; 398 - mutex_unlock(&register_mutex); 399 - kfree(info); 400 - kfree(port); 401 399 return 0; /* success */ 402 400 403 401 __nomem: ··· 407 411 snd_seq_delete_kernel_client(client->seq_client); 408 412 kfree(client); 409 413 } 410 - kfree(info); 411 - kfree(port); 412 - mutex_unlock(&register_mutex); 413 414 return -ENOMEM; 414 415 } 415 416 ··· 420 427 struct snd_card *card = dev->card; 421 428 int device = dev->device, p, ports; 422 429 423 - mutex_lock(&register_mutex); 430 + guard(mutex)(&register_mutex); 424 431 client = synths[card->number]; 425 - if (client == NULL || client->ports[device] == NULL) { 426 - mutex_unlock(&register_mutex); 432 + if (client == NULL || client->ports[device] == NULL) 427 433 return -ENODEV; 428 - } 429 434 ports = client->ports_per_device[device]; 430 435 client->ports_per_device[device] = 0; 431 436 msynth = client->ports[device]; ··· 437 446 synths[card->number] = NULL; 438 447 kfree(client); 439 448 } 440 - mutex_unlock(&register_mutex); 441 449 return 0; 442 450 } 443 451
+3 -11
sound/core/seq/seq_midi_event.c
··· 144 144 145 145 void snd_midi_event_reset_encode(struct snd_midi_event *dev) 146 146 { 147 - unsigned long flags; 148 - 149 - spin_lock_irqsave(&dev->lock, flags); 147 + guard(spinlock_irqsave)(&dev->lock); 150 148 reset_encode(dev); 151 - spin_unlock_irqrestore(&dev->lock, flags); 152 149 } 153 150 EXPORT_SYMBOL(snd_midi_event_reset_encode); 154 151 155 152 void snd_midi_event_reset_decode(struct snd_midi_event *dev) 156 153 { 157 - unsigned long flags; 158 - 159 - spin_lock_irqsave(&dev->lock, flags); 154 + guard(spinlock_irqsave)(&dev->lock); 160 155 dev->lastcmd = 0xff; 161 - spin_unlock_irqrestore(&dev->lock, flags); 162 156 } 163 157 EXPORT_SYMBOL(snd_midi_event_reset_decode); 164 158 ··· 171 177 struct snd_seq_event *ev) 172 178 { 173 179 bool rc = false; 174 - unsigned long flags; 175 180 176 181 if (c >= MIDI_CMD_COMMON_CLOCK) { 177 182 /* real-time event */ ··· 180 187 return ev->type != SNDRV_SEQ_EVENT_NONE; 181 188 } 182 189 183 - spin_lock_irqsave(&dev->lock, flags); 190 + guard(spinlock_irqsave)(&dev->lock); 184 191 if ((c & 0x80) && 185 192 (c != MIDI_CMD_COMMON_SYSEX_END || dev->type != ST_SYSEX)) { 186 193 /* new command */ ··· 229 236 } 230 237 } 231 238 232 - spin_unlock_irqrestore(&dev->lock, flags); 233 239 return rc; 234 240 } 235 241 EXPORT_SYMBOL(snd_midi_event_encode_byte);
+49 -65
sound/core/seq/seq_ports.c
··· 48 48 49 49 if (client == NULL) 50 50 return NULL; 51 - read_lock(&client->ports_lock); 51 + guard(read_lock)(&client->ports_lock); 52 52 list_for_each_entry(port, &client->ports_list_head, list) { 53 53 if (port->addr.port == num) { 54 54 if (port->closing) 55 55 break; /* deleting now */ 56 56 snd_use_lock_use(&port->use_lock); 57 - read_unlock(&client->ports_lock); 58 57 return port; 59 58 } 60 59 } 61 - read_unlock(&client->ports_lock); 62 60 return NULL; /* not found */ 63 61 } 64 62 ··· 71 73 72 74 num = pinfo->addr.port; 73 75 found = NULL; 74 - read_lock(&client->ports_lock); 76 + guard(read_lock)(&client->ports_lock); 75 77 list_for_each_entry(port, &client->ports_list_head, list) { 76 78 if ((port->capability & SNDRV_SEQ_PORT_CAP_INACTIVE) && 77 79 !check_inactive) ··· 91 93 else 92 94 snd_use_lock_use(&found->use_lock); 93 95 } 94 - read_unlock(&client->ports_lock); 95 96 return found; 96 97 } 97 98 ··· 142 145 snd_use_lock_use(&new_port->use_lock); 143 146 144 147 num = max(port, 0); 145 - mutex_lock(&client->ports_mutex); 146 - write_lock_irq(&client->ports_lock); 148 + guard(mutex)(&client->ports_mutex); 149 + guard(write_lock_irq)(&client->ports_lock); 147 150 list_for_each_entry(p, &client->ports_list_head, list) { 148 151 if (p->addr.port == port) { 149 152 kfree(new_port); 150 - num = -EBUSY; 151 - goto unlock; 153 + return -EBUSY; 152 154 } 153 155 if (p->addr.port > num) 154 156 break; ··· 160 164 new_port->addr.port = num; /* store the port number in the port */ 161 165 sprintf(new_port->name, "port-%d", num); 162 166 *port_ret = new_port; 163 - unlock: 164 - write_unlock_irq(&client->ports_lock); 165 - mutex_unlock(&client->ports_mutex); 166 167 167 168 return num; 168 169 } ··· 274 281 { 275 282 struct snd_seq_client_port *found = NULL, *p; 276 283 277 - mutex_lock(&client->ports_mutex); 278 - write_lock_irq(&client->ports_lock); 279 - list_for_each_entry(p, &client->ports_list_head, list) { 280 - if (p->addr.port == port) { 281 - /* ok found. delete from the list at first */ 282 - list_del(&p->list); 283 - client->num_ports--; 284 - found = p; 285 - break; 284 + scoped_guard(mutex, &client->ports_mutex) { 285 + guard(write_lock_irq)(&client->ports_lock); 286 + list_for_each_entry(p, &client->ports_list_head, list) { 287 + if (p->addr.port == port) { 288 + /* ok found. delete from the list at first */ 289 + list_del(&p->list); 290 + client->num_ports--; 291 + found = p; 292 + break; 293 + } 286 294 } 287 295 } 288 - write_unlock_irq(&client->ports_lock); 289 - mutex_unlock(&client->ports_mutex); 290 296 if (found) 291 297 return port_delete(client, found); 292 298 else ··· 301 309 /* move the port list to deleted_list, and 302 310 * clear the port list in the client data. 303 311 */ 304 - mutex_lock(&client->ports_mutex); 305 - write_lock_irq(&client->ports_lock); 306 - if (! list_empty(&client->ports_list_head)) { 307 - list_add(&deleted_list, &client->ports_list_head); 308 - list_del_init(&client->ports_list_head); 309 - } else { 310 - INIT_LIST_HEAD(&deleted_list); 312 + guard(mutex)(&client->ports_mutex); 313 + scoped_guard(write_lock_irq, &client->ports_lock) { 314 + if (!list_empty(&client->ports_list_head)) { 315 + list_add(&deleted_list, &client->ports_list_head); 316 + list_del_init(&client->ports_list_head); 317 + } else { 318 + INIT_LIST_HEAD(&deleted_list); 319 + } 320 + client->num_ports = 0; 311 321 } 312 - client->num_ports = 0; 313 - write_unlock_irq(&client->ports_lock); 314 322 315 323 /* remove each port in deleted_list */ 316 324 list_for_each_entry_safe(port, tmp, &deleted_list, list) { ··· 318 326 snd_seq_system_client_ev_port_exit(port->addr.client, port->addr.port); 319 327 port_delete(client, port); 320 328 } 321 - mutex_unlock(&client->ports_mutex); 322 329 return 0; 323 330 } 324 331 ··· 497 506 int err; 498 507 499 508 grp = is_src ? &port->c_src : &port->c_dest; 500 - err = -EBUSY; 501 - down_write(&grp->list_mutex); 509 + guard(rwsem_write)(&grp->list_mutex); 502 510 if (exclusive) { 503 511 if (!list_empty(&grp->list_head)) 504 - goto __error; 512 + return -EBUSY; 505 513 } else { 506 514 if (grp->exclusive) 507 - goto __error; 515 + return -EBUSY; 508 516 /* check whether already exists */ 509 517 list_for_each(p, &grp->list_head) { 510 518 s = get_subscriber(p, is_src); 511 519 if (match_subs_info(&subs->info, &s->info)) 512 - goto __error; 520 + return -EBUSY; 513 521 } 514 522 } 515 523 516 524 err = subscribe_port(client, port, grp, &subs->info, ack); 517 525 if (err < 0) { 518 526 grp->exclusive = 0; 519 - goto __error; 527 + return err; 520 528 } 521 529 522 530 /* add to list */ 523 - write_lock_irq(&grp->list_lock); 531 + guard(write_lock_irq)(&grp->list_lock); 524 532 if (is_src) 525 533 list_add_tail(&subs->src_list, &grp->list_head); 526 534 else 527 535 list_add_tail(&subs->dest_list, &grp->list_head); 528 536 grp->exclusive = exclusive; 529 537 atomic_inc(&subs->ref_count); 530 - write_unlock_irq(&grp->list_lock); 531 - err = 0; 532 538 533 - __error: 534 - up_write(&grp->list_mutex); 535 - return err; 539 + return 0; 536 540 } 537 541 538 542 /* called with grp->list_mutex held */ ··· 542 556 543 557 grp = is_src ? &port->c_src : &port->c_dest; 544 558 list = is_src ? &subs->src_list : &subs->dest_list; 545 - write_lock_irq(&grp->list_lock); 546 - empty = list_empty(list); 547 - if (!empty) 548 - list_del_init(list); 549 - grp->exclusive = 0; 550 - write_unlock_irq(&grp->list_lock); 559 + scoped_guard(write_lock_irq, &grp->list_lock) { 560 + empty = list_empty(list); 561 + if (!empty) 562 + list_del_init(list); 563 + grp->exclusive = 0; 564 + } 551 565 552 566 if (!empty) 553 567 unsubscribe_port(client, port, grp, &subs->info, ack); ··· 561 575 struct snd_seq_port_subs_info *grp; 562 576 563 577 grp = is_src ? &port->c_src : &port->c_dest; 564 - down_write(&grp->list_mutex); 578 + guard(rwsem_write)(&grp->list_mutex); 565 579 __delete_and_unsubscribe_port(client, port, subs, is_src, ack); 566 - up_write(&grp->list_mutex); 567 580 } 568 581 569 582 /* connect two ports */ ··· 624 639 /* always start from deleting the dest port for avoiding concurrent 625 640 * deletions 626 641 */ 627 - down_write(&dest->list_mutex); 628 - /* look for the connection */ 629 - list_for_each_entry(subs, &dest->list_head, dest_list) { 630 - if (match_subs_info(info, &subs->info)) { 631 - __delete_and_unsubscribe_port(dest_client, dest_port, 632 - subs, false, 633 - connector->number != dest_client->number); 634 - err = 0; 635 - break; 642 + scoped_guard(rwsem_write, &dest->list_mutex) { 643 + /* look for the connection */ 644 + list_for_each_entry(subs, &dest->list_head, dest_list) { 645 + if (match_subs_info(info, &subs->info)) { 646 + __delete_and_unsubscribe_port(dest_client, dest_port, 647 + subs, false, 648 + connector->number != dest_client->number); 649 + err = 0; 650 + break; 651 + } 636 652 } 637 653 } 638 - up_write(&dest->list_mutex); 639 654 if (err < 0) 640 655 return err; 641 656 ··· 654 669 struct snd_seq_subscribers *s; 655 670 int err = -ENOENT; 656 671 657 - down_read(&src_grp->list_mutex); 672 + guard(rwsem_read)(&src_grp->list_mutex); 658 673 list_for_each_entry(s, &src_grp->list_head, src_list) { 659 674 if (addr_match(dest_addr, &s->info.dest)) { 660 675 *subs = s->info; ··· 662 677 break; 663 678 } 664 679 } 665 - up_read(&src_grp->list_mutex); 666 680 return err; 667 681 } 668 682
+81 -117
sound/core/seq/seq_prioq.c
··· 132 132 struct snd_seq_event_cell * cell) 133 133 { 134 134 struct snd_seq_event_cell *cur, *prev; 135 - unsigned long flags; 136 135 int count; 137 136 int prior; 138 137 ··· 141 142 /* check flags */ 142 143 prior = (cell->event.flags & SNDRV_SEQ_PRIORITY_MASK); 143 144 144 - spin_lock_irqsave(&f->lock, flags); 145 + guard(spinlock_irqsave)(&f->lock); 145 146 146 147 /* check if this element needs to inserted at the end (ie. ordered 147 148 data is inserted) This will be very likeley if a sequencer ··· 153 154 f->tail = cell; 154 155 cell->next = NULL; 155 156 f->cells++; 156 - spin_unlock_irqrestore(&f->lock, flags); 157 157 return 0; 158 158 } 159 159 } ··· 177 179 prev = cur; 178 180 cur = cur->next; 179 181 if (! --count) { 180 - spin_unlock_irqrestore(&f->lock, flags); 181 182 pr_err("ALSA: seq: cannot find a pointer.. infinite loop?\n"); 182 183 return -EINVAL; 183 184 } ··· 192 195 if (cur == NULL) /* reached end of the list */ 193 196 f->tail = cell; 194 197 f->cells++; 195 - spin_unlock_irqrestore(&f->lock, flags); 196 198 return 0; 197 199 } 198 200 ··· 209 213 void *current_time) 210 214 { 211 215 struct snd_seq_event_cell *cell; 212 - unsigned long flags; 213 216 214 217 if (f == NULL) { 215 218 pr_debug("ALSA: seq: snd_seq_prioq_cell_in() called with NULL prioq\n"); 216 219 return NULL; 217 220 } 218 - spin_lock_irqsave(&f->lock, flags); 219 221 222 + guard(spinlock_irqsave)(&f->lock); 220 223 cell = f->head; 221 224 if (cell && current_time && !event_is_ready(&cell->event, current_time)) 222 225 cell = NULL; ··· 230 235 f->cells--; 231 236 } 232 237 233 - spin_unlock_irqrestore(&f->lock, flags); 234 238 return cell; 235 239 } 236 240 ··· 243 249 return f->cells; 244 250 } 245 251 246 - static inline int prioq_match(struct snd_seq_event_cell *cell, 247 - int client, int timestamp) 248 - { 249 - if (cell->event.source.client == client || 250 - cell->event.dest.client == client) 251 - return 1; 252 - if (!timestamp) 253 - return 0; 254 - switch (cell->event.flags & SNDRV_SEQ_TIME_STAMP_MASK) { 255 - case SNDRV_SEQ_TIME_STAMP_TICK: 256 - if (cell->event.time.tick) 257 - return 1; 258 - break; 259 - case SNDRV_SEQ_TIME_STAMP_REAL: 260 - if (cell->event.time.time.tv_sec || 261 - cell->event.time.time.tv_nsec) 262 - return 1; 263 - break; 264 - } 265 - return 0; 266 - } 267 - 268 - /* remove cells for left client */ 269 - void snd_seq_prioq_leave(struct snd_seq_prioq * f, int client, int timestamp) 252 + /* remove cells matching with the condition */ 253 + static void prioq_remove_cells(struct snd_seq_prioq *f, 254 + bool (*match)(struct snd_seq_event_cell *cell, 255 + void *arg), 256 + void *arg) 270 257 { 271 258 register struct snd_seq_event_cell *cell, *next; 272 - unsigned long flags; 273 259 struct snd_seq_event_cell *prev = NULL; 274 260 struct snd_seq_event_cell *freefirst = NULL, *freeprev = NULL, *freenext; 275 261 276 262 /* collect all removed cells */ 277 - spin_lock_irqsave(&f->lock, flags); 278 - cell = f->head; 279 - while (cell) { 280 - next = cell->next; 281 - if (prioq_match(cell, client, timestamp)) { 282 - /* remove cell from prioq */ 283 - if (cell == f->head) { 284 - f->head = cell->next; 285 - } else { 286 - prev->next = cell->next; 263 + scoped_guard(spinlock_irqsave, &f->lock) { 264 + for (cell = f->head; cell; cell = next) { 265 + next = cell->next; 266 + if (!match(cell, arg)) { 267 + prev = cell; 268 + continue; 287 269 } 270 + 271 + /* remove cell from prioq */ 272 + if (cell == f->head) 273 + f->head = cell->next; 274 + else 275 + prev->next = cell->next; 288 276 if (cell == f->tail) 289 277 f->tail = cell->next; 290 278 f->cells--; 279 + 291 280 /* add cell to free list */ 292 281 cell->next = NULL; 293 - if (freefirst == NULL) { 282 + if (freefirst == NULL) 294 283 freefirst = cell; 295 - } else { 284 + else 296 285 freeprev->next = cell; 297 - } 298 286 freeprev = cell; 299 - } else { 300 - #if 0 301 - pr_debug("ALSA: seq: type = %i, source = %i, dest = %i, " 302 - "client = %i\n", 303 - cell->event.type, 304 - cell->event.source.client, 305 - cell->event.dest.client, 306 - client); 307 - #endif 308 - prev = cell; 309 287 } 310 - cell = next; 311 288 } 312 - spin_unlock_irqrestore(&f->lock, flags); 313 289 314 290 /* remove selected cells */ 315 291 while (freefirst) { ··· 289 325 } 290 326 } 291 327 292 - static int prioq_remove_match(struct snd_seq_remove_events *info, 293 - struct snd_seq_event *ev) 328 + struct prioq_match_arg { 329 + int client; 330 + int timestamp; 331 + }; 332 + 333 + static inline bool prioq_match(struct snd_seq_event_cell *cell, void *arg) 294 334 { 335 + struct prioq_match_arg *v = arg; 336 + 337 + if (cell->event.source.client == v->client || 338 + cell->event.dest.client == v->client) 339 + return true; 340 + if (!v->timestamp) 341 + return false; 342 + switch (cell->event.flags & SNDRV_SEQ_TIME_STAMP_MASK) { 343 + case SNDRV_SEQ_TIME_STAMP_TICK: 344 + if (cell->event.time.tick) 345 + return true; 346 + break; 347 + case SNDRV_SEQ_TIME_STAMP_REAL: 348 + if (cell->event.time.time.tv_sec || 349 + cell->event.time.time.tv_nsec) 350 + return true; 351 + break; 352 + } 353 + return false; 354 + } 355 + 356 + /* remove cells for left client */ 357 + void snd_seq_prioq_leave(struct snd_seq_prioq *f, int client, int timestamp) 358 + { 359 + struct prioq_match_arg arg = { client, timestamp }; 360 + 361 + return prioq_remove_cells(f, prioq_match, &arg); 362 + } 363 + 364 + struct prioq_remove_match_arg { 365 + int client; 366 + struct snd_seq_remove_events *info; 367 + }; 368 + 369 + static bool prioq_remove_match(struct snd_seq_event_cell *cell, void *arg) 370 + { 371 + struct prioq_remove_match_arg *v = arg; 372 + struct snd_seq_event *ev = &cell->event; 373 + struct snd_seq_remove_events *info = v->info; 295 374 int res; 375 + 376 + if (ev->source.client != v->client) 377 + return false; 296 378 297 379 if (info->remove_mode & SNDRV_SEQ_REMOVE_DEST) { 298 380 if (ev->dest.client != info->dest.client || 299 381 ev->dest.port != info->dest.port) 300 - return 0; 382 + return false; 301 383 } 302 384 if (info->remove_mode & SNDRV_SEQ_REMOVE_DEST_CHANNEL) { 303 385 if (! snd_seq_ev_is_channel_type(ev)) 304 - return 0; 386 + return false; 305 387 /* data.note.channel and data.control.channel are identical */ 306 388 if (ev->data.note.channel != info->channel) 307 - return 0; 389 + return false; 308 390 } 309 391 if (info->remove_mode & SNDRV_SEQ_REMOVE_TIME_AFTER) { 310 392 if (info->remove_mode & SNDRV_SEQ_REMOVE_TIME_TICK) ··· 358 348 else 359 349 res = snd_seq_compare_real_time(&ev->time.time, &info->time.time); 360 350 if (!res) 361 - return 0; 351 + return false; 362 352 } 363 353 if (info->remove_mode & SNDRV_SEQ_REMOVE_TIME_BEFORE) { 364 354 if (info->remove_mode & SNDRV_SEQ_REMOVE_TIME_TICK) ··· 366 356 else 367 357 res = snd_seq_compare_real_time(&ev->time.time, &info->time.time); 368 358 if (res) 369 - return 0; 359 + return false; 370 360 } 371 361 if (info->remove_mode & SNDRV_SEQ_REMOVE_EVENT_TYPE) { 372 362 if (ev->type != info->type) 373 - return 0; 363 + return false; 374 364 } 375 365 if (info->remove_mode & SNDRV_SEQ_REMOVE_IGNORE_OFF) { 376 366 /* Do not remove off events */ 377 367 switch (ev->type) { 378 368 case SNDRV_SEQ_EVENT_NOTEOFF: 379 369 /* case SNDRV_SEQ_EVENT_SAMPLE_STOP: */ 380 - return 0; 370 + return false; 381 371 default: 382 372 break; 383 373 } 384 374 } 385 375 if (info->remove_mode & SNDRV_SEQ_REMOVE_TAG_MATCH) { 386 376 if (info->tag != ev->tag) 387 - return 0; 377 + return false; 388 378 } 389 379 390 - return 1; 380 + return true; 391 381 } 392 382 393 383 /* remove cells matching remove criteria */ 394 384 void snd_seq_prioq_remove_events(struct snd_seq_prioq * f, int client, 395 385 struct snd_seq_remove_events *info) 396 386 { 397 - struct snd_seq_event_cell *cell, *next; 398 - unsigned long flags; 399 - struct snd_seq_event_cell *prev = NULL; 400 - struct snd_seq_event_cell *freefirst = NULL, *freeprev = NULL, *freenext; 387 + struct prioq_remove_match_arg arg = { client, info }; 401 388 402 - /* collect all removed cells */ 403 - spin_lock_irqsave(&f->lock, flags); 404 - cell = f->head; 405 - 406 - while (cell) { 407 - next = cell->next; 408 - if (cell->event.source.client == client && 409 - prioq_remove_match(info, &cell->event)) { 410 - 411 - /* remove cell from prioq */ 412 - if (cell == f->head) { 413 - f->head = cell->next; 414 - } else { 415 - prev->next = cell->next; 416 - } 417 - 418 - if (cell == f->tail) 419 - f->tail = cell->next; 420 - f->cells--; 421 - 422 - /* add cell to free list */ 423 - cell->next = NULL; 424 - if (freefirst == NULL) { 425 - freefirst = cell; 426 - } else { 427 - freeprev->next = cell; 428 - } 429 - 430 - freeprev = cell; 431 - } else { 432 - prev = cell; 433 - } 434 - cell = next; 435 - } 436 - spin_unlock_irqrestore(&f->lock, flags); 437 - 438 - /* remove selected cells */ 439 - while (freefirst) { 440 - freenext = freefirst->next; 441 - snd_seq_cell_free(freefirst); 442 - freefirst = freenext; 443 - } 389 + return prioq_remove_cells(f, prioq_remove_match, &arg); 444 390 } 445 - 446 -
+28 -50
sound/core/seq/seq_queue.c
··· 50 50 static int queue_list_add(struct snd_seq_queue *q) 51 51 { 52 52 int i; 53 - unsigned long flags; 54 53 55 - spin_lock_irqsave(&queue_list_lock, flags); 54 + guard(spinlock_irqsave)(&queue_list_lock); 56 55 for (i = 0; i < SNDRV_SEQ_MAX_QUEUES; i++) { 57 56 if (! queue_list[i]) { 58 57 queue_list[i] = q; 59 58 q->queue = i; 60 59 num_queues++; 61 - spin_unlock_irqrestore(&queue_list_lock, flags); 62 60 return i; 63 61 } 64 62 } 65 - spin_unlock_irqrestore(&queue_list_lock, flags); 66 63 return -1; 67 64 } 68 65 69 66 static struct snd_seq_queue *queue_list_remove(int id, int client) 70 67 { 71 68 struct snd_seq_queue *q; 72 - unsigned long flags; 73 69 74 - spin_lock_irqsave(&queue_list_lock, flags); 70 + guard(spinlock_irqsave)(&queue_list_lock); 75 71 q = queue_list[id]; 76 72 if (q) { 77 - spin_lock(&q->owner_lock); 73 + guard(spinlock)(&q->owner_lock); 78 74 if (q->owner == client) { 79 75 /* found */ 80 76 q->klocked = 1; 81 - spin_unlock(&q->owner_lock); 82 77 queue_list[id] = NULL; 83 78 num_queues--; 84 - spin_unlock_irqrestore(&queue_list_lock, flags); 85 79 return q; 86 80 } 87 - spin_unlock(&q->owner_lock); 88 81 } 89 - spin_unlock_irqrestore(&queue_list_lock, flags); 90 82 return NULL; 91 83 } 92 84 ··· 195 203 struct snd_seq_queue *queueptr(int queueid) 196 204 { 197 205 struct snd_seq_queue *q; 198 - unsigned long flags; 199 206 200 207 if (queueid < 0 || queueid >= SNDRV_SEQ_MAX_QUEUES) 201 208 return NULL; 202 - spin_lock_irqsave(&queue_list_lock, flags); 209 + guard(spinlock_irqsave)(&queue_list_lock); 203 210 q = queue_list[queueid]; 204 211 if (q) 205 212 snd_use_lock_use(&q->use_lock); 206 - spin_unlock_irqrestore(&queue_list_lock, flags); 207 213 return q; 208 214 } 209 215 ··· 229 239 230 240 void snd_seq_check_queue(struct snd_seq_queue *q, int atomic, int hop) 231 241 { 232 - unsigned long flags; 233 242 struct snd_seq_event_cell *cell; 234 243 snd_seq_tick_time_t cur_tick; 235 244 snd_seq_real_time_t cur_time; ··· 238 249 return; 239 250 240 251 /* make this function non-reentrant */ 241 - spin_lock_irqsave(&q->check_lock, flags); 242 - if (q->check_blocked) { 243 - q->check_again = 1; 244 - spin_unlock_irqrestore(&q->check_lock, flags); 245 - return; /* other thread is already checking queues */ 252 + scoped_guard(spinlock_irqsave, &q->check_lock) { 253 + if (q->check_blocked) { 254 + q->check_again = 1; 255 + return; /* other thread is already checking queues */ 256 + } 257 + q->check_blocked = 1; 246 258 } 247 - q->check_blocked = 1; 248 - spin_unlock_irqrestore(&q->check_lock, flags); 249 259 250 260 __again: 251 261 /* Process tick queue... */ ··· 271 283 272 284 out: 273 285 /* free lock */ 274 - spin_lock_irqsave(&q->check_lock, flags); 275 - if (q->check_again) { 276 - q->check_again = 0; 277 - if (processed < MAX_CELL_PROCESSES_IN_QUEUE) { 278 - spin_unlock_irqrestore(&q->check_lock, flags); 279 - goto __again; 286 + scoped_guard(spinlock_irqsave, &q->check_lock) { 287 + if (q->check_again) { 288 + q->check_again = 0; 289 + if (processed < MAX_CELL_PROCESSES_IN_QUEUE) 290 + goto __again; 280 291 } 292 + q->check_blocked = 0; 281 293 } 282 - q->check_blocked = 0; 283 - spin_unlock_irqrestore(&q->check_lock, flags); 284 294 } 285 295 286 296 ··· 347 361 */ 348 362 static int queue_access_lock(struct snd_seq_queue *q, int client) 349 363 { 350 - unsigned long flags; 351 364 int access_ok; 352 365 353 - spin_lock_irqsave(&q->owner_lock, flags); 366 + guard(spinlock_irqsave)(&q->owner_lock); 354 367 access_ok = check_access(q, client); 355 368 if (access_ok) 356 369 q->klocked = 1; 357 - spin_unlock_irqrestore(&q->owner_lock, flags); 358 370 return access_ok; 359 371 } 360 372 361 373 /* unlock the queue */ 362 374 static inline void queue_access_unlock(struct snd_seq_queue *q) 363 375 { 364 - unsigned long flags; 365 - 366 - spin_lock_irqsave(&q->owner_lock, flags); 376 + guard(spinlock_irqsave)(&q->owner_lock); 367 377 q->klocked = 0; 368 - spin_unlock_irqrestore(&q->owner_lock, flags); 369 378 } 370 379 371 380 /* exported - only checking permission */ ··· 368 387 { 369 388 struct snd_seq_queue *q = queueptr(queueid); 370 389 int access_ok; 371 - unsigned long flags; 372 390 373 391 if (! q) 374 392 return 0; 375 - spin_lock_irqsave(&q->owner_lock, flags); 376 - access_ok = check_access(q, client); 377 - spin_unlock_irqrestore(&q->owner_lock, flags); 393 + scoped_guard(spinlock_irqsave, &q->owner_lock) 394 + access_ok = check_access(q, client); 378 395 queuefree(q); 379 396 return access_ok; 380 397 } ··· 385 406 int snd_seq_queue_set_owner(int queueid, int client, int locked) 386 407 { 387 408 struct snd_seq_queue *q = queueptr(queueid); 388 - unsigned long flags; 389 409 390 410 if (q == NULL) 391 411 return -EINVAL; ··· 394 416 return -EPERM; 395 417 } 396 418 397 - spin_lock_irqsave(&q->owner_lock, flags); 398 - q->locked = locked ? 1 : 0; 399 - q->owner = client; 400 - spin_unlock_irqrestore(&q->owner_lock, flags); 419 + scoped_guard(spinlock_irqsave, &q->owner_lock) { 420 + q->locked = locked ? 1 : 0; 421 + q->owner = client; 422 + } 401 423 queue_access_unlock(q); 402 424 queuefree(q); 403 425 ··· 728 750 else 729 751 bpm = 0; 730 752 731 - spin_lock_irq(&q->owner_lock); 732 - locked = q->locked; 733 - owner = q->owner; 734 - spin_unlock_irq(&q->owner_lock); 753 + scoped_guard(spinlock_irq, &q->owner_lock) { 754 + locked = q->locked; 755 + owner = q->owner; 756 + } 735 757 736 758 snd_iprintf(buffer, "queue %d: [%s]\n", q->queue, q->name); 737 759 snd_iprintf(buffer, "owned by client : %d\n", owner);
+58 -105
sound/core/seq/seq_timer.c
··· 75 75 76 76 void snd_seq_timer_defaults(struct snd_seq_timer * tmr) 77 77 { 78 - unsigned long flags; 79 - 80 - spin_lock_irqsave(&tmr->lock, flags); 78 + guard(spinlock_irqsave)(&tmr->lock); 81 79 /* setup defaults */ 82 80 tmr->ppq = 96; /* 96 PPQ */ 83 81 tmr->tempo = 500000; /* 120 BPM */ ··· 91 93 tmr->preferred_resolution = seq_default_timer_resolution; 92 94 93 95 tmr->skew = tmr->skew_base = SKEW_BASE; 94 - spin_unlock_irqrestore(&tmr->lock, flags); 95 96 } 96 97 97 98 static void seq_timer_reset(struct snd_seq_timer *tmr) ··· 105 108 106 109 void snd_seq_timer_reset(struct snd_seq_timer *tmr) 107 110 { 108 - unsigned long flags; 109 - 110 - spin_lock_irqsave(&tmr->lock, flags); 111 + guard(spinlock_irqsave)(&tmr->lock); 111 112 seq_timer_reset(tmr); 112 - spin_unlock_irqrestore(&tmr->lock, flags); 113 113 } 114 114 115 115 ··· 115 121 unsigned long resolution, 116 122 unsigned long ticks) 117 123 { 118 - unsigned long flags; 119 124 struct snd_seq_queue *q = timeri->callback_data; 120 125 struct snd_seq_timer *tmr; 121 126 ··· 123 130 tmr = q->timer; 124 131 if (tmr == NULL) 125 132 return; 126 - spin_lock_irqsave(&tmr->lock, flags); 127 - if (!tmr->running) { 128 - spin_unlock_irqrestore(&tmr->lock, flags); 129 - return; 133 + 134 + scoped_guard(spinlock_irqsave, &tmr->lock) { 135 + if (!tmr->running) 136 + return; 137 + 138 + resolution *= ticks; 139 + if (tmr->skew != tmr->skew_base) { 140 + /* FIXME: assuming skew_base = 0x10000 */ 141 + resolution = (resolution >> 16) * tmr->skew + 142 + (((resolution & 0xffff) * tmr->skew) >> 16); 143 + } 144 + 145 + /* update timer */ 146 + snd_seq_inc_time_nsec(&tmr->cur_time, resolution); 147 + 148 + /* calculate current tick */ 149 + snd_seq_timer_update_tick(&tmr->tick, resolution); 150 + 151 + /* register actual time of this timer update */ 152 + ktime_get_ts64(&tmr->last_update); 130 153 } 131 - 132 - resolution *= ticks; 133 - if (tmr->skew != tmr->skew_base) { 134 - /* FIXME: assuming skew_base = 0x10000 */ 135 - resolution = (resolution >> 16) * tmr->skew + 136 - (((resolution & 0xffff) * tmr->skew) >> 16); 137 - } 138 - 139 - /* update timer */ 140 - snd_seq_inc_time_nsec(&tmr->cur_time, resolution); 141 - 142 - /* calculate current tick */ 143 - snd_seq_timer_update_tick(&tmr->tick, resolution); 144 - 145 - /* register actual time of this timer update */ 146 - ktime_get_ts64(&tmr->last_update); 147 - 148 - spin_unlock_irqrestore(&tmr->lock, flags); 149 154 150 155 /* check queues and dispatch events */ 151 156 snd_seq_check_queue(q, 1, 0); ··· 152 161 /* set current tempo */ 153 162 int snd_seq_timer_set_tempo(struct snd_seq_timer * tmr, int tempo) 154 163 { 155 - unsigned long flags; 156 - 157 164 if (snd_BUG_ON(!tmr)) 158 165 return -EINVAL; 159 166 if (tempo <= 0) 160 167 return -EINVAL; 161 - spin_lock_irqsave(&tmr->lock, flags); 168 + guard(spinlock_irqsave)(&tmr->lock); 162 169 if ((unsigned int)tempo != tmr->tempo) { 163 170 tmr->tempo = tempo; 164 171 snd_seq_timer_set_tick_resolution(tmr); 165 172 } 166 - spin_unlock_irqrestore(&tmr->lock, flags); 167 173 return 0; 168 174 } 169 175 ··· 168 180 int snd_seq_timer_set_tempo_ppq(struct snd_seq_timer *tmr, int tempo, int ppq) 169 181 { 170 182 int changed; 171 - unsigned long flags; 172 183 173 184 if (snd_BUG_ON(!tmr)) 174 185 return -EINVAL; 175 186 if (tempo <= 0 || ppq <= 0) 176 187 return -EINVAL; 177 - spin_lock_irqsave(&tmr->lock, flags); 188 + guard(spinlock_irqsave)(&tmr->lock); 178 189 if (tmr->running && (ppq != tmr->ppq)) { 179 190 /* refuse to change ppq on running timers */ 180 191 /* because it will upset the song position (ticks) */ 181 - spin_unlock_irqrestore(&tmr->lock, flags); 182 192 pr_debug("ALSA: seq: cannot change ppq of a running timer\n"); 183 193 return -EBUSY; 184 194 } ··· 185 199 tmr->ppq = ppq; 186 200 if (changed) 187 201 snd_seq_timer_set_tick_resolution(tmr); 188 - spin_unlock_irqrestore(&tmr->lock, flags); 189 202 return 0; 190 203 } 191 204 ··· 192 207 int snd_seq_timer_set_position_tick(struct snd_seq_timer *tmr, 193 208 snd_seq_tick_time_t position) 194 209 { 195 - unsigned long flags; 196 - 197 210 if (snd_BUG_ON(!tmr)) 198 211 return -EINVAL; 199 212 200 - spin_lock_irqsave(&tmr->lock, flags); 213 + guard(spinlock_irqsave)(&tmr->lock); 201 214 tmr->tick.cur_tick = position; 202 215 tmr->tick.fraction = 0; 203 - spin_unlock_irqrestore(&tmr->lock, flags); 204 216 return 0; 205 217 } 206 218 ··· 205 223 int snd_seq_timer_set_position_time(struct snd_seq_timer *tmr, 206 224 snd_seq_real_time_t position) 207 225 { 208 - unsigned long flags; 209 - 210 226 if (snd_BUG_ON(!tmr)) 211 227 return -EINVAL; 212 228 213 229 snd_seq_sanity_real_time(&position); 214 - spin_lock_irqsave(&tmr->lock, flags); 230 + guard(spinlock_irqsave)(&tmr->lock); 215 231 tmr->cur_time = position; 216 - spin_unlock_irqrestore(&tmr->lock, flags); 217 232 return 0; 218 233 } 219 234 ··· 218 239 int snd_seq_timer_set_skew(struct snd_seq_timer *tmr, unsigned int skew, 219 240 unsigned int base) 220 241 { 221 - unsigned long flags; 222 - 223 242 if (snd_BUG_ON(!tmr)) 224 243 return -EINVAL; 225 244 ··· 226 249 pr_debug("ALSA: seq: invalid skew base 0x%x\n", base); 227 250 return -EINVAL; 228 251 } 229 - spin_lock_irqsave(&tmr->lock, flags); 252 + guard(spinlock_irqsave)(&tmr->lock); 230 253 tmr->skew = skew; 231 - spin_unlock_irqrestore(&tmr->lock, flags); 232 254 return 0; 233 255 } 234 256 ··· 272 296 snd_timer_instance_free(t); 273 297 return err; 274 298 } 275 - spin_lock_irq(&tmr->lock); 276 - if (tmr->timeri) 277 - err = -EBUSY; 278 - else 279 - tmr->timeri = t; 280 - spin_unlock_irq(&tmr->lock); 299 + scoped_guard(spinlock_irq, &tmr->lock) { 300 + if (tmr->timeri) 301 + err = -EBUSY; 302 + else 303 + tmr->timeri = t; 304 + } 281 305 if (err < 0) { 282 306 snd_timer_close(t); 283 307 snd_timer_instance_free(t); ··· 294 318 tmr = q->timer; 295 319 if (snd_BUG_ON(!tmr)) 296 320 return -EINVAL; 297 - spin_lock_irq(&tmr->lock); 298 - t = tmr->timeri; 299 - tmr->timeri = NULL; 300 - spin_unlock_irq(&tmr->lock); 321 + scoped_guard(spinlock_irq, &tmr->lock) { 322 + t = tmr->timeri; 323 + tmr->timeri = NULL; 324 + } 301 325 if (t) { 302 326 snd_timer_close(t); 303 327 snd_timer_instance_free(t); ··· 318 342 319 343 int snd_seq_timer_stop(struct snd_seq_timer *tmr) 320 344 { 321 - unsigned long flags; 322 - int err; 323 - 324 - spin_lock_irqsave(&tmr->lock, flags); 325 - err = seq_timer_stop(tmr); 326 - spin_unlock_irqrestore(&tmr->lock, flags); 327 - return err; 345 + guard(spinlock_irqsave)(&tmr->lock); 346 + return seq_timer_stop(tmr); 328 347 } 329 348 330 349 static int initialize_timer(struct snd_seq_timer *tmr) ··· 369 398 370 399 int snd_seq_timer_start(struct snd_seq_timer *tmr) 371 400 { 372 - unsigned long flags; 373 - int err; 374 - 375 - spin_lock_irqsave(&tmr->lock, flags); 376 - err = seq_timer_start(tmr); 377 - spin_unlock_irqrestore(&tmr->lock, flags); 378 - return err; 401 + guard(spinlock_irqsave)(&tmr->lock); 402 + return seq_timer_start(tmr); 379 403 } 380 404 381 405 static int seq_timer_continue(struct snd_seq_timer *tmr) ··· 392 426 393 427 int snd_seq_timer_continue(struct snd_seq_timer *tmr) 394 428 { 395 - unsigned long flags; 396 - int err; 397 - 398 - spin_lock_irqsave(&tmr->lock, flags); 399 - err = seq_timer_continue(tmr); 400 - spin_unlock_irqrestore(&tmr->lock, flags); 401 - return err; 429 + guard(spinlock_irqsave)(&tmr->lock); 430 + return seq_timer_continue(tmr); 402 431 } 403 432 404 433 /* return current 'real' time. use timeofday() to get better granularity. */ ··· 401 440 bool adjust_ktime) 402 441 { 403 442 snd_seq_real_time_t cur_time; 404 - unsigned long flags; 405 443 406 - spin_lock_irqsave(&tmr->lock, flags); 444 + guard(spinlock_irqsave)(&tmr->lock); 407 445 cur_time = tmr->cur_time; 408 446 if (adjust_ktime && tmr->running) { 409 447 struct timespec64 tm; ··· 413 453 cur_time.tv_sec += tm.tv_sec; 414 454 snd_seq_sanity_real_time(&cur_time); 415 455 } 416 - spin_unlock_irqrestore(&tmr->lock, flags); 417 456 return cur_time; 418 457 } 419 458 ··· 420 461 high PPQ values) */ 421 462 snd_seq_tick_time_t snd_seq_timer_get_cur_tick(struct snd_seq_timer *tmr) 422 463 { 423 - snd_seq_tick_time_t cur_tick; 424 - unsigned long flags; 425 - 426 - spin_lock_irqsave(&tmr->lock, flags); 427 - cur_tick = tmr->tick.cur_tick; 428 - spin_unlock_irqrestore(&tmr->lock, flags); 429 - return cur_tick; 464 + guard(spinlock_irqsave)(&tmr->lock); 465 + return tmr->tick.cur_tick; 430 466 } 431 467 432 468 ··· 440 486 q = queueptr(idx); 441 487 if (q == NULL) 442 488 continue; 443 - mutex_lock(&q->timer_mutex); 444 - tmr = q->timer; 445 - if (!tmr) 446 - goto unlock; 447 - ti = tmr->timeri; 448 - if (!ti) 449 - goto unlock; 450 - snd_iprintf(buffer, "Timer for queue %i : %s\n", q->queue, ti->timer->name); 451 - resolution = snd_timer_resolution(ti) * tmr->ticks; 452 - snd_iprintf(buffer, " Period time : %lu.%09lu\n", resolution / 1000000000, resolution % 1000000000); 453 - snd_iprintf(buffer, " Skew : %u / %u\n", tmr->skew, tmr->skew_base); 454 - unlock: 455 - mutex_unlock(&q->timer_mutex); 489 + scoped_guard(mutex, &q->timer_mutex) { 490 + tmr = q->timer; 491 + if (!tmr) 492 + break; 493 + ti = tmr->timeri; 494 + if (!ti) 495 + break; 496 + snd_iprintf(buffer, "Timer for queue %i : %s\n", q->queue, ti->timer->name); 497 + resolution = snd_timer_resolution(ti) * tmr->ticks; 498 + snd_iprintf(buffer, " Period time : %lu.%09lu\n", resolution / 1000000000, resolution % 1000000000); 499 + snd_iprintf(buffer, " Skew : %u / %u\n", tmr->skew, tmr->skew_base); 500 + } 456 501 queuefree(q); 457 502 } 458 503 }
+17 -29
sound/core/seq/seq_ump_client.c
··· 115 115 static int seq_ump_client_open(struct seq_ump_client *client, int dir) 116 116 { 117 117 struct snd_ump_endpoint *ump = client->ump; 118 - int err = 0; 118 + int err; 119 119 120 - mutex_lock(&ump->open_mutex); 120 + guard(mutex)(&ump->open_mutex); 121 121 if (dir == STR_OUT && !client->opened[dir]) { 122 122 err = snd_rawmidi_kernel_open(&ump->core, 0, 123 123 SNDRV_RAWMIDI_LFLG_OUTPUT | 124 124 SNDRV_RAWMIDI_LFLG_APPEND, 125 125 &client->out_rfile); 126 126 if (err < 0) 127 - goto unlock; 127 + return err; 128 128 } 129 129 client->opened[dir]++; 130 - unlock: 131 - mutex_unlock(&ump->open_mutex); 132 - return err; 130 + return 0; 133 131 } 134 132 135 133 /* close the rawmidi */ ··· 135 137 { 136 138 struct snd_ump_endpoint *ump = client->ump; 137 139 138 - mutex_lock(&ump->open_mutex); 140 + guard(mutex)(&ump->open_mutex); 139 141 if (!--client->opened[dir]) 140 142 if (dir == STR_OUT) 141 143 snd_rawmidi_kernel_release(&client->out_rfile); 142 - mutex_unlock(&ump->open_mutex); 143 144 return 0; 144 145 } 145 146 ··· 214 217 static int seq_ump_group_init(struct seq_ump_client *client, int group_index) 215 218 { 216 219 struct seq_ump_group *group = &client->groups[group_index]; 217 - struct snd_seq_port_info *port; 220 + struct snd_seq_port_info *port __free(kfree) = NULL; 218 221 struct snd_seq_port_callback pcallbacks; 219 - int err; 220 222 221 223 port = kzalloc(sizeof(*port), GFP_KERNEL); 222 - if (!port) { 223 - err = -ENOMEM; 224 - goto error; 225 - } 224 + if (!port) 225 + return -ENOMEM; 226 226 227 227 fill_port_info(port, client, group); 228 228 port->flags = SNDRV_SEQ_PORT_FLG_GIVEN_PORT; ··· 232 238 pcallbacks.unuse = seq_ump_unuse; 233 239 pcallbacks.event_input = seq_ump_process_event; 234 240 port->kernel = &pcallbacks; 235 - err = snd_seq_kernel_client_ctl(client->seq_client, 236 - SNDRV_SEQ_IOCTL_CREATE_PORT, 237 - port); 238 - error: 239 - kfree(port); 240 - return err; 241 + return snd_seq_kernel_client_ctl(client->seq_client, 242 + SNDRV_SEQ_IOCTL_CREATE_PORT, 243 + port); 241 244 } 242 245 243 246 /* update the sequencer ports; called from notify_fb_change callback */ 244 247 static void update_port_infos(struct seq_ump_client *client) 245 248 { 246 - struct snd_seq_port_info *old, *new; 249 + struct snd_seq_port_info *old __free(kfree) = NULL; 250 + struct snd_seq_port_info *new __free(kfree) = NULL; 247 251 int i, err; 248 252 249 253 old = kzalloc(sizeof(*old), GFP_KERNEL); 250 254 new = kzalloc(sizeof(*new), GFP_KERNEL); 251 255 if (!old || !new) 252 - goto error; 256 + return; 253 257 254 258 for (i = 0; i < SNDRV_UMP_MAX_GROUPS; i++) { 255 259 old->addr.client = client->seq_client; ··· 256 264 SNDRV_SEQ_IOCTL_GET_PORT_INFO, 257 265 old); 258 266 if (err < 0) 259 - goto error; 267 + return; 260 268 fill_port_info(new, client, &client->groups[i]); 261 269 if (old->capability == new->capability && 262 270 !strcmp(old->name, new->name)) ··· 265 273 SNDRV_SEQ_IOCTL_SET_PORT_INFO, 266 274 new); 267 275 if (err < 0) 268 - goto error; 276 + return; 269 277 /* notify to system port */ 270 278 snd_seq_system_client_ev_port_change(client->seq_client, i); 271 279 } 272 - error: 273 - kfree(new); 274 - kfree(old); 275 280 } 276 281 277 282 /* update dir_bits and active flag for all groups in the client */ ··· 323 334 /* create a UMP Endpoint port */ 324 335 static int create_ump_endpoint_port(struct seq_ump_client *client) 325 336 { 326 - struct snd_seq_port_info *port; 337 + struct snd_seq_port_info *port __free(kfree) = NULL; 327 338 struct snd_seq_port_callback pcallbacks; 328 339 unsigned int rawmidi_info = client->ump->core.info_flags; 329 340 int err; ··· 372 383 err = snd_seq_kernel_client_ctl(client->seq_client, 373 384 SNDRV_SEQ_IOCTL_CREATE_PORT, 374 385 port); 375 - kfree(port); 376 386 return err; 377 387 } 378 388
+23 -26
sound/core/seq/seq_virmidi.c
··· 62 62 /* 63 63 * decode input event and put to read buffer of each opened file 64 64 */ 65 + 66 + /* callback for snd_seq_dump_var_event(), bridging to snd_rawmidi_receive() */ 67 + static int dump_to_rawmidi(void *ptr, void *buf, int count) 68 + { 69 + return snd_rawmidi_receive(ptr, buf, count); 70 + } 71 + 65 72 static int snd_virmidi_dev_receive_event(struct snd_virmidi_dev *rdev, 66 73 struct snd_seq_event *ev, 67 74 bool atomic) ··· 87 80 if (ev->type == SNDRV_SEQ_EVENT_SYSEX) { 88 81 if ((ev->flags & SNDRV_SEQ_EVENT_LENGTH_MASK) != SNDRV_SEQ_EVENT_LENGTH_VARIABLE) 89 82 continue; 90 - snd_seq_dump_var_event(ev, (snd_seq_dump_func_t)snd_rawmidi_receive, vmidi->substream); 83 + snd_seq_dump_var_event(ev, dump_to_rawmidi, vmidi->substream); 91 84 snd_midi_event_reset_decode(vmidi->parser); 92 85 } else { 93 86 len = snd_midi_event_decode(vmidi->parser, msg, sizeof(msg), ev); ··· 199 192 vmidi->client = rdev->client; 200 193 vmidi->port = rdev->port; 201 194 runtime->private_data = vmidi; 202 - down_write(&rdev->filelist_sem); 203 - write_lock_irq(&rdev->filelist_lock); 204 - list_add_tail(&vmidi->list, &rdev->filelist); 205 - write_unlock_irq(&rdev->filelist_lock); 206 - up_write(&rdev->filelist_sem); 195 + scoped_guard(rwsem_write, &rdev->filelist_sem) { 196 + guard(write_lock_irq)(&rdev->filelist_lock); 197 + list_add_tail(&vmidi->list, &rdev->filelist); 198 + } 207 199 vmidi->rdev = rdev; 208 200 return 0; 209 201 } ··· 242 236 struct snd_virmidi_dev *rdev = substream->rmidi->private_data; 243 237 struct snd_virmidi *vmidi = substream->runtime->private_data; 244 238 245 - down_write(&rdev->filelist_sem); 246 - write_lock_irq(&rdev->filelist_lock); 247 - list_del(&vmidi->list); 248 - write_unlock_irq(&rdev->filelist_lock); 249 - up_write(&rdev->filelist_sem); 239 + scoped_guard(rwsem_write, &rdev->filelist_sem) { 240 + guard(write_lock_irq)(&rdev->filelist_lock); 241 + list_del(&vmidi->list); 242 + } 250 243 snd_midi_event_free(vmidi->parser); 251 244 substream->runtime->private_data = NULL; 252 245 kfree(vmidi); ··· 361 356 { 362 357 int client; 363 358 struct snd_seq_port_callback pcallbacks; 364 - struct snd_seq_port_info *pinfo; 359 + struct snd_seq_port_info *pinfo __free(kfree) = NULL; 365 360 int err; 366 361 367 362 if (rdev->client >= 0) 368 363 return 0; 369 364 370 365 pinfo = kzalloc(sizeof(*pinfo), GFP_KERNEL); 371 - if (!pinfo) { 372 - err = -ENOMEM; 373 - goto __error; 374 - } 366 + if (!pinfo) 367 + return -ENOMEM; 375 368 376 369 client = snd_seq_create_kernel_client(rdev->card, rdev->device, 377 370 "%s %d-%d", rdev->rmidi->name, 378 371 rdev->card->number, 379 372 rdev->device); 380 - if (client < 0) { 381 - err = client; 382 - goto __error; 383 - } 373 + if (client < 0) 374 + return client; 384 375 rdev->client = client; 385 376 386 377 /* create a port */ ··· 404 403 if (err < 0) { 405 404 snd_seq_delete_kernel_client(client); 406 405 rdev->client = -1; 407 - goto __error; 406 + return err; 408 407 } 409 408 410 409 rdev->port = pinfo->addr.port; 411 - err = 0; /* success */ 412 - 413 - __error: 414 - kfree(pinfo); 415 - return err; 410 + return 0; /* success */ 416 411 } 417 412 418 413
+1 -1
sound/core/seq_device.c
··· 49 49 sdrv->argsize == sdev->argsize; 50 50 } 51 51 52 - static struct bus_type snd_seq_bus_type = { 52 + static const struct bus_type snd_seq_bus_type = { 53 53 .name = "snd_seq", 54 54 .match = snd_seq_bus_match, 55 55 };
+11 -17
sound/core/sound.c
··· 103 103 104 104 if (minor >= ARRAY_SIZE(snd_minors)) 105 105 return NULL; 106 - mutex_lock(&sound_mutex); 106 + guard(mutex)(&sound_mutex); 107 107 mreg = snd_minors[minor]; 108 108 if (mreg && mreg->type == type) { 109 109 private_data = mreg->private_data; ··· 111 111 get_device(&mreg->card_ptr->card_dev); 112 112 } else 113 113 private_data = NULL; 114 - mutex_unlock(&sound_mutex); 115 114 return private_data; 116 115 } 117 116 EXPORT_SYMBOL(snd_lookup_minor_data); ··· 149 150 150 151 if (minor >= ARRAY_SIZE(snd_minors)) 151 152 return -ENODEV; 152 - mutex_lock(&sound_mutex); 153 - mptr = snd_minors[minor]; 154 - if (mptr == NULL) { 155 - mptr = autoload_device(minor); 156 - if (!mptr) { 157 - mutex_unlock(&sound_mutex); 158 - return -ENODEV; 153 + scoped_guard(mutex, &sound_mutex) { 154 + mptr = snd_minors[minor]; 155 + if (mptr == NULL) { 156 + mptr = autoload_device(minor); 157 + if (!mptr) 158 + return -ENODEV; 159 159 } 160 + new_fops = fops_get(mptr->f_ops); 160 161 } 161 - new_fops = fops_get(mptr->f_ops); 162 - mutex_unlock(&sound_mutex); 163 162 if (!new_fops) 164 163 return -ENODEV; 165 164 replace_fops(file, new_fops); ··· 266 269 preg->f_ops = f_ops; 267 270 preg->private_data = private_data; 268 271 preg->card_ptr = card; 269 - mutex_lock(&sound_mutex); 272 + guard(mutex)(&sound_mutex); 270 273 minor = snd_find_free_minor(type, card, dev); 271 274 if (minor < 0) { 272 275 err = minor; ··· 281 284 282 285 snd_minors[minor] = preg; 283 286 error: 284 - mutex_unlock(&sound_mutex); 285 287 if (err < 0) 286 288 kfree(preg); 287 289 return err; ··· 301 305 int minor; 302 306 struct snd_minor *preg; 303 307 304 - mutex_lock(&sound_mutex); 308 + guard(mutex)(&sound_mutex); 305 309 for (minor = 0; minor < ARRAY_SIZE(snd_minors); ++minor) { 306 310 preg = snd_minors[minor]; 307 311 if (preg && preg->dev == dev) { ··· 311 315 break; 312 316 } 313 317 } 314 - mutex_unlock(&sound_mutex); 315 318 if (minor >= ARRAY_SIZE(snd_minors)) 316 319 return -ENOENT; 317 320 return 0; ··· 350 355 int minor; 351 356 struct snd_minor *mptr; 352 357 353 - mutex_lock(&sound_mutex); 358 + guard(mutex)(&sound_mutex); 354 359 for (minor = 0; minor < SNDRV_OS_MINORS; ++minor) { 355 360 mptr = snd_minors[minor]; 356 361 if (!mptr) ··· 368 373 snd_iprintf(buffer, "%3i: : %s\n", minor, 369 374 snd_device_type_name(mptr->type)); 370 375 } 371 - mutex_unlock(&sound_mutex); 372 376 } 373 377 374 378 int __init snd_minor_info_init(void)
+312
sound/core/sound_kunit.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + /* 3 + * Sound core KUnit test 4 + * Author: Ivan Orlov <ivan.orlov0322@gmail.com> 5 + */ 6 + 7 + #include <kunit/test.h> 8 + #include <sound/core.h> 9 + #include <sound/pcm.h> 10 + 11 + #define SILENCE_BUFFER_MAX_FRAMES 260 12 + #define SILENCE_BUFFER_SIZE (sizeof(u64) * SILENCE_BUFFER_MAX_FRAMES) 13 + #define SILENCE(...) { __VA_ARGS__ } 14 + #define DEFINE_FORMAT(fmt, pbits, wd, endianness, signd, silence_arr) { \ 15 + .format = SNDRV_PCM_FORMAT_##fmt, .physical_bits = pbits, \ 16 + .width = wd, .le = endianness, .sd = signd, .silence = silence_arr, \ 17 + .name = #fmt, \ 18 + } 19 + 20 + #define WRONG_FORMAT_1 (__force snd_pcm_format_t)((__force int)SNDRV_PCM_FORMAT_LAST + 1) 21 + #define WRONG_FORMAT_2 (__force snd_pcm_format_t)-1 22 + 23 + #define VALID_NAME "ValidName" 24 + #define NAME_W_SPEC_CHARS "In%v@1id name" 25 + #define NAME_W_SPACE "Test name" 26 + #define NAME_W_SPACE_REMOVED "Testname" 27 + 28 + #define TEST_FIRST_COMPONENT "Component1" 29 + #define TEST_SECOND_COMPONENT "Component2" 30 + 31 + struct snd_format_test_data { 32 + snd_pcm_format_t format; 33 + int physical_bits; 34 + int width; 35 + int le; 36 + int sd; 37 + unsigned char silence[8]; 38 + unsigned char *name; 39 + }; 40 + 41 + struct avail_test_data { 42 + snd_pcm_uframes_t buffer_size; 43 + snd_pcm_uframes_t hw_ptr; 44 + snd_pcm_uframes_t appl_ptr; 45 + snd_pcm_uframes_t expected_avail; 46 + }; 47 + 48 + static struct snd_format_test_data valid_fmt[] = { 49 + DEFINE_FORMAT(S8, 8, 8, -1, 1, SILENCE()), 50 + DEFINE_FORMAT(U8, 8, 8, -1, 0, SILENCE(0x80)), 51 + DEFINE_FORMAT(S16_LE, 16, 16, 1, 1, SILENCE()), 52 + DEFINE_FORMAT(S16_BE, 16, 16, 0, 1, SILENCE()), 53 + DEFINE_FORMAT(U16_LE, 16, 16, 1, 0, SILENCE(0x00, 0x80)), 54 + DEFINE_FORMAT(U16_BE, 16, 16, 0, 0, SILENCE(0x80, 0x00)), 55 + DEFINE_FORMAT(S24_LE, 32, 24, 1, 1, SILENCE()), 56 + DEFINE_FORMAT(S24_BE, 32, 24, 0, 1, SILENCE()), 57 + DEFINE_FORMAT(U24_LE, 32, 24, 1, 0, SILENCE(0x00, 0x00, 0x80)), 58 + DEFINE_FORMAT(U24_BE, 32, 24, 0, 0, SILENCE(0x00, 0x80, 0x00, 0x00)), 59 + DEFINE_FORMAT(S32_LE, 32, 32, 1, 1, SILENCE()), 60 + DEFINE_FORMAT(S32_BE, 32, 32, 0, 1, SILENCE()), 61 + DEFINE_FORMAT(U32_LE, 32, 32, 1, 0, SILENCE(0x00, 0x00, 0x00, 0x80)), 62 + DEFINE_FORMAT(U32_BE, 32, 32, 0, 0, SILENCE(0x80, 0x00, 0x00, 0x00)), 63 + DEFINE_FORMAT(FLOAT_LE, 32, 32, 1, -1, SILENCE()), 64 + DEFINE_FORMAT(FLOAT_BE, 32, 32, 0, -1, SILENCE()), 65 + DEFINE_FORMAT(FLOAT64_LE, 64, 64, 1, -1, SILENCE()), 66 + DEFINE_FORMAT(FLOAT64_BE, 64, 64, 0, -1, SILENCE()), 67 + DEFINE_FORMAT(IEC958_SUBFRAME_LE, 32, 32, 1, -1, SILENCE()), 68 + DEFINE_FORMAT(IEC958_SUBFRAME_BE, 32, 32, 0, -1, SILENCE()), 69 + DEFINE_FORMAT(MU_LAW, 8, 8, -1, -1, SILENCE(0x7f)), 70 + DEFINE_FORMAT(A_LAW, 8, 8, -1, -1, SILENCE(0x55)), 71 + DEFINE_FORMAT(IMA_ADPCM, 4, 4, -1, -1, SILENCE()), 72 + DEFINE_FORMAT(G723_24, 3, 3, -1, -1, SILENCE()), 73 + DEFINE_FORMAT(G723_40, 5, 5, -1, -1, SILENCE()), 74 + DEFINE_FORMAT(DSD_U8, 8, 8, 1, 0, SILENCE(0x69)), 75 + DEFINE_FORMAT(DSD_U16_LE, 16, 16, 1, 0, SILENCE(0x69, 0x69)), 76 + DEFINE_FORMAT(DSD_U32_LE, 32, 32, 1, 0, SILENCE(0x69, 0x69, 0x69, 0x69)), 77 + DEFINE_FORMAT(DSD_U16_BE, 16, 16, 0, 0, SILENCE(0x69, 0x69)), 78 + DEFINE_FORMAT(DSD_U32_BE, 32, 32, 0, 0, SILENCE(0x69, 0x69, 0x69, 0x69)), 79 + DEFINE_FORMAT(S20_LE, 32, 20, 1, 1, SILENCE()), 80 + DEFINE_FORMAT(S20_BE, 32, 20, 0, 1, SILENCE()), 81 + DEFINE_FORMAT(U20_LE, 32, 20, 1, 0, SILENCE(0x00, 0x00, 0x08, 0x00)), 82 + DEFINE_FORMAT(U20_BE, 32, 20, 0, 0, SILENCE(0x00, 0x08, 0x00, 0x00)), 83 + DEFINE_FORMAT(S24_3LE, 24, 24, 1, 1, SILENCE()), 84 + DEFINE_FORMAT(S24_3BE, 24, 24, 0, 1, SILENCE()), 85 + DEFINE_FORMAT(U24_3LE, 24, 24, 1, 0, SILENCE(0x00, 0x00, 0x80)), 86 + DEFINE_FORMAT(U24_3BE, 24, 24, 0, 0, SILENCE(0x80, 0x00, 0x00)), 87 + DEFINE_FORMAT(S20_3LE, 24, 20, 1, 1, SILENCE()), 88 + DEFINE_FORMAT(S20_3BE, 24, 20, 0, 1, SILENCE()), 89 + DEFINE_FORMAT(U20_3LE, 24, 20, 1, 0, SILENCE(0x00, 0x00, 0x08)), 90 + DEFINE_FORMAT(U20_3BE, 24, 20, 0, 0, SILENCE(0x08, 0x00, 0x00)), 91 + DEFINE_FORMAT(S18_3LE, 24, 18, 1, 1, SILENCE()), 92 + DEFINE_FORMAT(S18_3BE, 24, 18, 0, 1, SILENCE()), 93 + DEFINE_FORMAT(U18_3LE, 24, 18, 1, 0, SILENCE(0x00, 0x00, 0x02)), 94 + DEFINE_FORMAT(U18_3BE, 24, 18, 0, 0, SILENCE(0x02, 0x00, 0x00)), 95 + DEFINE_FORMAT(G723_24_1B, 8, 3, -1, -1, SILENCE()), 96 + DEFINE_FORMAT(G723_40_1B, 8, 5, -1, -1, SILENCE()), 97 + }; 98 + 99 + static void test_phys_format_size(struct kunit *test) 100 + { 101 + u32 i; 102 + 103 + for (i = 0; i < ARRAY_SIZE(valid_fmt); i++) { 104 + KUNIT_EXPECT_EQ(test, snd_pcm_format_physical_width(valid_fmt[i].format), 105 + valid_fmt[i].physical_bits); 106 + } 107 + 108 + KUNIT_EXPECT_EQ(test, snd_pcm_format_physical_width(WRONG_FORMAT_1), -EINVAL); 109 + KUNIT_EXPECT_EQ(test, snd_pcm_format_physical_width(WRONG_FORMAT_2), -EINVAL); 110 + } 111 + 112 + static void test_format_width(struct kunit *test) 113 + { 114 + u32 i; 115 + 116 + for (i = 0; i < ARRAY_SIZE(valid_fmt); i++) { 117 + KUNIT_EXPECT_EQ(test, snd_pcm_format_width(valid_fmt[i].format), 118 + valid_fmt[i].width); 119 + } 120 + 121 + KUNIT_EXPECT_EQ(test, snd_pcm_format_width(WRONG_FORMAT_1), -EINVAL); 122 + KUNIT_EXPECT_EQ(test, snd_pcm_format_width(WRONG_FORMAT_2), -EINVAL); 123 + } 124 + 125 + static void test_format_signed(struct kunit *test) 126 + { 127 + u32 i; 128 + 129 + for (i = 0; i < ARRAY_SIZE(valid_fmt); i++) { 130 + KUNIT_EXPECT_EQ(test, snd_pcm_format_signed(valid_fmt[i].format), 131 + valid_fmt[i].sd < 0 ? -EINVAL : valid_fmt[i].sd); 132 + KUNIT_EXPECT_EQ(test, snd_pcm_format_unsigned(valid_fmt[i].format), 133 + valid_fmt[i].sd < 0 ? -EINVAL : 1 - valid_fmt[i].sd); 134 + } 135 + 136 + KUNIT_EXPECT_EQ(test, snd_pcm_format_width(WRONG_FORMAT_1), -EINVAL); 137 + KUNIT_EXPECT_EQ(test, snd_pcm_format_width(WRONG_FORMAT_2), -EINVAL); 138 + } 139 + 140 + static void test_format_endianness(struct kunit *test) 141 + { 142 + u32 i; 143 + 144 + for (i = 0; i < ARRAY_SIZE(valid_fmt); i++) { 145 + KUNIT_EXPECT_EQ(test, snd_pcm_format_little_endian(valid_fmt[i].format), 146 + valid_fmt[i].le < 0 ? -EINVAL : valid_fmt[i].le); 147 + KUNIT_EXPECT_EQ(test, snd_pcm_format_big_endian(valid_fmt[i].format), 148 + valid_fmt[i].le < 0 ? -EINVAL : 1 - valid_fmt[i].le); 149 + } 150 + 151 + KUNIT_EXPECT_EQ(test, snd_pcm_format_little_endian(WRONG_FORMAT_1), -EINVAL); 152 + KUNIT_EXPECT_EQ(test, snd_pcm_format_little_endian(WRONG_FORMAT_2), -EINVAL); 153 + KUNIT_EXPECT_EQ(test, snd_pcm_format_big_endian(WRONG_FORMAT_1), -EINVAL); 154 + KUNIT_EXPECT_EQ(test, snd_pcm_format_big_endian(WRONG_FORMAT_2), -EINVAL); 155 + } 156 + 157 + static void _test_fill_silence(struct kunit *test, struct snd_format_test_data *data, 158 + u8 *buffer, size_t samples_count) 159 + { 160 + size_t sample_bytes = data->physical_bits >> 3; 161 + u32 i; 162 + 163 + KUNIT_ASSERT_EQ(test, snd_pcm_format_set_silence(data->format, buffer, samples_count), 0); 164 + for (i = 0; i < samples_count * sample_bytes; i++) 165 + KUNIT_EXPECT_EQ(test, buffer[i], data->silence[i % sample_bytes]); 166 + } 167 + 168 + static void test_format_fill_silence(struct kunit *test) 169 + { 170 + u32 buf_samples[] = { 10, 20, 32, 64, 129, SILENCE_BUFFER_MAX_FRAMES }; 171 + u8 *buffer; 172 + u32 i, j; 173 + 174 + buffer = kunit_kzalloc(test, SILENCE_BUFFER_SIZE, GFP_KERNEL); 175 + 176 + for (i = 0; i < ARRAY_SIZE(buf_samples); i++) { 177 + for (j = 0; j < ARRAY_SIZE(valid_fmt); j++) 178 + _test_fill_silence(test, &valid_fmt[j], buffer, buf_samples[i]); 179 + } 180 + 181 + KUNIT_EXPECT_EQ(test, snd_pcm_format_set_silence(WRONG_FORMAT_1, buffer, 20), -EINVAL); 182 + KUNIT_EXPECT_EQ(test, snd_pcm_format_set_silence(SNDRV_PCM_FORMAT_LAST, buffer, 0), 0); 183 + } 184 + 185 + static snd_pcm_uframes_t calculate_boundary(snd_pcm_uframes_t buffer_size) 186 + { 187 + snd_pcm_uframes_t boundary = buffer_size; 188 + 189 + while (boundary * 2 <= 0x7fffffffUL - buffer_size) 190 + boundary *= 2; 191 + return boundary; 192 + } 193 + 194 + static struct avail_test_data p_avail_data[] = { 195 + /* buf_size + hw_ptr < appl_ptr => avail = buf_size + hw_ptr - appl_ptr + boundary */ 196 + { 128, 1000, 1129, 1073741824UL - 1 }, 197 + /* 198 + * buf_size + hw_ptr - appl_ptr >= boundary => 199 + * => avail = buf_size + hw_ptr - appl_ptr - boundary 200 + */ 201 + { 128, 1073741824UL, 10, 118 }, 202 + /* standard case: avail = buf_size + hw_ptr - appl_ptr */ 203 + { 128, 1000, 1001, 127 }, 204 + }; 205 + 206 + static void test_playback_avail(struct kunit *test) 207 + { 208 + struct snd_pcm_runtime *r = kunit_kzalloc(test, sizeof(*r), GFP_KERNEL); 209 + u32 i; 210 + 211 + r->status = kunit_kzalloc(test, sizeof(*r->status), GFP_KERNEL); 212 + r->control = kunit_kzalloc(test, sizeof(*r->control), GFP_KERNEL); 213 + 214 + for (i = 0; i < ARRAY_SIZE(p_avail_data); i++) { 215 + r->buffer_size = p_avail_data[i].buffer_size; 216 + r->boundary = calculate_boundary(r->buffer_size); 217 + r->status->hw_ptr = p_avail_data[i].hw_ptr; 218 + r->control->appl_ptr = p_avail_data[i].appl_ptr; 219 + KUNIT_EXPECT_EQ(test, snd_pcm_playback_avail(r), p_avail_data[i].expected_avail); 220 + } 221 + } 222 + 223 + static struct avail_test_data c_avail_data[] = { 224 + /* hw_ptr - appl_ptr < 0 => avail = hw_ptr - appl_ptr + boundary */ 225 + { 128, 1000, 1001, 1073741824UL - 1 }, 226 + /* standard case: avail = hw_ptr - appl_ptr */ 227 + { 128, 1001, 1000, 1 }, 228 + }; 229 + 230 + static void test_capture_avail(struct kunit *test) 231 + { 232 + struct snd_pcm_runtime *r = kunit_kzalloc(test, sizeof(*r), GFP_KERNEL); 233 + u32 i; 234 + 235 + r->status = kunit_kzalloc(test, sizeof(*r->status), GFP_KERNEL); 236 + r->control = kunit_kzalloc(test, sizeof(*r->control), GFP_KERNEL); 237 + 238 + for (i = 0; i < ARRAY_SIZE(c_avail_data); i++) { 239 + r->buffer_size = c_avail_data[i].buffer_size; 240 + r->boundary = calculate_boundary(r->buffer_size); 241 + r->status->hw_ptr = c_avail_data[i].hw_ptr; 242 + r->control->appl_ptr = c_avail_data[i].appl_ptr; 243 + KUNIT_EXPECT_EQ(test, snd_pcm_capture_avail(r), c_avail_data[i].expected_avail); 244 + } 245 + } 246 + 247 + static void test_card_set_id(struct kunit *test) 248 + { 249 + struct snd_card *card = kunit_kzalloc(test, sizeof(*card), GFP_KERNEL); 250 + 251 + snd_card_set_id(card, VALID_NAME); 252 + KUNIT_EXPECT_STREQ(test, card->id, VALID_NAME); 253 + 254 + /* clear the first id character so we can set it again */ 255 + card->id[0] = '\0'; 256 + snd_card_set_id(card, NAME_W_SPEC_CHARS); 257 + KUNIT_EXPECT_STRNEQ(test, card->id, NAME_W_SPEC_CHARS); 258 + 259 + card->id[0] = '\0'; 260 + snd_card_set_id(card, NAME_W_SPACE); 261 + kunit_info(test, "%s", card->id); 262 + KUNIT_EXPECT_STREQ(test, card->id, NAME_W_SPACE_REMOVED); 263 + } 264 + 265 + static void test_pcm_format_name(struct kunit *test) 266 + { 267 + u32 i; 268 + const char *name; 269 + 270 + for (i = 0; i < ARRAY_SIZE(valid_fmt); i++) { 271 + name = snd_pcm_format_name(valid_fmt[i].format); 272 + KUNIT_ASSERT_NOT_NULL_MSG(test, name, "Don't have name for %s", valid_fmt[i].name); 273 + KUNIT_EXPECT_STREQ(test, name, valid_fmt[i].name); 274 + } 275 + 276 + KUNIT_ASSERT_STREQ(test, snd_pcm_format_name(WRONG_FORMAT_1), "Unknown"); 277 + KUNIT_ASSERT_STREQ(test, snd_pcm_format_name(WRONG_FORMAT_2), "Unknown"); 278 + } 279 + 280 + static void test_card_add_component(struct kunit *test) 281 + { 282 + struct snd_card *card = kunit_kzalloc(test, sizeof(*card), GFP_KERNEL); 283 + 284 + snd_component_add(card, TEST_FIRST_COMPONENT); 285 + KUNIT_ASSERT_STREQ(test, card->components, TEST_FIRST_COMPONENT); 286 + 287 + snd_component_add(card, TEST_SECOND_COMPONENT); 288 + KUNIT_ASSERT_STREQ(test, card->components, TEST_FIRST_COMPONENT " " TEST_SECOND_COMPONENT); 289 + } 290 + 291 + static struct kunit_case sound_utils_cases[] = { 292 + KUNIT_CASE(test_phys_format_size), 293 + KUNIT_CASE(test_format_width), 294 + KUNIT_CASE(test_format_endianness), 295 + KUNIT_CASE(test_format_signed), 296 + KUNIT_CASE(test_format_fill_silence), 297 + KUNIT_CASE(test_playback_avail), 298 + KUNIT_CASE(test_capture_avail), 299 + KUNIT_CASE(test_card_set_id), 300 + KUNIT_CASE(test_pcm_format_name), 301 + KUNIT_CASE(test_card_add_component), 302 + {}, 303 + }; 304 + 305 + static struct kunit_suite sound_utils_suite = { 306 + .name = "sound-core-test", 307 + .test_cases = sound_utils_cases, 308 + }; 309 + 310 + kunit_test_suite(sound_utils_suite); 311 + MODULE_AUTHOR("Ivan Orlov"); 312 + MODULE_LICENSE("GPL");
+5 -12
sound/core/sound_oss.c
··· 29 29 30 30 if (minor >= ARRAY_SIZE(snd_oss_minors)) 31 31 return NULL; 32 - mutex_lock(&sound_oss_mutex); 32 + guard(mutex)(&sound_oss_mutex); 33 33 mreg = snd_oss_minors[minor]; 34 34 if (mreg && mreg->type == type) { 35 35 private_data = mreg->private_data; ··· 37 37 get_device(&mreg->card_ptr->card_dev); 38 38 } else 39 39 private_data = NULL; 40 - mutex_unlock(&sound_oss_mutex); 41 40 return private_data; 42 41 } 43 42 EXPORT_SYMBOL(snd_lookup_oss_minor_data); ··· 105 106 preg->f_ops = f_ops; 106 107 preg->private_data = private_data; 107 108 preg->card_ptr = card; 108 - mutex_lock(&sound_oss_mutex); 109 + guard(mutex)(&sound_oss_mutex); 109 110 snd_oss_minors[minor] = preg; 110 111 minor_unit = SNDRV_MINOR_OSS_DEVICE(minor); 111 112 switch (minor_unit) { ··· 129 130 goto __end; 130 131 snd_oss_minors[track2] = preg; 131 132 } 132 - mutex_unlock(&sound_oss_mutex); 133 133 return 0; 134 134 135 135 __end: ··· 137 139 if (register1 >= 0) 138 140 unregister_sound_special(register1); 139 141 snd_oss_minors[minor] = NULL; 140 - mutex_unlock(&sound_oss_mutex); 141 142 kfree(preg); 142 143 return -EBUSY; 143 144 } ··· 153 156 return 0; 154 157 if (minor < 0) 155 158 return minor; 156 - mutex_lock(&sound_oss_mutex); 159 + guard(mutex)(&sound_oss_mutex); 157 160 mptr = snd_oss_minors[minor]; 158 - if (mptr == NULL) { 159 - mutex_unlock(&sound_oss_mutex); 161 + if (mptr == NULL) 160 162 return -ENOENT; 161 - } 162 163 switch (SNDRV_MINOR_OSS_DEVICE(minor)) { 163 164 case SNDRV_MINOR_OSS_PCM: 164 165 track2 = SNDRV_MINOR_OSS(cidx, SNDRV_MINOR_OSS_AUDIO); ··· 171 176 if (track2 >= 0) 172 177 snd_oss_minors[track2] = NULL; 173 178 snd_oss_minors[minor] = NULL; 174 - mutex_unlock(&sound_oss_mutex); 175 179 176 180 /* call unregister_sound_special() outside sound_oss_mutex; 177 181 * otherwise may deadlock, as it can trigger the release of a card ··· 214 220 int minor; 215 221 struct snd_minor *mptr; 216 222 217 - mutex_lock(&sound_oss_mutex); 223 + guard(mutex)(&sound_oss_mutex); 218 224 for (minor = 0; minor < SNDRV_OSS_MINORS; ++minor) { 219 225 mptr = snd_oss_minors[minor]; 220 226 if (!mptr) ··· 227 233 snd_iprintf(buffer, "%3i: : %s\n", minor, 228 234 snd_oss_device_type_name(mptr->type)); 229 235 } 230 - mutex_unlock(&sound_oss_mutex); 231 236 } 232 237 233 238
+180 -262
sound/core/timer.c
··· 224 224 return -EBUSY; 225 225 list_move_tail(&slave->open_list, &master->slave_list_head); 226 226 master->timer->num_instances++; 227 - spin_lock_irq(&slave_active_lock); 228 - spin_lock(&master->timer->lock); 227 + guard(spinlock_irq)(&slave_active_lock); 228 + guard(spinlock)(&master->timer->lock); 229 229 slave->master = master; 230 230 slave->timer = master->timer; 231 231 if (slave->flags & SNDRV_TIMER_IFLG_RUNNING) 232 232 list_add_tail(&slave->active_list, &master->slave_active_head); 233 - spin_unlock(&master->timer->lock); 234 - spin_unlock_irq(&slave_active_lock); 235 233 return 1; 236 234 } 237 235 ··· 380 382 } 381 383 EXPORT_SYMBOL(snd_timer_open); 382 384 385 + /* remove slave links, called from snd_timer_close_locked() below */ 386 + static void remove_slave_links(struct snd_timer_instance *timeri, 387 + struct snd_timer *timer) 388 + { 389 + struct snd_timer_instance *slave, *tmp; 390 + 391 + guard(spinlock_irq)(&slave_active_lock); 392 + guard(spinlock)(&timer->lock); 393 + timeri->timer = NULL; 394 + list_for_each_entry_safe(slave, tmp, &timeri->slave_list_head, open_list) { 395 + list_move_tail(&slave->open_list, &snd_timer_slave_list); 396 + timer->num_instances--; 397 + slave->master = NULL; 398 + slave->timer = NULL; 399 + list_del_init(&slave->ack_list); 400 + list_del_init(&slave->active_list); 401 + } 402 + } 403 + 383 404 /* 384 405 * close a timer instance 385 406 * call this with register_mutex down. ··· 407 390 struct device **card_devp_to_put) 408 391 { 409 392 struct snd_timer *timer = timeri->timer; 410 - struct snd_timer_instance *slave, *tmp; 411 393 412 394 if (timer) { 413 - spin_lock_irq(&timer->lock); 395 + guard(spinlock)(&timer->lock); 414 396 timeri->flags |= SNDRV_TIMER_IFLG_DEAD; 415 - spin_unlock_irq(&timer->lock); 416 397 } 417 398 418 399 if (!list_empty(&timeri->open_list)) { ··· 433 418 } 434 419 spin_unlock_irq(&timer->lock); 435 420 436 - /* remove slave links */ 437 - spin_lock_irq(&slave_active_lock); 438 - spin_lock(&timer->lock); 439 - timeri->timer = NULL; 440 - list_for_each_entry_safe(slave, tmp, &timeri->slave_list_head, 441 - open_list) { 442 - list_move_tail(&slave->open_list, &snd_timer_slave_list); 443 - timer->num_instances--; 444 - slave->master = NULL; 445 - slave->timer = NULL; 446 - list_del_init(&slave->ack_list); 447 - list_del_init(&slave->active_list); 448 - } 449 - spin_unlock(&timer->lock); 450 - spin_unlock_irq(&slave_active_lock); 421 + remove_slave_links(timeri, timer); 451 422 452 423 /* slave doesn't need to release timer resources below */ 453 424 if (timeri->flags & SNDRV_TIMER_IFLG_SLAVE) ··· 460 459 if (snd_BUG_ON(!timeri)) 461 460 return; 462 461 463 - mutex_lock(&register_mutex); 464 - snd_timer_close_locked(timeri, &card_dev_to_put); 465 - mutex_unlock(&register_mutex); 462 + scoped_guard(mutex, &register_mutex) 463 + snd_timer_close_locked(timeri, &card_dev_to_put); 466 464 /* put_device() is called after unlock for avoiding deadlock */ 467 465 if (card_dev_to_put) 468 466 put_device(card_dev_to_put); ··· 480 480 { 481 481 struct snd_timer * timer; 482 482 unsigned long ret = 0; 483 - unsigned long flags; 484 483 485 484 if (timeri == NULL) 486 485 return 0; 487 486 timer = timeri->timer; 488 487 if (timer) { 489 - spin_lock_irqsave(&timer->lock, flags); 488 + guard(spinlock_irqsave)(&timer->lock); 490 489 ret = snd_timer_hw_resolution(timer); 491 - spin_unlock_irqrestore(&timer->lock, flags); 492 490 } 493 491 return ret; 494 492 } ··· 530 532 { 531 533 struct snd_timer *timer; 532 534 int result; 533 - unsigned long flags; 534 535 535 536 timer = timeri->timer; 536 537 if (!timer) 537 538 return -EINVAL; 538 539 539 - spin_lock_irqsave(&timer->lock, flags); 540 - if (timeri->flags & SNDRV_TIMER_IFLG_DEAD) { 541 - result = -EINVAL; 542 - goto unlock; 543 - } 544 - if (timer->card && timer->card->shutdown) { 545 - result = -ENODEV; 546 - goto unlock; 547 - } 540 + guard(spinlock_irqsave)(&timer->lock); 541 + if (timeri->flags & SNDRV_TIMER_IFLG_DEAD) 542 + return -EINVAL; 543 + if (timer->card && timer->card->shutdown) 544 + return -ENODEV; 548 545 if (timeri->flags & (SNDRV_TIMER_IFLG_RUNNING | 549 - SNDRV_TIMER_IFLG_START)) { 550 - result = -EBUSY; 551 - goto unlock; 552 - } 546 + SNDRV_TIMER_IFLG_START)) 547 + return -EBUSY; 553 548 554 549 if (start) 555 550 timeri->ticks = timeri->cticks = ticks; ··· 568 577 } 569 578 snd_timer_notify1(timeri, start ? SNDRV_TIMER_EVENT_START : 570 579 SNDRV_TIMER_EVENT_CONTINUE); 571 - unlock: 572 - spin_unlock_irqrestore(&timer->lock, flags); 573 580 return result; 574 581 } 575 582 ··· 575 586 static int snd_timer_start_slave(struct snd_timer_instance *timeri, 576 587 bool start) 577 588 { 578 - unsigned long flags; 579 - int err; 580 - 581 - spin_lock_irqsave(&slave_active_lock, flags); 582 - if (timeri->flags & SNDRV_TIMER_IFLG_DEAD) { 583 - err = -EINVAL; 584 - goto unlock; 585 - } 586 - if (timeri->flags & SNDRV_TIMER_IFLG_RUNNING) { 587 - err = -EBUSY; 588 - goto unlock; 589 - } 589 + guard(spinlock_irqsave)(&slave_active_lock); 590 + if (timeri->flags & SNDRV_TIMER_IFLG_DEAD) 591 + return -EINVAL; 592 + if (timeri->flags & SNDRV_TIMER_IFLG_RUNNING) 593 + return -EBUSY; 590 594 timeri->flags |= SNDRV_TIMER_IFLG_RUNNING; 591 595 if (timeri->master && timeri->timer) { 592 - spin_lock(&timeri->timer->lock); 596 + guard(spinlock)(&timeri->timer->lock); 593 597 list_add_tail(&timeri->active_list, 594 598 &timeri->master->slave_active_head); 595 599 snd_timer_notify1(timeri, start ? SNDRV_TIMER_EVENT_START : 596 600 SNDRV_TIMER_EVENT_CONTINUE); 597 - spin_unlock(&timeri->timer->lock); 598 601 } 599 - err = 1; /* delayed start */ 600 - unlock: 601 - spin_unlock_irqrestore(&slave_active_lock, flags); 602 - return err; 602 + return 1; /* delayed start */ 603 603 } 604 604 605 605 /* stop/pause a master timer */ 606 606 static int snd_timer_stop1(struct snd_timer_instance *timeri, bool stop) 607 607 { 608 608 struct snd_timer *timer; 609 - int result = 0; 610 - unsigned long flags; 611 609 612 610 timer = timeri->timer; 613 611 if (!timer) 614 612 return -EINVAL; 615 - spin_lock_irqsave(&timer->lock, flags); 613 + guard(spinlock_irqsave)(&timer->lock); 616 614 list_del_init(&timeri->ack_list); 617 615 list_del_init(&timeri->active_list); 618 616 if (!(timeri->flags & (SNDRV_TIMER_IFLG_RUNNING | 619 - SNDRV_TIMER_IFLG_START))) { 620 - result = -EBUSY; 621 - goto unlock; 622 - } 617 + SNDRV_TIMER_IFLG_START))) 618 + return -EBUSY; 623 619 if (timer->card && timer->card->shutdown) 624 - goto unlock; 620 + return 0; 625 621 if (stop) { 626 622 timeri->cticks = timeri->ticks; 627 623 timeri->pticks = 0; ··· 630 656 timeri->flags |= SNDRV_TIMER_IFLG_PAUSED; 631 657 snd_timer_notify1(timeri, stop ? SNDRV_TIMER_EVENT_STOP : 632 658 SNDRV_TIMER_EVENT_PAUSE); 633 - unlock: 634 - spin_unlock_irqrestore(&timer->lock, flags); 635 - return result; 659 + return 0; 636 660 } 637 661 638 662 /* stop/pause a slave timer */ 639 663 static int snd_timer_stop_slave(struct snd_timer_instance *timeri, bool stop) 640 664 { 641 - unsigned long flags; 642 665 bool running; 643 666 644 - spin_lock_irqsave(&slave_active_lock, flags); 667 + guard(spinlock_irqsave)(&slave_active_lock); 645 668 running = timeri->flags & SNDRV_TIMER_IFLG_RUNNING; 646 669 timeri->flags &= ~SNDRV_TIMER_IFLG_RUNNING; 647 670 if (timeri->timer) { 648 - spin_lock(&timeri->timer->lock); 671 + guard(spinlock)(&timeri->timer->lock); 649 672 list_del_init(&timeri->ack_list); 650 673 list_del_init(&timeri->active_list); 651 674 if (running) 652 675 snd_timer_notify1(timeri, stop ? SNDRV_TIMER_EVENT_STOP : 653 676 SNDRV_TIMER_EVENT_PAUSE); 654 - spin_unlock(&timeri->timer->lock); 655 677 } 656 - spin_unlock_irqrestore(&slave_active_lock, flags); 657 678 return running ? 0 : -EBUSY; 658 679 } 659 680 ··· 773 804 static void snd_timer_clear_callbacks(struct snd_timer *timer, 774 805 struct list_head *head) 775 806 { 776 - unsigned long flags; 777 - 778 - spin_lock_irqsave(&timer->lock, flags); 807 + guard(spinlock_irqsave)(&timer->lock); 779 808 while (!list_empty(head)) 780 809 list_del_init(head->next); 781 - spin_unlock_irqrestore(&timer->lock, flags); 782 810 } 783 811 784 812 /* ··· 785 819 static void snd_timer_work(struct work_struct *work) 786 820 { 787 821 struct snd_timer *timer = container_of(work, struct snd_timer, task_work); 788 - unsigned long flags; 789 822 790 823 if (timer->card && timer->card->shutdown) { 791 824 snd_timer_clear_callbacks(timer, &timer->sack_list_head); 792 825 return; 793 826 } 794 827 795 - spin_lock_irqsave(&timer->lock, flags); 828 + guard(spinlock_irqsave)(&timer->lock); 796 829 snd_timer_process_callbacks(timer, &timer->sack_list_head); 797 - spin_unlock_irqrestore(&timer->lock, flags); 798 830 } 799 831 800 832 /* ··· 806 842 struct snd_timer_instance *ti, *ts, *tmp; 807 843 unsigned long resolution; 808 844 struct list_head *ack_list_head; 809 - unsigned long flags; 810 - bool use_work = false; 811 845 812 846 if (timer == NULL) 813 847 return; ··· 815 853 return; 816 854 } 817 855 818 - spin_lock_irqsave(&timer->lock, flags); 856 + guard(spinlock_irqsave)(&timer->lock); 819 857 820 858 /* remember the current resolution */ 821 859 resolution = snd_timer_hw_resolution(timer); ··· 881 919 snd_timer_process_callbacks(timer, &timer->ack_list_head); 882 920 883 921 /* do we have any slow callbacks? */ 884 - use_work = !list_empty(&timer->sack_list_head); 885 - spin_unlock_irqrestore(&timer->lock, flags); 886 - 887 - if (use_work) 922 + if (!list_empty(&timer->sack_list_head)) 888 923 queue_work(system_highpri_wq, &timer->task_work); 889 924 } 890 925 EXPORT_SYMBOL(snd_timer_interrupt); ··· 947 988 if (!timer) 948 989 return 0; 949 990 950 - mutex_lock(&register_mutex); 991 + guard(mutex)(&register_mutex); 951 992 if (! list_empty(&timer->open_list_head)) { 952 993 struct list_head *p, *n; 953 994 struct snd_timer_instance *ti; ··· 959 1000 } 960 1001 } 961 1002 list_del(&timer->device_list); 962 - mutex_unlock(&register_mutex); 963 1003 964 1004 if (timer->private_free) 965 1005 timer->private_free(timer); ··· 983 1025 !timer->hw.resolution && timer->hw.c_resolution == NULL) 984 1026 return -EINVAL; 985 1027 986 - mutex_lock(&register_mutex); 1028 + guard(mutex)(&register_mutex); 987 1029 list_for_each_entry(timer1, &snd_timer_list, device_list) { 988 1030 if (timer1->tmr_class > timer->tmr_class) 989 1031 break; ··· 1004 1046 if (timer1->tmr_subdevice < timer->tmr_subdevice) 1005 1047 continue; 1006 1048 /* conflicts.. */ 1007 - mutex_unlock(&register_mutex); 1008 1049 return -EBUSY; 1009 1050 } 1010 1051 list_add_tail(&timer->device_list, &timer1->device_list); 1011 - mutex_unlock(&register_mutex); 1012 1052 return 0; 1013 1053 } 1014 1054 ··· 1015 1059 struct snd_timer *timer = device->device_data; 1016 1060 struct snd_timer_instance *ti; 1017 1061 1018 - mutex_lock(&register_mutex); 1062 + guard(mutex)(&register_mutex); 1019 1063 list_del_init(&timer->device_list); 1020 1064 /* wake up pending sleepers */ 1021 1065 list_for_each_entry(ti, &timer->open_list_head, open_list) { 1022 1066 if (ti->disconnect) 1023 1067 ti->disconnect(ti); 1024 1068 } 1025 - mutex_unlock(&register_mutex); 1026 1069 return 0; 1027 1070 } 1028 1071 1029 1072 void snd_timer_notify(struct snd_timer *timer, int event, struct timespec64 *tstamp) 1030 1073 { 1031 - unsigned long flags; 1032 1074 unsigned long resolution = 0; 1033 1075 struct snd_timer_instance *ti, *ts; 1034 1076 ··· 1037 1083 if (snd_BUG_ON(event < SNDRV_TIMER_EVENT_MSTART || 1038 1084 event > SNDRV_TIMER_EVENT_MRESUME)) 1039 1085 return; 1040 - spin_lock_irqsave(&timer->lock, flags); 1086 + guard(spinlock_irqsave)(&timer->lock); 1041 1087 if (event == SNDRV_TIMER_EVENT_MSTART || 1042 1088 event == SNDRV_TIMER_EVENT_MCONTINUE || 1043 1089 event == SNDRV_TIMER_EVENT_MRESUME) ··· 1049 1095 if (ts->ccallback) 1050 1096 ts->ccallback(ts, event, tstamp, resolution); 1051 1097 } 1052 - spin_unlock_irqrestore(&timer->lock, flags); 1053 1098 } 1054 1099 EXPORT_SYMBOL(snd_timer_notify); 1055 1100 ··· 1201 1248 struct snd_timer_instance *ti; 1202 1249 unsigned long resolution; 1203 1250 1204 - mutex_lock(&register_mutex); 1251 + guard(mutex)(&register_mutex); 1205 1252 list_for_each_entry(timer, &snd_timer_list, device_list) { 1206 1253 if (timer->card && timer->card->shutdown) 1207 1254 continue; ··· 1223 1270 timer->tmr_device, timer->tmr_subdevice); 1224 1271 } 1225 1272 snd_iprintf(buffer, "%s :", timer->name); 1226 - spin_lock_irq(&timer->lock); 1227 - resolution = snd_timer_hw_resolution(timer); 1228 - spin_unlock_irq(&timer->lock); 1273 + scoped_guard(spinlock_irq, &timer->lock) 1274 + resolution = snd_timer_hw_resolution(timer); 1229 1275 if (resolution) 1230 1276 snd_iprintf(buffer, " %lu.%03luus (%lu ticks)", 1231 1277 resolution / 1000, ··· 1240 1288 SNDRV_TIMER_IFLG_RUNNING)) 1241 1289 ? "running" : "stopped"); 1242 1290 } 1243 - mutex_unlock(&register_mutex); 1244 1291 } 1245 1292 1246 1293 static struct snd_info_entry *snd_timer_proc_entry; ··· 1280 1329 struct snd_timer_read *r; 1281 1330 int prev; 1282 1331 1283 - spin_lock(&tu->qlock); 1332 + guard(spinlock)(&tu->qlock); 1284 1333 if (tu->qused > 0) { 1285 1334 prev = tu->qtail == 0 ? tu->queue_size - 1 : tu->qtail - 1; 1286 1335 r = &tu->queue[prev]; ··· 1299 1348 tu->qused++; 1300 1349 } 1301 1350 __wake: 1302 - spin_unlock(&tu->qlock); 1303 1351 snd_kill_fasync(tu->fasync, SIGIO, POLL_IN); 1304 1352 wake_up(&tu->qchange_sleep); 1305 1353 } ··· 1322 1372 { 1323 1373 struct snd_timer_user *tu = timeri->callback_data; 1324 1374 struct snd_timer_tread64 r1; 1325 - unsigned long flags; 1326 1375 1327 1376 if (event >= SNDRV_TIMER_EVENT_START && 1328 1377 event <= SNDRV_TIMER_EVENT_PAUSE) ··· 1333 1384 r1.tstamp_sec = tstamp->tv_sec; 1334 1385 r1.tstamp_nsec = tstamp->tv_nsec; 1335 1386 r1.val = resolution; 1336 - spin_lock_irqsave(&tu->qlock, flags); 1337 - snd_timer_user_append_to_tqueue(tu, &r1); 1338 - spin_unlock_irqrestore(&tu->qlock, flags); 1387 + scoped_guard(spinlock_irqsave, &tu->qlock) 1388 + snd_timer_user_append_to_tqueue(tu, &r1); 1339 1389 snd_kill_fasync(tu->fasync, SIGIO, POLL_IN); 1340 1390 wake_up(&tu->qchange_sleep); 1341 1391 } ··· 1358 1410 1359 1411 memset(&r1, 0, sizeof(r1)); 1360 1412 memset(&tstamp, 0, sizeof(tstamp)); 1361 - spin_lock(&tu->qlock); 1362 - if ((tu->filter & ((1 << SNDRV_TIMER_EVENT_RESOLUTION) | 1363 - (1 << SNDRV_TIMER_EVENT_TICK))) == 0) { 1364 - spin_unlock(&tu->qlock); 1365 - return; 1366 - } 1367 - if (tu->last_resolution != resolution || ticks > 0) { 1368 - if (timer_tstamp_monotonic) 1369 - ktime_get_ts64(&tstamp); 1370 - else 1371 - ktime_get_real_ts64(&tstamp); 1372 - } 1373 - if ((tu->filter & (1 << SNDRV_TIMER_EVENT_RESOLUTION)) && 1374 - tu->last_resolution != resolution) { 1375 - r1.event = SNDRV_TIMER_EVENT_RESOLUTION; 1413 + scoped_guard(spinlock, &tu->qlock) { 1414 + if ((tu->filter & ((1 << SNDRV_TIMER_EVENT_RESOLUTION) | 1415 + (1 << SNDRV_TIMER_EVENT_TICK))) == 0) 1416 + return; 1417 + if (tu->last_resolution != resolution || ticks > 0) { 1418 + if (timer_tstamp_monotonic) 1419 + ktime_get_ts64(&tstamp); 1420 + else 1421 + ktime_get_real_ts64(&tstamp); 1422 + } 1423 + if ((tu->filter & (1 << SNDRV_TIMER_EVENT_RESOLUTION)) && 1424 + tu->last_resolution != resolution) { 1425 + r1.event = SNDRV_TIMER_EVENT_RESOLUTION; 1426 + r1.tstamp_sec = tstamp.tv_sec; 1427 + r1.tstamp_nsec = tstamp.tv_nsec; 1428 + r1.val = resolution; 1429 + snd_timer_user_append_to_tqueue(tu, &r1); 1430 + tu->last_resolution = resolution; 1431 + append++; 1432 + } 1433 + if ((tu->filter & (1 << SNDRV_TIMER_EVENT_TICK)) == 0) 1434 + break; 1435 + if (ticks == 0) 1436 + break; 1437 + if (tu->qused > 0) { 1438 + prev = tu->qtail == 0 ? tu->queue_size - 1 : tu->qtail - 1; 1439 + r = &tu->tqueue[prev]; 1440 + if (r->event == SNDRV_TIMER_EVENT_TICK) { 1441 + r->tstamp_sec = tstamp.tv_sec; 1442 + r->tstamp_nsec = tstamp.tv_nsec; 1443 + r->val += ticks; 1444 + append++; 1445 + break; 1446 + } 1447 + } 1448 + r1.event = SNDRV_TIMER_EVENT_TICK; 1376 1449 r1.tstamp_sec = tstamp.tv_sec; 1377 1450 r1.tstamp_nsec = tstamp.tv_nsec; 1378 - r1.val = resolution; 1451 + r1.val = ticks; 1379 1452 snd_timer_user_append_to_tqueue(tu, &r1); 1380 - tu->last_resolution = resolution; 1381 1453 append++; 1382 1454 } 1383 - if ((tu->filter & (1 << SNDRV_TIMER_EVENT_TICK)) == 0) 1384 - goto __wake; 1385 - if (ticks == 0) 1386 - goto __wake; 1387 - if (tu->qused > 0) { 1388 - prev = tu->qtail == 0 ? tu->queue_size - 1 : tu->qtail - 1; 1389 - r = &tu->tqueue[prev]; 1390 - if (r->event == SNDRV_TIMER_EVENT_TICK) { 1391 - r->tstamp_sec = tstamp.tv_sec; 1392 - r->tstamp_nsec = tstamp.tv_nsec; 1393 - r->val += ticks; 1394 - append++; 1395 - goto __wake; 1396 - } 1397 - } 1398 - r1.event = SNDRV_TIMER_EVENT_TICK; 1399 - r1.tstamp_sec = tstamp.tv_sec; 1400 - r1.tstamp_nsec = tstamp.tv_nsec; 1401 - r1.val = ticks; 1402 - snd_timer_user_append_to_tqueue(tu, &r1); 1403 - append++; 1404 - __wake: 1405 - spin_unlock(&tu->qlock); 1406 1455 if (append == 0) 1407 1456 return; 1408 1457 snd_kill_fasync(tu->fasync, SIGIO, POLL_IN); ··· 1421 1476 return -ENOMEM; 1422 1477 } 1423 1478 1424 - spin_lock_irq(&tu->qlock); 1479 + guard(spinlock_irq)(&tu->qlock); 1425 1480 kfree(tu->queue); 1426 1481 kfree(tu->tqueue); 1427 1482 tu->queue_size = size; 1428 1483 tu->queue = queue; 1429 1484 tu->tqueue = tqueue; 1430 1485 tu->qhead = tu->qtail = tu->qused = 0; 1431 - spin_unlock_irq(&tu->qlock); 1432 1486 1433 1487 return 0; 1434 1488 } ··· 1463 1519 if (file->private_data) { 1464 1520 tu = file->private_data; 1465 1521 file->private_data = NULL; 1466 - mutex_lock(&tu->ioctl_lock); 1467 - if (tu->timeri) { 1468 - snd_timer_close(tu->timeri); 1469 - snd_timer_instance_free(tu->timeri); 1522 + scoped_guard(mutex, &tu->ioctl_lock) { 1523 + if (tu->timeri) { 1524 + snd_timer_close(tu->timeri); 1525 + snd_timer_instance_free(tu->timeri); 1526 + } 1470 1527 } 1471 - mutex_unlock(&tu->ioctl_lock); 1472 1528 snd_fasync_free(tu->fasync); 1473 1529 kfree(tu->queue); 1474 1530 kfree(tu->tqueue); ··· 1503 1559 1504 1560 if (copy_from_user(&id, _tid, sizeof(id))) 1505 1561 return -EFAULT; 1506 - mutex_lock(&register_mutex); 1562 + guard(mutex)(&register_mutex); 1507 1563 if (id.dev_class < 0) { /* first item */ 1508 1564 if (list_empty(&snd_timer_list)) 1509 1565 snd_timer_user_zero_id(&id); ··· 1580 1636 snd_timer_user_zero_id(&id); 1581 1637 } 1582 1638 } 1583 - mutex_unlock(&register_mutex); 1584 1639 if (copy_to_user(_tid, &id, sizeof(*_tid))) 1585 1640 return -EFAULT; 1586 1641 return 0; ··· 1588 1645 static int snd_timer_user_ginfo(struct file *file, 1589 1646 struct snd_timer_ginfo __user *_ginfo) 1590 1647 { 1591 - struct snd_timer_ginfo *ginfo; 1648 + struct snd_timer_ginfo *ginfo __free(kfree) = NULL; 1592 1649 struct snd_timer_id tid; 1593 1650 struct snd_timer *t; 1594 1651 struct list_head *p; 1595 - int err = 0; 1596 1652 1597 1653 ginfo = memdup_user(_ginfo, sizeof(*ginfo)); 1598 1654 if (IS_ERR(ginfo)) 1599 - return PTR_ERR(ginfo); 1655 + return PTR_ERR(no_free_ptr(ginfo)); 1600 1656 1601 1657 tid = ginfo->tid; 1602 1658 memset(ginfo, 0, sizeof(*ginfo)); 1603 1659 ginfo->tid = tid; 1604 - mutex_lock(&register_mutex); 1660 + guard(mutex)(&register_mutex); 1605 1661 t = snd_timer_find(&tid); 1606 - if (t != NULL) { 1607 - ginfo->card = t->card ? t->card->number : -1; 1608 - if (t->hw.flags & SNDRV_TIMER_HW_SLAVE) 1609 - ginfo->flags |= SNDRV_TIMER_FLG_SLAVE; 1610 - strscpy(ginfo->id, t->id, sizeof(ginfo->id)); 1611 - strscpy(ginfo->name, t->name, sizeof(ginfo->name)); 1612 - spin_lock_irq(&t->lock); 1662 + if (!t) 1663 + return -ENODEV; 1664 + ginfo->card = t->card ? t->card->number : -1; 1665 + if (t->hw.flags & SNDRV_TIMER_HW_SLAVE) 1666 + ginfo->flags |= SNDRV_TIMER_FLG_SLAVE; 1667 + strscpy(ginfo->id, t->id, sizeof(ginfo->id)); 1668 + strscpy(ginfo->name, t->name, sizeof(ginfo->name)); 1669 + scoped_guard(spinlock_irq, &t->lock) 1613 1670 ginfo->resolution = snd_timer_hw_resolution(t); 1614 - spin_unlock_irq(&t->lock); 1615 - if (t->hw.resolution_min > 0) { 1616 - ginfo->resolution_min = t->hw.resolution_min; 1617 - ginfo->resolution_max = t->hw.resolution_max; 1618 - } 1619 - list_for_each(p, &t->open_list_head) { 1620 - ginfo->clients++; 1621 - } 1622 - } else { 1623 - err = -ENODEV; 1671 + if (t->hw.resolution_min > 0) { 1672 + ginfo->resolution_min = t->hw.resolution_min; 1673 + ginfo->resolution_max = t->hw.resolution_max; 1624 1674 } 1625 - mutex_unlock(&register_mutex); 1626 - if (err >= 0 && copy_to_user(_ginfo, ginfo, sizeof(*ginfo))) 1627 - err = -EFAULT; 1628 - kfree(ginfo); 1629 - return err; 1675 + list_for_each(p, &t->open_list_head) { 1676 + ginfo->clients++; 1677 + } 1678 + if (copy_to_user(_ginfo, ginfo, sizeof(*ginfo))) 1679 + return -EFAULT; 1680 + return 0; 1630 1681 } 1631 1682 1632 1683 static int timer_set_gparams(struct snd_timer_gparams *gparams) 1633 1684 { 1634 1685 struct snd_timer *t; 1635 - int err; 1636 1686 1637 - mutex_lock(&register_mutex); 1687 + guard(mutex)(&register_mutex); 1638 1688 t = snd_timer_find(&gparams->tid); 1639 - if (!t) { 1640 - err = -ENODEV; 1641 - goto _error; 1642 - } 1643 - if (!list_empty(&t->open_list_head)) { 1644 - err = -EBUSY; 1645 - goto _error; 1646 - } 1647 - if (!t->hw.set_period) { 1648 - err = -ENOSYS; 1649 - goto _error; 1650 - } 1651 - err = t->hw.set_period(t, gparams->period_num, gparams->period_den); 1652 - _error: 1653 - mutex_unlock(&register_mutex); 1654 - return err; 1689 + if (!t) 1690 + return -ENODEV; 1691 + if (!list_empty(&t->open_list_head)) 1692 + return -EBUSY; 1693 + if (!t->hw.set_period) 1694 + return -ENOSYS; 1695 + return t->hw.set_period(t, gparams->period_num, gparams->period_den); 1655 1696 } 1656 1697 1657 1698 static int snd_timer_user_gparams(struct file *file, ··· 1661 1734 tid = gstatus.tid; 1662 1735 memset(&gstatus, 0, sizeof(gstatus)); 1663 1736 gstatus.tid = tid; 1664 - mutex_lock(&register_mutex); 1737 + guard(mutex)(&register_mutex); 1665 1738 t = snd_timer_find(&tid); 1666 1739 if (t != NULL) { 1667 - spin_lock_irq(&t->lock); 1740 + guard(spinlock_irq)(&t->lock); 1668 1741 gstatus.resolution = snd_timer_hw_resolution(t); 1669 1742 if (t->hw.precise_resolution) { 1670 1743 t->hw.precise_resolution(t, &gstatus.resolution_num, ··· 1673 1746 gstatus.resolution_num = gstatus.resolution; 1674 1747 gstatus.resolution_den = 1000000000uL; 1675 1748 } 1676 - spin_unlock_irq(&t->lock); 1677 1749 } else { 1678 1750 err = -ENODEV; 1679 1751 } 1680 - mutex_unlock(&register_mutex); 1681 1752 if (err >= 0 && copy_to_user(_gstatus, &gstatus, sizeof(gstatus))) 1682 1753 err = -EFAULT; 1683 1754 return err; ··· 1729 1804 struct snd_timer_info __user *_info) 1730 1805 { 1731 1806 struct snd_timer_user *tu; 1732 - struct snd_timer_info *info; 1807 + struct snd_timer_info *info __free(kfree) = NULL; 1733 1808 struct snd_timer *t; 1734 - int err = 0; 1735 1809 1736 1810 tu = file->private_data; 1737 1811 if (!tu->timeri) ··· 1747 1823 info->flags |= SNDRV_TIMER_FLG_SLAVE; 1748 1824 strscpy(info->id, t->id, sizeof(info->id)); 1749 1825 strscpy(info->name, t->name, sizeof(info->name)); 1750 - spin_lock_irq(&t->lock); 1751 - info->resolution = snd_timer_hw_resolution(t); 1752 - spin_unlock_irq(&t->lock); 1826 + scoped_guard(spinlock_irq, &t->lock) 1827 + info->resolution = snd_timer_hw_resolution(t); 1753 1828 if (copy_to_user(_info, info, sizeof(*_info))) 1754 - err = -EFAULT; 1755 - kfree(info); 1756 - return err; 1829 + return -EFAULT; 1830 + return 0; 1757 1831 } 1758 1832 1759 1833 static int snd_timer_user_params(struct file *file, ··· 1809 1887 goto _end; 1810 1888 } 1811 1889 snd_timer_stop(tu->timeri); 1812 - spin_lock_irq(&t->lock); 1813 - tu->timeri->flags &= ~(SNDRV_TIMER_IFLG_AUTO| 1814 - SNDRV_TIMER_IFLG_EXCLUSIVE| 1815 - SNDRV_TIMER_IFLG_EARLY_EVENT); 1816 - if (params.flags & SNDRV_TIMER_PSFLG_AUTO) 1817 - tu->timeri->flags |= SNDRV_TIMER_IFLG_AUTO; 1818 - if (params.flags & SNDRV_TIMER_PSFLG_EXCLUSIVE) 1819 - tu->timeri->flags |= SNDRV_TIMER_IFLG_EXCLUSIVE; 1820 - if (params.flags & SNDRV_TIMER_PSFLG_EARLY_EVENT) 1821 - tu->timeri->flags |= SNDRV_TIMER_IFLG_EARLY_EVENT; 1822 - spin_unlock_irq(&t->lock); 1890 + scoped_guard(spinlock_irq, &t->lock) { 1891 + tu->timeri->flags &= ~(SNDRV_TIMER_IFLG_AUTO| 1892 + SNDRV_TIMER_IFLG_EXCLUSIVE| 1893 + SNDRV_TIMER_IFLG_EARLY_EVENT); 1894 + if (params.flags & SNDRV_TIMER_PSFLG_AUTO) 1895 + tu->timeri->flags |= SNDRV_TIMER_IFLG_AUTO; 1896 + if (params.flags & SNDRV_TIMER_PSFLG_EXCLUSIVE) 1897 + tu->timeri->flags |= SNDRV_TIMER_IFLG_EXCLUSIVE; 1898 + if (params.flags & SNDRV_TIMER_PSFLG_EARLY_EVENT) 1899 + tu->timeri->flags |= SNDRV_TIMER_IFLG_EARLY_EVENT; 1900 + } 1823 1901 if (params.queue_size > 0 && 1824 1902 (unsigned int)tu->queue_size != params.queue_size) { 1825 1903 err = realloc_user_queue(tu, params.queue_size); 1826 1904 if (err < 0) 1827 1905 goto _end; 1828 1906 } 1829 - spin_lock_irq(&tu->qlock); 1830 - tu->qhead = tu->qtail = tu->qused = 0; 1831 - if (tu->timeri->flags & SNDRV_TIMER_IFLG_EARLY_EVENT) { 1832 - if (tu->tread) { 1833 - struct snd_timer_tread64 tread; 1834 - memset(&tread, 0, sizeof(tread)); 1835 - tread.event = SNDRV_TIMER_EVENT_EARLY; 1836 - tread.tstamp_sec = 0; 1837 - tread.tstamp_nsec = 0; 1838 - tread.val = 0; 1839 - snd_timer_user_append_to_tqueue(tu, &tread); 1840 - } else { 1841 - struct snd_timer_read *r = &tu->queue[0]; 1842 - r->resolution = 0; 1843 - r->ticks = 0; 1844 - tu->qused++; 1845 - tu->qtail++; 1907 + scoped_guard(spinlock_irq, &tu->qlock) { 1908 + tu->qhead = tu->qtail = tu->qused = 0; 1909 + if (tu->timeri->flags & SNDRV_TIMER_IFLG_EARLY_EVENT) { 1910 + if (tu->tread) { 1911 + struct snd_timer_tread64 tread; 1912 + 1913 + memset(&tread, 0, sizeof(tread)); 1914 + tread.event = SNDRV_TIMER_EVENT_EARLY; 1915 + tread.tstamp_sec = 0; 1916 + tread.tstamp_nsec = 0; 1917 + tread.val = 0; 1918 + snd_timer_user_append_to_tqueue(tu, &tread); 1919 + } else { 1920 + struct snd_timer_read *r = &tu->queue[0]; 1921 + 1922 + r->resolution = 0; 1923 + r->ticks = 0; 1924 + tu->qused++; 1925 + tu->qtail++; 1926 + } 1846 1927 } 1928 + tu->filter = params.filter; 1929 + tu->ticks = params.ticks; 1847 1930 } 1848 - tu->filter = params.filter; 1849 - tu->ticks = params.ticks; 1850 - spin_unlock_irq(&tu->qlock); 1851 1931 err = 0; 1852 1932 _end: 1853 1933 if (copy_to_user(_params, &params, sizeof(params))) ··· 1872 1948 status.resolution = snd_timer_resolution(tu->timeri); 1873 1949 status.lost = tu->timeri->lost; 1874 1950 status.overrun = tu->overrun; 1875 - spin_lock_irq(&tu->qlock); 1876 - status.queue = tu->qused; 1877 - spin_unlock_irq(&tu->qlock); 1951 + scoped_guard(spinlock_irq, &tu->qlock) 1952 + status.queue = tu->qused; 1878 1953 if (copy_to_user(_status, &status, sizeof(status))) 1879 1954 return -EFAULT; 1880 1955 return 0; ··· 1894 1971 status.resolution = snd_timer_resolution(tu->timeri); 1895 1972 status.lost = tu->timeri->lost; 1896 1973 status.overrun = tu->overrun; 1897 - spin_lock_irq(&tu->qlock); 1898 - status.queue = tu->qused; 1899 - spin_unlock_irq(&tu->qlock); 1974 + scoped_guard(spinlock_irq, &tu->qlock) 1975 + status.queue = tu->qused; 1900 1976 if (copy_to_user(_status, &status, sizeof(status))) 1901 1977 return -EFAULT; 1902 1978 return 0; ··· 2053 2131 unsigned long arg) 2054 2132 { 2055 2133 struct snd_timer_user *tu = file->private_data; 2056 - long ret; 2057 2134 2058 - mutex_lock(&tu->ioctl_lock); 2059 - ret = __snd_timer_user_ioctl(file, cmd, arg, false); 2060 - mutex_unlock(&tu->ioctl_lock); 2061 - return ret; 2135 + guard(mutex)(&tu->ioctl_lock); 2136 + return __snd_timer_user_ioctl(file, cmd, arg, false); 2062 2137 } 2063 2138 2064 2139 static int snd_timer_user_fasync(int fd, struct file * file, int on) ··· 2182 2263 poll_wait(file, &tu->qchange_sleep, wait); 2183 2264 2184 2265 mask = 0; 2185 - spin_lock_irq(&tu->qlock); 2266 + guard(spinlock_irq)(&tu->qlock); 2186 2267 if (tu->qused) 2187 2268 mask |= EPOLLIN | EPOLLRDNORM; 2188 2269 if (tu->disconnected) 2189 2270 mask |= EPOLLERR; 2190 - spin_unlock_irq(&tu->qlock); 2191 2271 2192 2272 return mask; 2193 2273 }
+2 -5
sound/core/timer_compat.c
··· 115 115 unsigned long arg) 116 116 { 117 117 struct snd_timer_user *tu = file->private_data; 118 - long ret; 119 118 120 - mutex_lock(&tu->ioctl_lock); 121 - ret = __snd_timer_user_ioctl_compat(file, cmd, arg); 122 - mutex_unlock(&tu->ioctl_lock); 123 - return ret; 119 + guard(mutex)(&tu->ioctl_lock); 120 + return __snd_timer_user_ioctl_compat(file, cmd, arg); 124 121 }
+12 -23
sound/core/ump.c
··· 985 985 struct snd_ump_endpoint *ump = substream->rmidi->private_data; 986 986 int dir = substream->stream; 987 987 int group = ump->legacy_mapping[substream->number]; 988 - int err = 0; 988 + int err; 989 989 990 - mutex_lock(&ump->open_mutex); 991 - if (ump->legacy_substreams[dir][group]) { 992 - err = -EBUSY; 993 - goto unlock; 994 - } 990 + guard(mutex)(&ump->open_mutex); 991 + if (ump->legacy_substreams[dir][group]) 992 + return -EBUSY; 995 993 if (dir == SNDRV_RAWMIDI_STREAM_OUTPUT) { 996 994 if (!ump->legacy_out_opens) { 997 995 err = snd_rawmidi_kernel_open(&ump->core, 0, ··· 997 999 SNDRV_RAWMIDI_LFLG_APPEND, 998 1000 &ump->legacy_out_rfile); 999 1001 if (err < 0) 1000 - goto unlock; 1002 + return err; 1001 1003 } 1002 1004 ump->legacy_out_opens++; 1003 1005 snd_ump_convert_reset(&ump->out_cvts[group]); 1004 1006 } 1005 - spin_lock_irq(&ump->legacy_locks[dir]); 1007 + guard(spinlock_irq)(&ump->legacy_locks[dir]); 1006 1008 ump->legacy_substreams[dir][group] = substream; 1007 - spin_unlock_irq(&ump->legacy_locks[dir]); 1008 - unlock: 1009 - mutex_unlock(&ump->open_mutex); 1010 - return err; 1009 + return 0; 1011 1010 } 1012 1011 1013 1012 static int snd_ump_legacy_close(struct snd_rawmidi_substream *substream) ··· 1013 1018 int dir = substream->stream; 1014 1019 int group = ump->legacy_mapping[substream->number]; 1015 1020 1016 - mutex_lock(&ump->open_mutex); 1017 - spin_lock_irq(&ump->legacy_locks[dir]); 1018 - ump->legacy_substreams[dir][group] = NULL; 1019 - spin_unlock_irq(&ump->legacy_locks[dir]); 1021 + guard(mutex)(&ump->open_mutex); 1022 + scoped_guard(spinlock_irq, &ump->legacy_locks[dir]) 1023 + ump->legacy_substreams[dir][group] = NULL; 1020 1024 if (dir == SNDRV_RAWMIDI_STREAM_OUTPUT) { 1021 1025 if (!--ump->legacy_out_opens) 1022 1026 snd_rawmidi_kernel_release(&ump->legacy_out_rfile); 1023 1027 } 1024 - mutex_unlock(&ump->open_mutex); 1025 1028 return 0; 1026 1029 } 1027 1030 ··· 1071 1078 const int dir = SNDRV_RAWMIDI_STREAM_OUTPUT; 1072 1079 unsigned char c; 1073 1080 int group, size = 0; 1074 - unsigned long flags; 1075 1081 1076 1082 if (!ump->out_cvts || !ump->legacy_out_opens) 1077 1083 return 0; 1078 1084 1079 - spin_lock_irqsave(&ump->legacy_locks[dir], flags); 1085 + guard(spinlock_irqsave)(&ump->legacy_locks[dir]); 1080 1086 for (group = 0; group < SNDRV_UMP_MAX_GROUPS; group++) { 1081 1087 substream = ump->legacy_substreams[dir][group]; 1082 1088 if (!substream) ··· 1091 1099 break; 1092 1100 } 1093 1101 } 1094 - spin_unlock_irqrestore(&ump->legacy_locks[dir], flags); 1095 1102 return size; 1096 1103 } 1097 1104 ··· 1100 1109 struct snd_rawmidi_substream *substream; 1101 1110 unsigned char buf[16]; 1102 1111 unsigned char group; 1103 - unsigned long flags; 1104 1112 const int dir = SNDRV_RAWMIDI_STREAM_INPUT; 1105 1113 int size; 1106 1114 1107 1115 size = snd_ump_convert_from_ump(src, buf, &group); 1108 1116 if (size <= 0) 1109 1117 return; 1110 - spin_lock_irqsave(&ump->legacy_locks[dir], flags); 1118 + guard(spinlock_irqsave)(&ump->legacy_locks[dir]); 1111 1119 substream = ump->legacy_substreams[dir][group]; 1112 1120 if (substream) 1113 1121 snd_rawmidi_receive(substream, buf, size); 1114 - spin_unlock_irqrestore(&ump->legacy_locks[dir], flags); 1115 1122 } 1116 1123 1117 1124 /* Fill ump->legacy_mapping[] for groups to be used for legacy rawmidi */
+6 -13
sound/core/vmaster.c
··· 56 56 57 57 static int follower_update(struct link_follower *follower) 58 58 { 59 - struct snd_ctl_elem_value *uctl; 59 + struct snd_ctl_elem_value *uctl __free(kfree) = NULL; 60 60 int err, ch; 61 61 62 62 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL); ··· 65 65 uctl->id = follower->follower.id; 66 66 err = follower->follower.get(&follower->follower, uctl); 67 67 if (err < 0) 68 - goto error; 68 + return err; 69 69 for (ch = 0; ch < follower->info.count; ch++) 70 70 follower->vals[ch] = uctl->value.integer.value[ch]; 71 - error: 72 - kfree(uctl); 73 - return err < 0 ? err : 0; 71 + return 0; 74 72 } 75 73 76 74 /* get the follower ctl info and save the initial values */ 77 75 static int follower_init(struct link_follower *follower) 78 76 { 79 - struct snd_ctl_elem_info *uinfo; 77 + struct snd_ctl_elem_info *uinfo __free(kfree) = NULL; 80 78 int err; 81 79 82 80 if (follower->info.count) { ··· 89 91 return -ENOMEM; 90 92 uinfo->id = follower->follower.id; 91 93 err = follower->follower.info(&follower->follower, uinfo); 92 - if (err < 0) { 93 - kfree(uinfo); 94 + if (err < 0) 94 95 return err; 95 - } 96 96 follower->info.type = uinfo->type; 97 97 follower->info.count = uinfo->count; 98 98 if (follower->info.count > 2 || 99 99 (follower->info.type != SNDRV_CTL_ELEM_TYPE_INTEGER && 100 100 follower->info.type != SNDRV_CTL_ELEM_TYPE_BOOLEAN)) { 101 101 pr_err("ALSA: vmaster: invalid follower element\n"); 102 - kfree(uinfo); 103 102 return -EINVAL; 104 103 } 105 104 follower->info.min_val = uinfo->value.integer.min; 106 105 follower->info.max_val = uinfo->value.integer.max; 107 - kfree(uinfo); 108 106 109 107 return follower_update(follower); 110 108 } ··· 335 341 static int sync_followers(struct link_master *master, int old_val, int new_val) 336 342 { 337 343 struct link_follower *follower; 338 - struct snd_ctl_elem_value *uval; 344 + struct snd_ctl_elem_value *uval __free(kfree) = NULL; 339 345 340 346 uval = kmalloc(sizeof(*uval), GFP_KERNEL); 341 347 if (!uval) ··· 347 353 master->val = new_val; 348 354 follower_put_val(follower, uval); 349 355 } 350 - kfree(uval); 351 356 return 0; 352 357 } 353 358
+2 -7
sound/drivers/aloop.c
··· 1830 1830 return 0; 1831 1831 } 1832 1832 1833 - #ifdef CONFIG_PM_SLEEP 1834 1833 static int loopback_suspend(struct device *pdev) 1835 1834 { 1836 1835 struct snd_card *card = dev_get_drvdata(pdev); ··· 1846 1847 return 0; 1847 1848 } 1848 1849 1849 - static SIMPLE_DEV_PM_OPS(loopback_pm, loopback_suspend, loopback_resume); 1850 - #define LOOPBACK_PM_OPS &loopback_pm 1851 - #else 1852 - #define LOOPBACK_PM_OPS NULL 1853 - #endif 1850 + static DEFINE_SIMPLE_DEV_PM_OPS(loopback_pm, loopback_suspend, loopback_resume); 1854 1851 1855 1852 #define SND_LOOPBACK_DRIVER "snd_aloop" 1856 1853 ··· 1854 1859 .probe = loopback_probe, 1855 1860 .driver = { 1856 1861 .name = SND_LOOPBACK_DRIVER, 1857 - .pm = LOOPBACK_PM_OPS, 1862 + .pm = &loopback_pm, 1858 1863 }, 1859 1864 }; 1860 1865
+2 -7
sound/drivers/dummy.c
··· 1098 1098 return 0; 1099 1099 } 1100 1100 1101 - #ifdef CONFIG_PM_SLEEP 1102 1101 static int snd_dummy_suspend(struct device *pdev) 1103 1102 { 1104 1103 struct snd_card *card = dev_get_drvdata(pdev); ··· 1114 1115 return 0; 1115 1116 } 1116 1117 1117 - static SIMPLE_DEV_PM_OPS(snd_dummy_pm, snd_dummy_suspend, snd_dummy_resume); 1118 - #define SND_DUMMY_PM_OPS &snd_dummy_pm 1119 - #else 1120 - #define SND_DUMMY_PM_OPS NULL 1121 - #endif 1118 + static DEFINE_SIMPLE_DEV_PM_OPS(snd_dummy_pm, snd_dummy_suspend, snd_dummy_resume); 1122 1119 1123 1120 #define SND_DUMMY_DRIVER "snd_dummy" 1124 1121 ··· 1122 1127 .probe = snd_dummy_probe, 1123 1128 .driver = { 1124 1129 .name = SND_DUMMY_DRIVER, 1125 - .pm = SND_DUMMY_PM_OPS, 1130 + .pm = &snd_dummy_pm, 1126 1131 }, 1127 1132 }; 1128 1133
+2 -7
sound/drivers/pcsp/pcsp.c
··· 176 176 pcspkr_stop_sound(); 177 177 } 178 178 179 - #ifdef CONFIG_PM_SLEEP 180 179 static int pcsp_suspend(struct device *dev) 181 180 { 182 181 struct snd_pcsp *chip = dev_get_drvdata(dev); ··· 183 184 return 0; 184 185 } 185 186 186 - static SIMPLE_DEV_PM_OPS(pcsp_pm, pcsp_suspend, NULL); 187 - #define PCSP_PM_OPS &pcsp_pm 188 - #else 189 - #define PCSP_PM_OPS NULL 190 - #endif /* CONFIG_PM_SLEEP */ 187 + static DEFINE_SIMPLE_DEV_PM_OPS(pcsp_pm, pcsp_suspend, NULL); 191 188 192 189 static void pcsp_shutdown(struct platform_device *dev) 193 190 { ··· 194 199 static struct platform_driver pcsp_platform_driver = { 195 200 .driver = { 196 201 .name = "pcspkr", 197 - .pm = PCSP_PM_OPS, 202 + .pm = &pcsp_pm, 198 203 }, 199 204 .probe = pcsp_probe, 200 205 .shutdown = pcsp_shutdown,
+2
sound/firewire/Kconfig
··· 175 175 * 8pre 176 176 * 828mk3 (FireWire only) 177 177 * 828mk3 (Hybrid) 178 + * 896mk3 (FireWire only) 179 + * 896mk3 (Hybrid) 178 180 * Ultralite mk3 (FireWire only) 179 181 * Ultralite mk3 (Hybrid) 180 182 * Traveler mk3
+8 -4
sound/firewire/amdtp-stream.c
··· 773 773 } else { 774 774 unsigned int dbc_interval; 775 775 776 - if (*data_blocks > 0 && s->ctx_data.tx.dbc_interval > 0) 777 - dbc_interval = s->ctx_data.tx.dbc_interval; 778 - else 779 - dbc_interval = *data_blocks; 776 + if (!(s->flags & CIP_DBC_IS_PAYLOAD_QUADLETS)) { 777 + if (*data_blocks > 0 && s->ctx_data.tx.dbc_interval > 0) 778 + dbc_interval = s->ctx_data.tx.dbc_interval; 779 + else 780 + dbc_interval = *data_blocks; 781 + } else { 782 + dbc_interval = payload_length / sizeof(__be32); 783 + } 780 784 781 785 lost = dbc != ((*data_block_counter + dbc_interval) & 0xff); 782 786 }
+4
sound/firewire/amdtp-stream.h
··· 37 37 * the value of current SYT_INTERVAL; e.g. initial value is not zero. 38 38 * @CIP_UNAWARE_SYT: For outgoing packet, the value in SYT field of CIP is 0xffff. 39 39 * For incoming packet, the value in SYT field of CIP is not handled. 40 + * @CIP_DBC_IS_PAYLOAD_QUADLETS: Available for incoming packet, and only effective with 41 + * CIP_DBC_IS_END_EVENT flag. The value of dbc field is the number of accumulated quadlets 42 + * in CIP payload, instead of the number of accumulated data blocks. 40 43 */ 41 44 enum cip_flags { 42 45 CIP_NONBLOCKING = 0x00, ··· 54 51 CIP_NO_HEADER = 0x100, 55 52 CIP_UNALIGHED_DBC = 0x200, 56 53 CIP_UNAWARE_SYT = 0x400, 54 + CIP_DBC_IS_PAYLOAD_QUADLETS = 0x800, 57 55 }; 58 56 59 57 /**
+9
sound/firewire/motu/motu-protocol-v3.c
··· 261 261 262 262 if (motu->spec == &snd_motu_spec_828mk3_fw || 263 263 motu->spec == &snd_motu_spec_828mk3_hybrid || 264 + motu->spec == &snd_motu_spec_896mk3 || 264 265 motu->spec == &snd_motu_spec_traveler_mk3 || 265 266 motu->spec == &snd_motu_spec_track16) 266 267 return detect_packet_formats_with_opt_ifaces(motu, data); ··· 287 286 SND_MOTU_SPEC_COMMAND_DSP, 288 287 .tx_fixed_pcm_chunks = {18, 18, 14}, 289 288 .rx_fixed_pcm_chunks = {14, 14, 14}, // Additional 4 dummy chunks at higher rate. 289 + }; 290 + 291 + const struct snd_motu_spec snd_motu_spec_896mk3 = { 292 + .name = "896mk3", 293 + .protocol_version = SND_MOTU_PROTOCOL_V3, 294 + .flags = SND_MOTU_SPEC_COMMAND_DSP, 295 + .tx_fixed_pcm_chunks = {18, 14, 10}, 296 + .rx_fixed_pcm_chunks = {18, 14, 10}, 290 297 }; 291 298 292 299 const struct snd_motu_spec snd_motu_spec_traveler_mk3 = {
+2
sound/firewire/motu/motu.c
··· 168 168 SND_MOTU_DEV_ENTRY(0x00000d, &snd_motu_spec_ultralite), 169 169 SND_MOTU_DEV_ENTRY(0x00000f, &snd_motu_spec_8pre), 170 170 SND_MOTU_DEV_ENTRY(0x000015, &snd_motu_spec_828mk3_fw), // FireWire only. 171 + SND_MOTU_DEV_ENTRY(0x000017, &snd_motu_spec_896mk3), // FireWire only. 171 172 SND_MOTU_DEV_ENTRY(0x000019, &snd_motu_spec_ultralite_mk3), // FireWire only. 172 173 SND_MOTU_DEV_ENTRY(0x00001b, &snd_motu_spec_traveler_mk3), 173 174 SND_MOTU_DEV_ENTRY(0x000030, &snd_motu_spec_ultralite_mk3), // Hybrid. 174 175 SND_MOTU_DEV_ENTRY(0x000035, &snd_motu_spec_828mk3_hybrid), // Hybrid. 176 + SND_MOTU_DEV_ENTRY(0x000037, &snd_motu_spec_896mk3), // Hybrid. 175 177 SND_MOTU_DEV_ENTRY(0x000033, &snd_motu_spec_audio_express), 176 178 SND_MOTU_DEV_ENTRY(0x000039, &snd_motu_spec_track16), 177 179 SND_MOTU_DEV_ENTRY(0x000045, &snd_motu_spec_4pre),
+1
sound/firewire/motu/motu.h
··· 138 138 139 139 extern const struct snd_motu_spec snd_motu_spec_828mk3_fw; 140 140 extern const struct snd_motu_spec snd_motu_spec_828mk3_hybrid; 141 + extern const struct snd_motu_spec snd_motu_spec_896mk3; 141 142 extern const struct snd_motu_spec snd_motu_spec_traveler_mk3; 142 143 extern const struct snd_motu_spec snd_motu_spec_ultralite_mk3; 143 144 extern const struct snd_motu_spec snd_motu_spec_audio_express;
+76 -24
sound/firewire/oxfw/oxfw-stream.c
··· 177 177 flags |= CIP_JUMBO_PAYLOAD; 178 178 if (oxfw->quirks & SND_OXFW_QUIRK_WRONG_DBS) 179 179 flags |= CIP_WRONG_DBS; 180 + if (oxfw->quirks & SND_OXFW_QUIRK_DBC_IS_TOTAL_PAYLOAD_QUADLETS) 181 + flags |= CIP_DBC_IS_END_EVENT | CIP_DBC_IS_PAYLOAD_QUADLETS; 180 182 } else { 181 183 conn = &oxfw->in_conn; 182 184 c_dir = CMP_INPUT; ··· 488 486 enum avc_general_plug_dir dir, 489 487 struct snd_oxfw_stream_formation *formation) 490 488 { 491 - u8 *format; 492 - unsigned int len; 493 489 int err; 494 490 495 - len = AVC_GENERIC_FRAME_MAXIMUM_BYTES; 496 - format = kmalloc(len, GFP_KERNEL); 497 - if (format == NULL) 498 - return -ENOMEM; 491 + if (!(oxfw->quirks & SND_OXFW_QUIRK_STREAM_FORMAT_INFO_UNSUPPORTED)) { 492 + u8 *format; 493 + unsigned int len; 499 494 500 - err = avc_stream_get_format_single(oxfw->unit, dir, 0, format, &len); 501 - if (err < 0) 502 - goto end; 503 - if (len < 3) { 504 - err = -EIO; 505 - goto end; 495 + len = AVC_GENERIC_FRAME_MAXIMUM_BYTES; 496 + format = kmalloc(len, GFP_KERNEL); 497 + if (format == NULL) 498 + return -ENOMEM; 499 + 500 + err = avc_stream_get_format_single(oxfw->unit, dir, 0, format, &len); 501 + if (err >= 0) { 502 + if (len < 3) 503 + err = -EIO; 504 + else 505 + err = snd_oxfw_stream_parse_format(format, formation); 506 + } 507 + 508 + kfree(format); 509 + } else { 510 + // Miglia Harmony Audio does not support Extended Stream Format Information 511 + // command. Use the duplicated hard-coded format, instead. 512 + unsigned int rate; 513 + u8 *const *formats; 514 + int i; 515 + 516 + err = avc_general_get_sig_fmt(oxfw->unit, &rate, dir, 0); 517 + if (err < 0) 518 + return err; 519 + 520 + if (dir == AVC_GENERAL_PLUG_DIR_IN) 521 + formats = oxfw->rx_stream_formats; 522 + else 523 + formats = oxfw->tx_stream_formats; 524 + 525 + for (i = 0; (i < SND_OXFW_STREAM_FORMAT_ENTRIES); ++i) { 526 + if (!formats[i]) 527 + continue; 528 + 529 + err = snd_oxfw_stream_parse_format(formats[i], formation); 530 + if (err < 0) 531 + continue; 532 + 533 + if (formation->rate == rate) 534 + break; 535 + } 536 + if (i == SND_OXFW_STREAM_FORMAT_ENTRIES) 537 + return -EIO; 506 538 } 507 539 508 - err = snd_oxfw_stream_parse_format(format, formation); 509 - end: 510 - kfree(format); 511 540 return err; 512 541 } 513 542 ··· 548 515 * in AV/C Stream Format Information Specification 1.1 (Apr 2005, 1394TA) 549 516 * Also 'Clause 12 AM824 sequence adaption layers' in IEC 61883-6:2005 550 517 */ 551 - int snd_oxfw_stream_parse_format(u8 *format, 518 + int snd_oxfw_stream_parse_format(const u8 *format, 552 519 struct snd_oxfw_stream_formation *formation) 553 520 { 554 521 unsigned int i, e, channels, type; ··· 633 600 unsigned int i, eid; 634 601 int err; 635 602 636 - /* get format at current sampling rate */ 637 - err = avc_stream_get_format_single(oxfw->unit, dir, pid, buf, len); 638 - if (err < 0) { 639 - dev_err(&oxfw->unit->device, 640 - "fail to get current stream format for isoc %s plug %d:%d\n", 641 - (dir == AVC_GENERAL_PLUG_DIR_IN) ? "in" : "out", 642 - pid, err); 643 - goto end; 603 + // get format at current sampling rate. 604 + if (!(oxfw->quirks & SND_OXFW_QUIRK_STREAM_FORMAT_INFO_UNSUPPORTED)) { 605 + err = avc_stream_get_format_single(oxfw->unit, dir, pid, buf, len); 606 + if (err < 0) { 607 + dev_err(&oxfw->unit->device, 608 + "fail to get current stream format for isoc %s plug %d:%d\n", 609 + (dir == AVC_GENERAL_PLUG_DIR_IN) ? "in" : "out", 610 + pid, err); 611 + goto end; 612 + } 613 + } else { 614 + // Miglia Harmony Audio does not support Extended Stream Format Information 615 + // command. Use the hard-coded format, instead. 616 + buf[0] = 0x90; 617 + buf[1] = 0x40; 618 + buf[2] = avc_stream_rate_table[0]; 619 + buf[3] = 0x00; 620 + buf[4] = 0x01; 621 + 622 + if (dir == AVC_GENERAL_PLUG_DIR_IN) 623 + buf[5] = 0x08; 624 + else 625 + buf[5] = 0x02; 626 + 627 + buf[6] = 0x06; 628 + 629 + *len = 7; 644 630 } 645 631 646 632 /* parse and set stream format */
+9 -1
sound/firewire/oxfw/oxfw.c
··· 21 21 #define VENDOR_TASCAM 0x00022e 22 22 #define OUI_STANTON 0x001260 23 23 #define OUI_APOGEE 0x0003db 24 + #define OUI_OXFORD 0x0030e0 24 25 25 26 #define MODEL_SATELLITE 0x00200f 26 27 #define MODEL_SCS1M 0x001000 ··· 233 232 if (err < 0) 234 233 goto error; 235 234 235 + if (entry->vendor_id == OUI_OXFORD && entry->model_id == 0x00f970) { 236 + oxfw->quirks |= SND_OXFW_QUIRK_STREAM_FORMAT_INFO_UNSUPPORTED | 237 + SND_OXFW_QUIRK_DBC_IS_TOTAL_PAYLOAD_QUADLETS; 238 + } 239 + 236 240 err = snd_oxfw_stream_discover(oxfw); 237 241 if (err < 0) 238 242 goto error; ··· 336 330 // 337 331 OXFW_DEV_ENTRY(VENDOR_GRIFFIN, 0x00f970, &griffin_firewave), 338 332 OXFW_DEV_ENTRY(VENDOR_LACIE, 0x00f970, &lacie_speakers), 333 + // Miglia HarmonyAudio (HA02). The numeric vendor ID is ASIC vendor and the model ID is the 334 + // default value of ASIC. 335 + OXFW_DEV_ENTRY(OUI_OXFORD, 0x00f970, NULL), 339 336 // Behringer,F-Control Audio 202. The value of SYT field is not reliable at all. 340 337 OXFW_DEV_ENTRY(VENDOR_BEHRINGER, 0x00fc22, NULL), 341 338 // Loud Technologies, Tapco Link.FireWire 4x6. The value of SYT field is always 0xffff. ··· 346 337 // Loud Technologies, Mackie Onyx Satellite. Although revised version of firmware is 347 338 // installed to avoid the postpone, the value of SYT field is always 0xffff. 348 339 OXFW_DEV_ENTRY(VENDOR_LOUD, MODEL_SATELLITE, NULL), 349 - // Miglia HarmonyAudio. Not yet identified. 350 340 351 341 // 352 342 // OXFW971 devices:
+6 -1
sound/firewire/oxfw/oxfw.h
··· 52 52 // performs media clock recovery voluntarily. In the recovery, the packets with NO_INFO 53 53 // are ignored, thus driver should transfer packets with timestamp. 54 54 SND_OXFW_QUIRK_VOLUNTARY_RECOVERY = 0x20, 55 + // Miglia Harmony Audio does not support AV/C Stream Format Information command. 56 + SND_OXFW_QUIRK_STREAM_FORMAT_INFO_UNSUPPORTED = 0x40, 57 + // Miglia Harmony Audio transmits CIP in which the value of dbc field expresses the number 58 + // of accumulated payload quadlets including the packet. 59 + SND_OXFW_QUIRK_DBC_IS_TOTAL_PAYLOAD_QUADLETS = 0x80, 55 60 }; 56 61 57 62 /* This is an arbitrary number for convinience. */ ··· 141 136 unsigned int pcm; 142 137 unsigned int midi; 143 138 }; 144 - int snd_oxfw_stream_parse_format(u8 *format, 139 + int snd_oxfw_stream_parse_format(const u8 *format, 145 140 struct snd_oxfw_stream_formation *formation); 146 141 int snd_oxfw_stream_get_current_formation(struct snd_oxfw *oxfw, 147 142 enum avc_general_plug_dir dir,
+29 -3
sound/hda/hdac_i915.c
··· 127 127 /* check whether Intel graphics is present and reachable */ 128 128 static int i915_gfx_present(struct pci_dev *hdac_pci) 129 129 { 130 + /* List of known platforms with no i915 support. */ 131 + static const struct pci_device_id denylist[] = { 132 + /* CNL */ 133 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x5a40), 0x030000, 0xff0000 }, 134 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x5a41), 0x030000, 0xff0000 }, 135 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x5a42), 0x030000, 0xff0000 }, 136 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x5a44), 0x030000, 0xff0000 }, 137 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x5a49), 0x030000, 0xff0000 }, 138 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x5a4a), 0x030000, 0xff0000 }, 139 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x5a4c), 0x030000, 0xff0000 }, 140 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x5a50), 0x030000, 0xff0000 }, 141 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x5a51), 0x030000, 0xff0000 }, 142 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x5a52), 0x030000, 0xff0000 }, 143 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x5a54), 0x030000, 0xff0000 }, 144 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x5a59), 0x030000, 0xff0000 }, 145 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x5a5a), 0x030000, 0xff0000 }, 146 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x5a5c), 0x030000, 0xff0000 }, 147 + /* LKF */ 148 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x9840), 0x030000, 0xff0000 }, 149 + {} 150 + }; 130 151 struct pci_dev *display_dev = NULL; 131 152 132 153 if (!gpu_bind || (gpu_bind < 0 && video_firmware_drivers_only())) 133 154 return false; 134 155 135 156 for_each_pci_dev(display_dev) { 136 - if (display_dev->vendor == PCI_VENDOR_ID_INTEL && 137 - (display_dev->class >> 16) == PCI_BASE_CLASS_DISPLAY && 138 - connectivity_check(display_dev, hdac_pci)) { 157 + if (display_dev->vendor != PCI_VENDOR_ID_INTEL || 158 + (display_dev->class >> 16) != PCI_BASE_CLASS_DISPLAY) 159 + continue; 160 + 161 + if (pci_match_id(denylist, display_dev)) 162 + continue; 163 + 164 + if (connectivity_check(display_dev, hdac_pci)) { 139 165 pci_dev_put(display_dev); 140 166 return true; 141 167 }
+1 -1
sound/hda/hdac_stream.c
··· 567 567 return 0; 568 568 569 569 error: 570 - dev_err(bus->dev, "Too many BDL entries: buffer=%d, period=%d\n", 570 + dev_dbg(bus->dev, "Too many BDL entries: buffer=%d, period=%d\n", 571 571 azx_dev->bufsize, period_bytes); 572 572 return -EINVAL; 573 573 }
+7
sound/hda/intel-sdw-acpi.c
··· 23 23 module_param_named(sdw_link_mask, ctrl_link_mask, int, 0444); 24 24 MODULE_PARM_DESC(sdw_link_mask, "Intel link mask (one bit per link)"); 25 25 26 + static ulong ctrl_addr = 0x40000000; 27 + module_param_named(sdw_ctrl_addr, ctrl_addr, ulong, 0444); 28 + MODULE_PARM_DESC(sdw_ctrl_addr, "Intel SoundWire Controller _ADR"); 29 + 26 30 static bool is_link_enabled(struct fwnode_handle *fw_node, u8 idx) 27 31 { 28 32 struct fwnode_handle *link; ··· 143 139 * SoundWire link so filter accordingly 144 140 */ 145 141 if (FIELD_GET(GENMASK(31, 28), adr) != SDW_LINK_TYPE) 142 + return AE_OK; /* keep going */ 143 + 144 + if (adr != ctrl_addr) 146 145 return AE_OK; /* keep going */ 147 146 148 147 /* found the correct SoundWire controller */
+2 -5
sound/pci/ac97/ac97_patch.c
··· 41 41 static void reset_tlv(struct snd_ac97 *ac97, const char *name, 42 42 const unsigned int *tlv) 43 43 { 44 - struct snd_ctl_elem_id sid; 45 44 struct snd_kcontrol *kctl; 46 - memset(&sid, 0, sizeof(sid)); 47 - strcpy(sid.name, name); 48 - sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 49 - kctl = snd_ctl_find_id(ac97->bus->card, &sid); 45 + 46 + kctl = snd_ctl_find_id_mixer(ac97->bus->card, name); 50 47 if (kctl && kctl->tlv.p) 51 48 kctl->tlv.p = tlv; 52 49 }
+5 -27
sound/pci/ali5451/ali5451.c
··· 243 243 spinlock_t reg_lock; 244 244 spinlock_t voice_alloc; 245 245 246 - #ifdef CONFIG_PM_SLEEP 247 - struct snd_ali_image *image; 248 - #endif 246 + struct snd_ali_image image; 249 247 }; 250 248 251 249 static const struct pci_device_id snd_ali_ids[] = { ··· 1822 1824 return 0; 1823 1825 } 1824 1826 1825 - #ifdef CONFIG_PM_SLEEP 1826 1827 static int ali_suspend(struct device *dev) 1827 1828 { 1828 1829 struct snd_card *card = dev_get_drvdata(dev); 1829 1830 struct snd_ali *chip = card->private_data; 1830 - struct snd_ali_image *im; 1831 + struct snd_ali_image *im = &chip->image; 1831 1832 int i, j; 1832 - 1833 - im = chip->image; 1834 - if (!im) 1835 - return 0; 1836 1833 1837 1834 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); 1838 1835 for (i = 0; i < chip->num_of_codecs; i++) ··· 1865 1872 { 1866 1873 struct snd_card *card = dev_get_drvdata(dev); 1867 1874 struct snd_ali *chip = card->private_data; 1868 - struct snd_ali_image *im; 1875 + struct snd_ali_image *im = &chip->image; 1869 1876 int i, j; 1870 - 1871 - im = chip->image; 1872 - if (!im) 1873 - return 0; 1874 1877 1875 1878 spin_lock_irq(&chip->reg_lock); 1876 1879 ··· 1897 1908 return 0; 1898 1909 } 1899 1910 1900 - static SIMPLE_DEV_PM_OPS(ali_pm, ali_suspend, ali_resume); 1901 - #define ALI_PM_OPS &ali_pm 1902 - #else 1903 - #define ALI_PM_OPS NULL 1904 - #endif /* CONFIG_PM_SLEEP */ 1911 + static DEFINE_SIMPLE_DEV_PM_OPS(ali_pm, ali_suspend, ali_resume); 1905 1912 1906 1913 static void snd_ali_free(struct snd_card *card) 1907 1914 { ··· 2097 2112 return err; 2098 2113 } 2099 2114 2100 - #ifdef CONFIG_PM_SLEEP 2101 - codec->image = devm_kmalloc(&pci->dev, sizeof(*codec->image), 2102 - GFP_KERNEL); 2103 - if (!codec->image) 2104 - dev_warn(card->dev, "can't allocate apm buffer\n"); 2105 - #endif 2106 - 2107 2115 snd_ali_enable_address_interrupt(codec); 2108 2116 codec->hw_initialized = 1; 2109 2117 return 0; ··· 2159 2181 .id_table = snd_ali_ids, 2160 2182 .probe = snd_ali_probe, 2161 2183 .driver = { 2162 - .pm = ALI_PM_OPS, 2184 + .pm = &ali_pm, 2163 2185 }, 2164 2186 }; 2165 2187
+2 -7
sound/pci/als300.c
··· 654 654 return 0; 655 655 } 656 656 657 - #ifdef CONFIG_PM_SLEEP 658 657 static int snd_als300_suspend(struct device *dev) 659 658 { 660 659 struct snd_card *card = dev_get_drvdata(dev); ··· 676 677 return 0; 677 678 } 678 679 679 - static SIMPLE_DEV_PM_OPS(snd_als300_pm, snd_als300_suspend, snd_als300_resume); 680 - #define SND_ALS300_PM_OPS &snd_als300_pm 681 - #else 682 - #define SND_ALS300_PM_OPS NULL 683 - #endif 680 + static DEFINE_SIMPLE_DEV_PM_OPS(snd_als300_pm, snd_als300_suspend, snd_als300_resume); 684 681 685 682 static int snd_als300_probe(struct pci_dev *pci, 686 683 const struct pci_device_id *pci_id) ··· 734 739 .id_table = snd_als300_ids, 735 740 .probe = snd_als300_probe, 736 741 .driver = { 737 - .pm = SND_ALS300_PM_OPS, 742 + .pm = &snd_als300_pm, 738 743 }, 739 744 }; 740 745
+2 -7
sound/pci/als4000.c
··· 936 936 return snd_card_free_on_error(&pci->dev, __snd_card_als4000_probe(pci, pci_id)); 937 937 } 938 938 939 - #ifdef CONFIG_PM_SLEEP 940 939 static int snd_als4000_suspend(struct device *dev) 941 940 { 942 941 struct snd_card *card = dev_get_drvdata(dev); ··· 967 968 return 0; 968 969 } 969 970 970 - static SIMPLE_DEV_PM_OPS(snd_als4000_pm, snd_als4000_suspend, snd_als4000_resume); 971 - #define SND_ALS4000_PM_OPS &snd_als4000_pm 972 - #else 973 - #define SND_ALS4000_PM_OPS NULL 974 - #endif /* CONFIG_PM_SLEEP */ 971 + static DEFINE_SIMPLE_DEV_PM_OPS(snd_als4000_pm, snd_als4000_suspend, snd_als4000_resume); 975 972 976 973 static struct pci_driver als4000_driver = { 977 974 .name = KBUILD_MODNAME, 978 975 .id_table = snd_als4000_ids, 979 976 .probe = snd_card_als4000_probe, 980 977 .driver = { 981 - .pm = SND_ALS4000_PM_OPS, 978 + .pm = &snd_als4000_pm, 982 979 }, 983 980 }; 984 981
+2 -10
sound/pci/atiixp.c
··· 520 520 return 0; 521 521 } 522 522 523 - #ifdef CONFIG_PM_SLEEP 524 523 static int snd_atiixp_aclink_down(struct atiixp *chip) 525 524 { 526 525 // if (atiixp_read(chip, MODEM_MIRROR) & 0x1) /* modem running, too? */ ··· 529 530 ATI_REG_CMD_POWERDOWN); 530 531 return 0; 531 532 } 532 - #endif 533 533 534 534 /* 535 535 * auto-detection of codecs ··· 1452 1454 } 1453 1455 1454 1456 1455 - #ifdef CONFIG_PM_SLEEP 1456 1457 /* 1457 1458 * power management 1458 1459 */ ··· 1496 1499 return 0; 1497 1500 } 1498 1501 1499 - static SIMPLE_DEV_PM_OPS(snd_atiixp_pm, snd_atiixp_suspend, snd_atiixp_resume); 1500 - #define SND_ATIIXP_PM_OPS &snd_atiixp_pm 1501 - #else 1502 - #define SND_ATIIXP_PM_OPS NULL 1503 - #endif /* CONFIG_PM_SLEEP */ 1504 - 1502 + static DEFINE_SIMPLE_DEV_PM_OPS(snd_atiixp_pm, snd_atiixp_suspend, snd_atiixp_resume); 1505 1503 1506 1504 /* 1507 1505 * proc interface for register dump ··· 1626 1634 .id_table = snd_atiixp_ids, 1627 1635 .probe = snd_atiixp_probe, 1628 1636 .driver = { 1629 - .pm = SND_ATIIXP_PM_OPS, 1637 + .pm = &snd_atiixp_pm, 1630 1638 }, 1631 1639 }; 1632 1640
+2 -9
sound/pci/atiixp_modem.c
··· 496 496 return 0; 497 497 } 498 498 499 - #ifdef CONFIG_PM_SLEEP 500 499 static int snd_atiixp_aclink_down(struct atiixp_modem *chip) 501 500 { 502 501 // if (atiixp_read(chip, MODEM_MIRROR) & 0x1) /* modem running, too? */ ··· 505 506 ATI_REG_CMD_POWERDOWN); 506 507 return 0; 507 508 } 508 - #endif 509 509 510 510 /* 511 511 * auto-detection of codecs ··· 1092 1094 } 1093 1095 1094 1096 1095 - #ifdef CONFIG_PM_SLEEP 1096 1097 /* 1097 1098 * power management 1098 1099 */ ··· 1125 1128 return 0; 1126 1129 } 1127 1130 1128 - static SIMPLE_DEV_PM_OPS(snd_atiixp_pm, snd_atiixp_suspend, snd_atiixp_resume); 1129 - #define SND_ATIIXP_PM_OPS &snd_atiixp_pm 1130 - #else 1131 - #define SND_ATIIXP_PM_OPS NULL 1132 - #endif /* CONFIG_PM_SLEEP */ 1131 + static DEFINE_SIMPLE_DEV_PM_OPS(snd_atiixp_pm, snd_atiixp_suspend, snd_atiixp_resume); 1133 1132 1134 1133 /* 1135 1134 * proc interface for register dump ··· 1251 1258 .id_table = snd_atiixp_ids, 1252 1259 .probe = snd_atiixp_probe, 1253 1260 .driver = { 1254 - .pm = SND_ATIIXP_PM_OPS, 1261 + .pm = &snd_atiixp_pm, 1255 1262 }, 1256 1263 }; 1257 1264
+3 -2
sound/pci/aw2/aw2-saa7146.h
··· 19 19 20 20 #define NUM_STREAM_CAPTURE_ANA 0 21 21 22 - typedef void (*snd_aw2_saa7146_it_cb) (void *); 22 + struct snd_pcm_substream; 23 + typedef void (*snd_aw2_saa7146_it_cb) (struct snd_pcm_substream *); 23 24 24 25 struct snd_aw2_saa7146_cb_param { 25 26 snd_aw2_saa7146_it_cb p_it_callback; 26 - void *p_callback_param; 27 + struct snd_pcm_substream *p_callback_param; 27 28 }; 28 29 29 30 /* definition of the chip-specific record */
+2 -9
sound/pci/azt3328.c
··· 295 295 * CONFIG_PM register storage below, but that's slightly difficult. */ 296 296 u16 shadow_reg_ctrl_6AH; 297 297 298 - #ifdef CONFIG_PM_SLEEP 299 298 /* register value containers for power management 300 299 * Note: not always full I/O range preserved (similar to Win driver!) */ 301 300 u32 saved_regs_ctrl[AZF_ALIGN(AZF_IO_SIZE_CTRL_PM) / 4]; ··· 302 303 u32 saved_regs_mpu[AZF_ALIGN(AZF_IO_SIZE_MPU_PM) / 4]; 303 304 u32 saved_regs_opl3[AZF_ALIGN(AZF_IO_SIZE_OPL3_PM) / 4]; 304 305 u32 saved_regs_mixer[AZF_ALIGN(AZF_IO_SIZE_MIXER_PM) / 4]; 305 - #endif 306 306 }; 307 307 308 308 static const struct pci_device_id snd_azf3328_ids[] = { ··· 2515 2517 return snd_card_free_on_error(&pci->dev, __snd_azf3328_probe(pci, pci_id)); 2516 2518 } 2517 2519 2518 - #ifdef CONFIG_PM_SLEEP 2519 2520 static inline void 2520 2521 snd_azf3328_suspend_regs(const struct snd_azf3328 *chip, 2521 2522 unsigned long io_addr, unsigned count, u32 *saved_regs) ··· 2630 2633 return 0; 2631 2634 } 2632 2635 2633 - static SIMPLE_DEV_PM_OPS(snd_azf3328_pm, snd_azf3328_suspend, snd_azf3328_resume); 2634 - #define SND_AZF3328_PM_OPS &snd_azf3328_pm 2635 - #else 2636 - #define SND_AZF3328_PM_OPS NULL 2637 - #endif /* CONFIG_PM_SLEEP */ 2636 + static DEFINE_SIMPLE_DEV_PM_OPS(snd_azf3328_pm, snd_azf3328_suspend, snd_azf3328_resume); 2638 2637 2639 2638 static struct pci_driver azf3328_driver = { 2640 2639 .name = KBUILD_MODNAME, 2641 2640 .id_table = snd_azf3328_ids, 2642 2641 .probe = snd_azf3328_probe, 2643 2642 .driver = { 2644 - .pm = SND_AZF3328_PM_OPS, 2643 + .pm = &snd_azf3328_pm, 2645 2644 }, 2646 2645 }; 2647 2646
+2 -9
sound/pci/cmipci.c
··· 486 486 487 487 spinlock_t reg_lock; 488 488 489 - #ifdef CONFIG_PM_SLEEP 490 489 unsigned int saved_regs[0x20]; 491 490 unsigned char saved_mixers[0x20]; 492 - #endif 493 491 }; 494 492 495 493 ··· 3258 3260 return err; 3259 3261 } 3260 3262 3261 - #ifdef CONFIG_PM_SLEEP 3262 3263 /* 3263 3264 * power management 3264 3265 */ ··· 3321 3324 return 0; 3322 3325 } 3323 3326 3324 - static SIMPLE_DEV_PM_OPS(snd_cmipci_pm, snd_cmipci_suspend, snd_cmipci_resume); 3325 - #define SND_CMIPCI_PM_OPS &snd_cmipci_pm 3326 - #else 3327 - #define SND_CMIPCI_PM_OPS NULL 3328 - #endif /* CONFIG_PM_SLEEP */ 3327 + static DEFINE_SIMPLE_DEV_PM_OPS(snd_cmipci_pm, snd_cmipci_suspend, snd_cmipci_resume); 3329 3328 3330 3329 static struct pci_driver cmipci_driver = { 3331 3330 .name = KBUILD_MODNAME, 3332 3331 .id_table = snd_cmipci_ids, 3333 3332 .probe = snd_cmipci_probe, 3334 3333 .driver = { 3335 - .pm = SND_CMIPCI_PM_OPS, 3334 + .pm = &snd_cmipci_pm, 3336 3335 }, 3337 3336 }; 3338 3337
+2 -11
sound/pci/cs4281.c
··· 470 470 471 471 struct gameport *gameport; 472 472 473 - #ifdef CONFIG_PM_SLEEP 474 473 u32 suspend_regs[SUSPEND_REGISTERS]; 475 - #endif 476 - 477 474 }; 478 475 479 476 static irqreturn_t snd_cs4281_interrupt(int irq, void *dev_id); ··· 1894 1897 /* 1895 1898 * Power Management 1896 1899 */ 1897 - #ifdef CONFIG_PM_SLEEP 1898 - 1899 1900 static const int saved_regs[SUSPEND_REGISTERS] = { 1900 1901 BA0_JSCTL, 1901 1902 BA0_GPIOR, ··· 1982 1987 return 0; 1983 1988 } 1984 1989 1985 - static SIMPLE_DEV_PM_OPS(cs4281_pm, cs4281_suspend, cs4281_resume); 1986 - #define CS4281_PM_OPS &cs4281_pm 1987 - #else 1988 - #define CS4281_PM_OPS NULL 1989 - #endif /* CONFIG_PM_SLEEP */ 1990 + static DEFINE_SIMPLE_DEV_PM_OPS(cs4281_pm, cs4281_suspend, cs4281_resume); 1990 1991 1991 1992 static struct pci_driver cs4281_driver = { 1992 1993 .name = KBUILD_MODNAME, 1993 1994 .id_table = snd_cs4281_ids, 1994 1995 .probe = snd_cs4281_probe, 1995 1996 .driver = { 1996 - .pm = CS4281_PM_OPS, 1997 + .pm = &cs4281_pm, 1997 1998 }, 1998 1999 }; 1999 2000
+6 -4
sound/pci/ctxfi/ctamixer.c
··· 292 292 return 0; 293 293 } 294 294 295 - int amixer_mgr_create(struct hw *hw, struct amixer_mgr **ramixer_mgr) 295 + int amixer_mgr_create(struct hw *hw, void **ramixer_mgr) 296 296 { 297 297 int err; 298 298 struct amixer_mgr *amixer_mgr; ··· 321 321 return err; 322 322 } 323 323 324 - int amixer_mgr_destroy(struct amixer_mgr *amixer_mgr) 324 + int amixer_mgr_destroy(void *ptr) 325 325 { 326 + struct amixer_mgr *amixer_mgr = ptr; 326 327 rsc_mgr_uninit(&amixer_mgr->mgr); 327 328 kfree(amixer_mgr); 328 329 return 0; ··· 447 446 return 0; 448 447 } 449 448 450 - int sum_mgr_create(struct hw *hw, struct sum_mgr **rsum_mgr) 449 + int sum_mgr_create(struct hw *hw, void **rsum_mgr) 451 450 { 452 451 int err; 453 452 struct sum_mgr *sum_mgr; ··· 476 475 return err; 477 476 } 478 477 479 - int sum_mgr_destroy(struct sum_mgr *sum_mgr) 478 + int sum_mgr_destroy(void *ptr) 480 479 { 480 + struct sum_mgr *sum_mgr = ptr; 481 481 rsc_mgr_uninit(&sum_mgr->mgr); 482 482 kfree(sum_mgr); 483 483 return 0;
+4 -4
sound/pci/ctxfi/ctamixer.h
··· 43 43 }; 44 44 45 45 /* Constructor and destructor of daio resource manager */ 46 - int sum_mgr_create(struct hw *hw, struct sum_mgr **rsum_mgr); 47 - int sum_mgr_destroy(struct sum_mgr *sum_mgr); 46 + int sum_mgr_create(struct hw *hw, void **ptr); 47 + int sum_mgr_destroy(void *ptr); 48 48 49 49 /* Define the descriptor of a amixer resource */ 50 50 struct amixer_rsc_ops; ··· 89 89 }; 90 90 91 91 /* Constructor and destructor of amixer resource manager */ 92 - int amixer_mgr_create(struct hw *hw, struct amixer_mgr **ramixer_mgr); 93 - int amixer_mgr_destroy(struct amixer_mgr *amixer_mgr); 92 + int amixer_mgr_create(struct hw *hw, void **ramixer_mgr); 93 + int amixer_mgr_destroy(void *amixer_mgr); 94 94 95 95 #endif /* CTAMIXER_H */
+10 -13
sound/pci/ctxfi/ctatc.c
··· 105 105 .public_name = "Mixer"} 106 106 }; 107 107 108 - typedef int (*create_t)(struct hw *, void **); 109 - typedef int (*destroy_t)(void *); 110 - 111 108 static struct { 112 109 int (*create)(struct hw *hw, void **rmgr); 113 110 int (*destroy)(void *mgr); 114 111 } rsc_mgr_funcs[NUM_RSCTYP] = { 115 - [SRC] = { .create = (create_t)src_mgr_create, 116 - .destroy = (destroy_t)src_mgr_destroy }, 117 - [SRCIMP] = { .create = (create_t)srcimp_mgr_create, 118 - .destroy = (destroy_t)srcimp_mgr_destroy }, 119 - [AMIXER] = { .create = (create_t)amixer_mgr_create, 120 - .destroy = (destroy_t)amixer_mgr_destroy }, 121 - [SUM] = { .create = (create_t)sum_mgr_create, 122 - .destroy = (destroy_t)sum_mgr_destroy }, 123 - [DAIO] = { .create = (create_t)daio_mgr_create, 124 - .destroy = (destroy_t)daio_mgr_destroy } 112 + [SRC] = { .create = src_mgr_create, 113 + .destroy = src_mgr_destroy }, 114 + [SRCIMP] = { .create = srcimp_mgr_create, 115 + .destroy = srcimp_mgr_destroy }, 116 + [AMIXER] = { .create = amixer_mgr_create, 117 + .destroy = amixer_mgr_destroy }, 118 + [SUM] = { .create = sum_mgr_create, 119 + .destroy = sum_mgr_destroy }, 120 + [DAIO] = { .create = daio_mgr_create, 121 + .destroy = daio_mgr_destroy } 125 122 }; 126 123 127 124 static int
+3 -2
sound/pci/ctxfi/ctdaio.c
··· 684 684 return 0; 685 685 } 686 686 687 - int daio_mgr_create(struct hw *hw, struct daio_mgr **rdaio_mgr) 687 + int daio_mgr_create(struct hw *hw, void **rdaio_mgr) 688 688 { 689 689 int err, i; 690 690 struct daio_mgr *daio_mgr; ··· 738 738 return err; 739 739 } 740 740 741 - int daio_mgr_destroy(struct daio_mgr *daio_mgr) 741 + int daio_mgr_destroy(void *ptr) 742 742 { 743 + struct daio_mgr *daio_mgr = ptr; 743 744 unsigned long flags; 744 745 745 746 /* free daio input mapper list */
+2 -2
sound/pci/ctxfi/ctdaio.h
··· 115 115 }; 116 116 117 117 /* Constructor and destructor of daio resource manager */ 118 - int daio_mgr_create(struct hw *hw, struct daio_mgr **rdaio_mgr); 119 - int daio_mgr_destroy(struct daio_mgr *daio_mgr); 118 + int daio_mgr_create(struct hw *hw, void **ptr); 119 + int daio_mgr_destroy(void *ptr); 120 120 121 121 #endif /* CTDAIO_H */
+6 -4
sound/pci/ctxfi/ctsrc.c
··· 540 540 return 0; 541 541 } 542 542 543 - int src_mgr_create(struct hw *hw, struct src_mgr **rsrc_mgr) 543 + int src_mgr_create(struct hw *hw, void **rsrc_mgr) 544 544 { 545 545 int err, i; 546 546 struct src_mgr *src_mgr; ··· 580 580 return err; 581 581 } 582 582 583 - int src_mgr_destroy(struct src_mgr *src_mgr) 583 + int src_mgr_destroy(void *ptr) 584 584 { 585 + struct src_mgr *src_mgr = ptr; 585 586 rsc_mgr_uninit(&src_mgr->mgr); 586 587 kfree(src_mgr); 587 588 ··· 822 821 return err; 823 822 } 824 823 825 - int srcimp_mgr_create(struct hw *hw, struct srcimp_mgr **rsrcimp_mgr) 824 + int srcimp_mgr_create(struct hw *hw, void **rsrcimp_mgr) 826 825 { 827 826 int err; 828 827 struct srcimp_mgr *srcimp_mgr; ··· 867 866 return err; 868 867 } 869 868 870 - int srcimp_mgr_destroy(struct srcimp_mgr *srcimp_mgr) 869 + int srcimp_mgr_destroy(void *ptr) 871 870 { 871 + struct srcimp_mgr *srcimp_mgr = ptr; 872 872 unsigned long flags; 873 873 874 874 /* free src input mapper list */
+4 -4
sound/pci/ctxfi/ctsrc.h
··· 139 139 }; 140 140 141 141 /* Constructor and destructor of SRC resource manager */ 142 - int src_mgr_create(struct hw *hw, struct src_mgr **rsrc_mgr); 143 - int src_mgr_destroy(struct src_mgr *src_mgr); 142 + int src_mgr_create(struct hw *hw, void **ptr); 143 + int src_mgr_destroy(void *ptr); 144 144 /* Constructor and destructor of SRCIMP resource manager */ 145 - int srcimp_mgr_create(struct hw *hw, struct srcimp_mgr **rsrc_mgr); 146 - int srcimp_mgr_destroy(struct srcimp_mgr *srcimp_mgr); 145 + int srcimp_mgr_create(struct hw *hw, void **ptr); 146 + int srcimp_mgr_destroy(void *ptr); 147 147 148 148 #endif /* CTSRC_H */
+2 -19
sound/pci/echoaudio/echoaudio.c
··· 34 34 int err; 35 35 char name[30]; 36 36 37 - #ifdef CONFIG_PM_SLEEP 38 37 if (chip->fw_cache[fw_index]) { 39 38 dev_dbg(chip->card->dev, 40 39 "firmware requested: %s is cached\n", ··· 41 42 *fw_entry = chip->fw_cache[fw_index]; 42 43 return 0; 43 44 } 44 - #endif 45 45 46 46 dev_dbg(chip->card->dev, 47 47 "firmware requested: %s\n", card_fw[fw_index].data); ··· 49 51 if (err < 0) 50 52 dev_err(chip->card->dev, 51 53 "get_firmware(): Firmware not available (%d)\n", err); 52 - #ifdef CONFIG_PM_SLEEP 53 54 else 54 55 chip->fw_cache[fw_index] = *fw_entry; 55 - #endif 56 56 return err; 57 57 } 58 58 ··· 59 63 static void free_firmware(const struct firmware *fw_entry, 60 64 struct echoaudio *chip) 61 65 { 62 - #ifdef CONFIG_PM_SLEEP 63 66 dev_dbg(chip->card->dev, "firmware not released (kept in cache)\n"); 64 - #else 65 - release_firmware(fw_entry); 66 - #endif 67 67 } 68 68 69 69 70 70 71 71 static void free_firmware_cache(struct echoaudio *chip) 72 72 { 73 - #ifdef CONFIG_PM_SLEEP 74 73 int i; 75 74 76 75 for (i = 0; i < 8 ; i++) ··· 73 82 release_firmware(chip->fw_cache[i]); 74 83 dev_dbg(chip->card->dev, "release_firmware(%d)\n", i); 75 84 } 76 - 77 - #endif 78 85 } 79 86 80 87 ··· 2135 2146 } 2136 2147 2137 2148 2138 - #if defined(CONFIG_PM_SLEEP) 2139 - 2140 2149 static int snd_echo_suspend(struct device *dev) 2141 2150 { 2142 2151 struct echoaudio *chip = dev_get_drvdata(dev); ··· 2224 2237 return 0; 2225 2238 } 2226 2239 2227 - static SIMPLE_DEV_PM_OPS(snd_echo_pm, snd_echo_suspend, snd_echo_resume); 2228 - #define SND_ECHO_PM_OPS &snd_echo_pm 2229 - #else 2230 - #define SND_ECHO_PM_OPS NULL 2231 - #endif /* CONFIG_PM_SLEEP */ 2240 + static DEFINE_SIMPLE_DEV_PM_OPS(snd_echo_pm, snd_echo_suspend, snd_echo_resume); 2232 2241 2233 2242 /****************************************************************************** 2234 2243 Everything starts and ends here ··· 2236 2253 .id_table = snd_echo_ids, 2237 2254 .probe = snd_echo_probe, 2238 2255 .driver = { 2239 - .pm = SND_ECHO_PM_OPS, 2256 + .pm = &snd_echo_pm, 2240 2257 }, 2241 2258 }; 2242 2259
-2
sound/pci/echoaudio/echoaudio.h
··· 422 422 u32 __iomem *dsp_registers; /* DSP's register base */ 423 423 u32 active_mask; /* Chs. active mask or 424 424 * punks out */ 425 - #ifdef CONFIG_PM_SLEEP 426 425 const struct firmware *fw_cache[8]; /* Cached firmwares */ 427 - #endif 428 426 429 427 #ifdef ECHOCARD_HAS_MIDI 430 428 u16 mtc_state; /* State for MIDI input parsing state machine */
-1
sound/pci/echoaudio/echoaudio_3g.c
··· 274 274 chip->digital_mode == DIGITAL_MODE_ADAT)) 275 275 return -EINVAL; 276 276 277 - clock = 0; 278 277 control_reg = le32_to_cpu(chip->comm_page->control_register); 279 278 control_reg &= E3G_CLOCK_CLEAR_MASK; 280 279
+2 -7
sound/pci/ens1370.c
··· 1968 1968 outl(ensoniq->cssr, ES_REG(ensoniq, STATUS)); 1969 1969 } 1970 1970 1971 - #ifdef CONFIG_PM_SLEEP 1972 1971 static int snd_ensoniq_suspend(struct device *dev) 1973 1972 { 1974 1973 struct snd_card *card = dev_get_drvdata(dev); ··· 2006 2007 return 0; 2007 2008 } 2008 2009 2009 - static SIMPLE_DEV_PM_OPS(snd_ensoniq_pm, snd_ensoniq_suspend, snd_ensoniq_resume); 2010 - #define SND_ENSONIQ_PM_OPS &snd_ensoniq_pm 2011 - #else 2012 - #define SND_ENSONIQ_PM_OPS NULL 2013 - #endif /* CONFIG_PM_SLEEP */ 2010 + static DEFINE_SIMPLE_DEV_PM_OPS(snd_ensoniq_pm, snd_ensoniq_suspend, snd_ensoniq_resume); 2014 2011 2015 2012 static int snd_ensoniq_create(struct snd_card *card, 2016 2013 struct pci_dev *pci) ··· 2375 2380 .id_table = snd_audiopci_ids, 2376 2381 .probe = snd_audiopci_probe, 2377 2382 .driver = { 2378 - .pm = SND_ENSONIQ_PM_OPS, 2383 + .pm = &snd_ensoniq_pm, 2379 2384 }, 2380 2385 }; 2381 2386
+2 -9
sound/pci/es1938.c
··· 216 216 #ifdef SUPPORT_JOYSTICK 217 217 struct gameport *gameport; 218 218 #endif 219 - #ifdef CONFIG_PM_SLEEP 220 219 unsigned char saved_regs[SAVED_REG_SIZE]; 221 - #endif 222 220 }; 223 221 224 222 static irqreturn_t snd_es1938_interrupt(int irq, void *dev_id); ··· 1393 1395 outb(0, SLDM_REG(chip, DMACLEAR)); 1394 1396 } 1395 1397 1396 - #ifdef CONFIG_PM_SLEEP 1397 1398 /* 1398 1399 * PM support 1399 1400 */ ··· 1458 1461 return 0; 1459 1462 } 1460 1463 1461 - static SIMPLE_DEV_PM_OPS(es1938_pm, es1938_suspend, es1938_resume); 1462 - #define ES1938_PM_OPS &es1938_pm 1463 - #else 1464 - #define ES1938_PM_OPS NULL 1465 - #endif /* CONFIG_PM_SLEEP */ 1464 + static DEFINE_SIMPLE_DEV_PM_OPS(es1938_pm, es1938_suspend, es1938_resume); 1466 1465 1467 1466 #ifdef SUPPORT_JOYSTICK 1468 1467 static int snd_es1938_create_gameport(struct es1938 *chip) ··· 1780 1787 .id_table = snd_es1938_ids, 1781 1788 .probe = snd_es1938_probe, 1782 1789 .driver = { 1783 - .pm = ES1938_PM_OPS, 1790 + .pm = &es1938_pm, 1784 1791 }, 1785 1792 }; 1786 1793
+2 -15
sound/pci/es1968.c
··· 473 473 /* linked list */ 474 474 struct list_head list; 475 475 476 - #ifdef CONFIG_PM_SLEEP 477 476 u16 wc_map[4]; 478 - #endif 479 477 }; 480 478 481 479 struct es1968 { ··· 524 526 struct list_head substream_list; 525 527 spinlock_t substream_lock; 526 528 527 - #ifdef CONFIG_PM_SLEEP 528 529 u16 apu_map[NR_APUS][NR_APU_REGS]; 529 - #endif 530 530 531 531 #ifdef SUPPORT_JOYSTICK 532 532 struct gameport *gameport; ··· 685 689 { 686 690 if (snd_BUG_ON(channel >= NR_APUS)) 687 691 return; 688 - #ifdef CONFIG_PM_SLEEP 689 692 chip->apu_map[channel][reg] = data; 690 - #endif 691 693 reg |= (channel << 4); 692 694 apu_index_set(chip, reg); 693 695 apu_data_set(chip, data); ··· 970 976 /* set the wavecache control reg */ 971 977 wave_set_register(chip, es->apu[channel] << 3, tmpval); 972 978 973 - #ifdef CONFIG_PM_SLEEP 974 979 es->wc_map[channel] = tmpval; 975 - #endif 976 980 } 977 981 978 982 ··· 2348 2356 outw(w, chip->io_port + ESM_PORT_HOST_IRQ); 2349 2357 } 2350 2358 2351 - #ifdef CONFIG_PM_SLEEP 2352 2359 /* 2353 2360 * PM support 2354 2361 */ ··· 2409 2418 return 0; 2410 2419 } 2411 2420 2412 - static SIMPLE_DEV_PM_OPS(es1968_pm, es1968_suspend, es1968_resume); 2413 - #define ES1968_PM_OPS &es1968_pm 2414 - #else 2415 - #define ES1968_PM_OPS NULL 2416 - #endif /* CONFIG_PM_SLEEP */ 2421 + static DEFINE_SIMPLE_DEV_PM_OPS(es1968_pm, es1968_suspend, es1968_resume); 2417 2422 2418 2423 #ifdef SUPPORT_JOYSTICK 2419 2424 #define JOYSTICK_ADDR 0x200 ··· 2839 2852 .id_table = snd_es1968_ids, 2840 2853 .probe = snd_es1968_probe, 2841 2854 .driver = { 2842 - .pm = ES1968_PM_OPS, 2855 + .pm = &es1968_pm, 2843 2856 }, 2844 2857 }; 2845 2858
+2 -9
sound/pci/fm801.c
··· 222 222 struct snd_tea575x tea; 223 223 #endif 224 224 225 - #ifdef CONFIG_PM_SLEEP 226 225 u16 saved_regs[0x20]; 227 - #endif 228 226 }; 229 227 230 228 /* ··· 1337 1339 return snd_card_free_on_error(&pci->dev, __snd_card_fm801_probe(pci, pci_id)); 1338 1340 } 1339 1341 1340 - #ifdef CONFIG_PM_SLEEP 1341 1342 static const unsigned char saved_regs[] = { 1342 1343 FM801_PCM_VOL, FM801_I2S_VOL, FM801_FM_VOL, FM801_REC_SRC, 1343 1344 FM801_PLY_CTRL, FM801_PLY_COUNT, FM801_PLY_BUF1, FM801_PLY_BUF2, ··· 1393 1396 return 0; 1394 1397 } 1395 1398 1396 - static SIMPLE_DEV_PM_OPS(snd_fm801_pm, snd_fm801_suspend, snd_fm801_resume); 1397 - #define SND_FM801_PM_OPS &snd_fm801_pm 1398 - #else 1399 - #define SND_FM801_PM_OPS NULL 1400 - #endif /* CONFIG_PM_SLEEP */ 1399 + static DEFINE_SIMPLE_DEV_PM_OPS(snd_fm801_pm, snd_fm801_suspend, snd_fm801_resume); 1401 1400 1402 1401 static struct pci_driver fm801_driver = { 1403 1402 .name = KBUILD_MODNAME, 1404 1403 .id_table = snd_fm801_ids, 1405 1404 .probe = snd_card_fm801_probe, 1406 1405 .driver = { 1407 - .pm = SND_FM801_PM_OPS, 1406 + .pm = &snd_fm801_pm, 1408 1407 }, 1409 1408 }; 1410 1409
+4
sound/pci/hda/Kconfig
··· 116 116 tristate 117 117 select FW_CS_DSP 118 118 119 + config SND_HDA_SCODEC_COMPONENT 120 + tristate 121 + 119 122 config SND_HDA_SCODEC_CS35L41_I2C 120 123 tristate "Build CS35L41 HD-audio side codec support for I2C Bus" 121 124 depends on I2C ··· 204 201 tristate "Build Realtek HD-audio codec support" 205 202 select SND_HDA_GENERIC 206 203 select SND_HDA_GENERIC_LEDS 204 + select SND_HDA_SCODEC_COMPONENT 207 205 help 208 206 Say Y or M here to include Realtek HD-audio codec support in 209 207 snd-hda-intel driver, such as ALC880.
+2
sound/pci/hda/Makefile
··· 37 37 snd-hda-scodec-cs35l56-i2c-objs := cs35l56_hda_i2c.o 38 38 snd-hda-scodec-cs35l56-spi-objs := cs35l56_hda_spi.o 39 39 snd-hda-cs-dsp-ctls-objs := hda_cs_dsp_ctl.o 40 + snd-hda-scodec-component-objs := hda_component.o 40 41 snd-hda-scodec-tas2781-i2c-objs := tas2781_hda_i2c.o 41 42 42 43 # common driver ··· 68 67 obj-$(CONFIG_SND_HDA_SCODEC_CS35L56_I2C) += snd-hda-scodec-cs35l56-i2c.o 69 68 obj-$(CONFIG_SND_HDA_SCODEC_CS35L56_SPI) += snd-hda-scodec-cs35l56-spi.o 70 69 obj-$(CONFIG_SND_HDA_CS_DSP_CONTROLS) += snd-hda-cs-dsp-ctls.o 70 + obj-$(CONFIG_SND_HDA_SCODEC_COMPONENT) += snd-hda-scodec-component.o 71 71 obj-$(CONFIG_SND_HDA_SCODEC_TAS2781_I2C) += snd-hda-scodec-tas2781-i2c.o 72 72 73 73 # this must be the last entry after codec drivers;
+74 -16
sound/pci/hda/cs35l41_hda_property.c
··· 51 51 { "103C8A2E", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 }, 52 52 { "103C8A30", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 }, 53 53 { "103C8A31", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 }, 54 + { "103C8A6E", 4, EXTERNAL, { CS35L41_LEFT, CS35L41_LEFT, CS35L41_RIGHT, CS35L41_RIGHT }, 0, -1, -1, 0, 0, 0 }, 54 55 { "103C8BB3", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 }, 55 56 { "103C8BB4", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 }, 57 + { "103C8BDD", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 }, 58 + { "103C8BDE", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 }, 56 59 { "103C8BDF", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 }, 57 60 { "103C8BE0", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 }, 58 61 { "103C8BE1", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 }, 59 62 { "103C8BE2", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 }, 60 - { "103C8BE9", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 }, 61 - { "103C8BDD", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 }, 62 - { "103C8BDE", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 }, 63 63 { "103C8BE3", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 }, 64 64 { "103C8BE5", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 }, 65 65 { "103C8BE6", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 }, 66 + { "103C8BE7", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 }, 67 + { "103C8BE8", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 }, 68 + { "103C8BE9", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 }, 66 69 { "103C8B3A", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 }, 70 + { "103C8C15", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4000, 24 }, 71 + { "103C8C16", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4000, 24 }, 72 + { "103C8C17", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4000, 24 }, 73 + { "103C8C4F", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 }, 74 + { "103C8C50", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 }, 75 + { "103C8C51", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 }, 76 + { "103C8CDD", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 }, 77 + { "103C8CDE", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 3900, 24 }, 67 78 { "104312AF", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 }, 68 79 { "10431433", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4500, 24 }, 69 80 { "10431463", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4500, 24 }, ··· 221 210 struct spi_device *spi; 222 211 bool dsd_found; 223 212 int ret; 213 + int i; 224 214 225 215 for (cfg = cs35l41_config_table; cfg->ssid; cfg++) { 226 216 if (!strcasecmp(cfg->ssid, cs35l41->acpi_subsystem_id)) ··· 307 295 cs35l41->index = id == 0x40 ? 0 : 1; 308 296 } 309 297 310 - if (cfg->num_amps == 3) 311 - /* 3 amps means a center channel, so no duplicate channels */ 312 - cs35l41->channel_index = 0; 313 - else 314 - /* 315 - * if 4 amps, there are duplicate channels, so they need different indexes 316 - * if 2 amps, no duplicate channels, channel_index would be 0 317 - */ 318 - cs35l41->channel_index = cs35l41->index / 2; 319 - 320 298 cs35l41->reset_gpio = fwnode_gpiod_get_index(acpi_fwnode_handle(cs35l41->dacpi), "reset", 321 299 cs35l41->index, GPIOD_OUT_LOW, 322 300 "cs35l41-reset"); 323 301 cs35l41->speaker_id = cs35l41_get_speaker_id(physdev, cs35l41->index, cfg->num_amps, -1); 324 302 325 303 hw_cfg->spk_pos = cfg->channel[cs35l41->index]; 304 + 305 + cs35l41->channel_index = 0; 306 + for (i = 0; i < cs35l41->index; i++) 307 + if (cfg->channel[i] == hw_cfg->spk_pos) 308 + cs35l41->channel_index++; 326 309 327 310 if (cfg->boost_type == INTERNAL) { 328 311 hw_cfg->bst_type = CS35L41_INT_BOOST; ··· 338 331 hw_cfg->gpio2.func = CS35L41_INTERRUPT; 339 332 hw_cfg->gpio2.valid = true; 340 333 hw_cfg->valid = true; 334 + 335 + return 0; 336 + } 337 + 338 + /* 339 + * Systems 103C8C66, 103C8C67, 103C8C68, 103C8C6A use a dual speaker id system - each speaker has 340 + * its own speaker id. 341 + */ 342 + static int hp_i2c_int_2amp_dual_spkid(struct cs35l41_hda *cs35l41, struct device *physdev, int id, 343 + const char *hid) 344 + { 345 + struct cs35l41_hw_cfg *hw_cfg = &cs35l41->hw_cfg; 346 + 347 + /* If _DSD exists for this laptop, we cannot support it through here */ 348 + if (acpi_dev_has_props(cs35l41->dacpi)) 349 + return -ENOENT; 350 + 351 + /* check I2C address to assign the index */ 352 + cs35l41->index = id == 0x40 ? 0 : 1; 353 + cs35l41->channel_index = 0; 354 + cs35l41->reset_gpio = gpiod_get_index(physdev, NULL, 0, GPIOD_OUT_HIGH); 355 + if (cs35l41->index == 0) 356 + cs35l41->speaker_id = cs35l41_get_speaker_id(physdev, 0, 0, 1); 357 + else 358 + cs35l41->speaker_id = cs35l41_get_speaker_id(physdev, 0, 0, 2); 359 + hw_cfg->spk_pos = cs35l41->index; 360 + hw_cfg->gpio2.func = CS35L41_INTERRUPT; 361 + hw_cfg->gpio2.valid = true; 362 + hw_cfg->valid = true; 363 + 364 + hw_cfg->bst_type = CS35L41_INT_BOOST; 365 + hw_cfg->bst_ind = 1000; 366 + hw_cfg->bst_ipk = 4100; 367 + hw_cfg->bst_cap = 24; 368 + hw_cfg->gpio1.func = CS35L41_NOT_USED; 369 + hw_cfg->gpio1.valid = true; 341 370 342 371 return 0; 343 372 } ··· 435 392 { "CSC3551", "103C8A2E", generic_dsd_config }, 436 393 { "CSC3551", "103C8A30", generic_dsd_config }, 437 394 { "CSC3551", "103C8A31", generic_dsd_config }, 395 + { "CSC3551", "103C8A6E", generic_dsd_config }, 438 396 { "CSC3551", "103C8BB3", generic_dsd_config }, 439 397 { "CSC3551", "103C8BB4", generic_dsd_config }, 398 + { "CSC3551", "103C8BDD", generic_dsd_config }, 399 + { "CSC3551", "103C8BDE", generic_dsd_config }, 440 400 { "CSC3551", "103C8BDF", generic_dsd_config }, 441 401 { "CSC3551", "103C8BE0", generic_dsd_config }, 442 402 { "CSC3551", "103C8BE1", generic_dsd_config }, 443 403 { "CSC3551", "103C8BE2", generic_dsd_config }, 444 - { "CSC3551", "103C8BE9", generic_dsd_config }, 445 - { "CSC3551", "103C8BDD", generic_dsd_config }, 446 - { "CSC3551", "103C8BDE", generic_dsd_config }, 447 404 { "CSC3551", "103C8BE3", generic_dsd_config }, 448 405 { "CSC3551", "103C8BE5", generic_dsd_config }, 449 406 { "CSC3551", "103C8BE6", generic_dsd_config }, 407 + { "CSC3551", "103C8BE7", generic_dsd_config }, 408 + { "CSC3551", "103C8BE8", generic_dsd_config }, 409 + { "CSC3551", "103C8BE9", generic_dsd_config }, 450 410 { "CSC3551", "103C8B3A", generic_dsd_config }, 411 + { "CSC3551", "103C8C15", generic_dsd_config }, 412 + { "CSC3551", "103C8C16", generic_dsd_config }, 413 + { "CSC3551", "103C8C17", generic_dsd_config }, 414 + { "CSC3551", "103C8C4F", generic_dsd_config }, 415 + { "CSC3551", "103C8C50", generic_dsd_config }, 416 + { "CSC3551", "103C8C51", generic_dsd_config }, 417 + { "CSC3551", "103C8C66", hp_i2c_int_2amp_dual_spkid }, 418 + { "CSC3551", "103C8C67", hp_i2c_int_2amp_dual_spkid }, 419 + { "CSC3551", "103C8C68", hp_i2c_int_2amp_dual_spkid }, 420 + { "CSC3551", "103C8C6A", hp_i2c_int_2amp_dual_spkid }, 421 + { "CSC3551", "103C8CDD", generic_dsd_config }, 422 + { "CSC3551", "103C8CDE", generic_dsd_config }, 451 423 { "CSC3551", "104312AF", generic_dsd_config }, 452 424 { "CSC3551", "10431433", generic_dsd_config }, 453 425 { "CSC3551", "10431463", generic_dsd_config },
+10 -6
sound/pci/hda/cs35l56_hda.c
··· 458 458 459 459 if (preloaded_fw_ver) { 460 460 snprintf(base_name, sizeof(base_name), 461 - "cirrus/cs35l56-%02x%s-%06x-dsp1-misc", 461 + "cirrus/cs35l%02x-%02x%s-%06x-dsp1-misc", 462 + cs35l56->base.type, 462 463 cs35l56->base.rev, 463 464 cs35l56->base.secured ? "-s" : "", 464 465 preloaded_fw_ver & 0xffffff); 465 466 } else { 466 467 snprintf(base_name, sizeof(base_name), 467 - "cirrus/cs35l56-%02x%s-dsp1-misc", 468 + "cirrus/cs35l%02x-%02x%s-dsp1-misc", 469 + cs35l56->base.type, 468 470 cs35l56->base.rev, 469 471 cs35l56->base.secured ? "-s" : ""); 470 472 } ··· 836 834 return 0; 837 835 } 838 836 839 - static int cs35l56_hda_read_acpi(struct cs35l56_hda *cs35l56, int id) 837 + static int cs35l56_hda_read_acpi(struct cs35l56_hda *cs35l56, int hid, int id) 840 838 { 841 839 u32 values[HDA_MAX_COMPONENTS]; 840 + char hid_string[8]; 842 841 struct acpi_device *adev; 843 842 const char *property, *sub; 844 843 size_t nval; ··· 850 847 * the serial-multi-instantiate driver, so lookup the node by HID 851 848 */ 852 849 if (!ACPI_COMPANION(cs35l56->base.dev)) { 853 - adev = acpi_dev_get_first_match_dev("CSC3556", NULL, -1); 850 + snprintf(hid_string, sizeof(hid_string), "CSC%04X", hid); 851 + adev = acpi_dev_get_first_match_dev(hid_string, NULL, -1); 854 852 if (!adev) { 855 853 dev_err(cs35l56->base.dev, "Failed to find an ACPI device for %s\n", 856 854 dev_name(cs35l56->base.dev)); ··· 939 935 return ret; 940 936 } 941 937 942 - int cs35l56_hda_common_probe(struct cs35l56_hda *cs35l56, int id) 938 + int cs35l56_hda_common_probe(struct cs35l56_hda *cs35l56, int hid, int id) 943 939 { 944 940 int ret; 945 941 946 942 mutex_init(&cs35l56->base.irq_lock); 947 943 dev_set_drvdata(cs35l56->base.dev, cs35l56); 948 944 949 - ret = cs35l56_hda_read_acpi(cs35l56, id); 945 + ret = cs35l56_hda_read_acpi(cs35l56, hid, id); 950 946 if (ret) 951 947 goto err; 952 948
+1 -1
sound/pci/hda/cs35l56_hda.h
··· 42 42 43 43 extern const struct dev_pm_ops cs35l56_hda_pm_ops; 44 44 45 - int cs35l56_hda_common_probe(struct cs35l56_hda *cs35l56, int id); 45 + int cs35l56_hda_common_probe(struct cs35l56_hda *cs35l56, int hid, int id); 46 46 void cs35l56_hda_remove(struct device *dev); 47 47 48 48 #endif /*__CS35L56_HDA_H__*/
+5 -2
sound/pci/hda/cs35l56_hda_i2c.c
··· 13 13 14 14 static int cs35l56_hda_i2c_probe(struct i2c_client *clt) 15 15 { 16 + const struct i2c_device_id *id = i2c_client_get_device_id(clt); 16 17 struct cs35l56_hda *cs35l56; 17 18 int ret; 18 19 ··· 34 33 return ret; 35 34 } 36 35 37 - ret = cs35l56_hda_common_probe(cs35l56, clt->addr); 36 + ret = cs35l56_hda_common_probe(cs35l56, id->driver_data, clt->addr); 38 37 if (ret) 39 38 return ret; 40 39 ret = cs35l56_irq_request(&cs35l56->base, clt->irq); ··· 50 49 } 51 50 52 51 static const struct i2c_device_id cs35l56_hda_i2c_id[] = { 53 - { "cs35l56-hda", 0 }, 52 + { "cs35l54-hda", 0x3554 }, 53 + { "cs35l56-hda", 0x3556 }, 54 + { "cs35l57-hda", 0x3557 }, 54 55 {} 55 56 }; 56 57
+5 -2
sound/pci/hda/cs35l56_hda_spi.c
··· 13 13 14 14 static int cs35l56_hda_spi_probe(struct spi_device *spi) 15 15 { 16 + const struct spi_device_id *id = spi_get_device_id(spi); 16 17 struct cs35l56_hda *cs35l56; 17 18 int ret; 18 19 ··· 34 33 return ret; 35 34 } 36 35 37 - ret = cs35l56_hda_common_probe(cs35l56, spi_get_chipselect(spi, 0)); 36 + ret = cs35l56_hda_common_probe(cs35l56, id->driver_data, spi_get_chipselect(spi, 0)); 38 37 if (ret) 39 38 return ret; 40 39 ret = cs35l56_irq_request(&cs35l56->base, spi->irq); ··· 50 49 } 51 50 52 51 static const struct spi_device_id cs35l56_hda_spi_id[] = { 53 - { "cs35l56-hda", 0 }, 52 + { "cs35l54-hda", 0x3554 }, 53 + { "cs35l56-hda", 0x3556 }, 54 + { "cs35l57-hda", 0x3557 }, 54 55 {} 55 56 }; 56 57
-1
sound/pci/hda/hda_beep.c
··· 231 231 codec->beep = beep; 232 232 233 233 INIT_WORK(&beep->beep_work, &snd_hda_generate_beep); 234 - mutex_init(&beep->mutex); 235 234 236 235 input_dev = input_allocate_device(); 237 236 if (!input_dev) {
-1
sound/pci/hda/hda_beep.h
··· 27 27 unsigned int playing:1; 28 28 unsigned int keep_power_at_enable:1; /* set by driver */ 29 29 struct work_struct beep_work; /* scheduled task for beep event */ 30 - struct mutex mutex; 31 30 void (*power_hook)(struct hda_beep *beep, bool on); 32 31 }; 33 32
+1 -1
sound/pci/hda/hda_codec.c
··· 3313 3313 list_for_each_entry(cpcm, &codec->pcm_list_head, list) { 3314 3314 int stream; 3315 3315 3316 - for (stream = 0; stream < 2; stream++) { 3316 + for_each_pcm_streams(stream) { 3317 3317 struct hda_pcm_stream *info = &cpcm->stream[stream]; 3318 3318 3319 3319 if (!info->substreams)
+169
sound/pci/hda/hda_component.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + /* 3 + * HD audio Component Binding Interface 4 + * 5 + * Copyright (C) 2021, 2023 Cirrus Logic, Inc. and 6 + * Cirrus Logic International Semiconductor Ltd. 7 + */ 8 + 9 + #include <linux/acpi.h> 10 + #include <linux/component.h> 11 + #include <linux/module.h> 12 + #include <linux/slab.h> 13 + #include <sound/hda_codec.h> 14 + #include "hda_component.h" 15 + #include "hda_local.h" 16 + 17 + #ifdef CONFIG_ACPI 18 + void hda_component_acpi_device_notify(struct hda_component *comps, int num_comps, 19 + acpi_handle handle, u32 event, void *data) 20 + { 21 + int i; 22 + 23 + for (i = 0; i < num_comps; i++) { 24 + if (comps[i].dev && comps[i].acpi_notify) 25 + comps[i].acpi_notify(acpi_device_handle(comps[i].adev), event, 26 + comps[i].dev); 27 + } 28 + } 29 + EXPORT_SYMBOL_NS_GPL(hda_component_acpi_device_notify, SND_HDA_SCODEC_COMPONENT); 30 + 31 + int hda_component_manager_bind_acpi_notifications(struct hda_codec *cdc, 32 + struct hda_component *comps, int num_comps, 33 + acpi_notify_handler handler, void *data) 34 + { 35 + bool support_notifications = false; 36 + struct acpi_device *adev; 37 + int ret; 38 + int i; 39 + 40 + adev = comps[0].adev; 41 + if (!acpi_device_handle(adev)) 42 + return 0; 43 + 44 + for (i = 0; i < num_comps; i++) 45 + support_notifications = support_notifications || 46 + comps[i].acpi_notifications_supported; 47 + 48 + if (support_notifications) { 49 + ret = acpi_install_notify_handler(adev->handle, ACPI_DEVICE_NOTIFY, 50 + handler, data); 51 + if (ret < 0) { 52 + codec_warn(cdc, "Failed to install notify handler: %d\n", ret); 53 + return 0; 54 + } 55 + 56 + codec_dbg(cdc, "Notify handler installed\n"); 57 + } 58 + 59 + return 0; 60 + } 61 + EXPORT_SYMBOL_NS_GPL(hda_component_manager_bind_acpi_notifications, SND_HDA_SCODEC_COMPONENT); 62 + 63 + void hda_component_manager_unbind_acpi_notifications(struct hda_codec *cdc, 64 + struct hda_component *comps, 65 + acpi_notify_handler handler) 66 + { 67 + struct acpi_device *adev; 68 + int ret; 69 + 70 + adev = comps[0].adev; 71 + if (!acpi_device_handle(adev)) 72 + return; 73 + 74 + ret = acpi_remove_notify_handler(adev->handle, ACPI_DEVICE_NOTIFY, handler); 75 + if (ret < 0) 76 + codec_warn(cdc, "Failed to uninstall notify handler: %d\n", ret); 77 + } 78 + EXPORT_SYMBOL_NS_GPL(hda_component_manager_unbind_acpi_notifications, SND_HDA_SCODEC_COMPONENT); 79 + #endif /* ifdef CONFIG_ACPI */ 80 + 81 + void hda_component_manager_playback_hook(struct hda_component *comps, int num_comps, int action) 82 + { 83 + int i; 84 + 85 + for (i = 0; i < num_comps; i++) { 86 + if (comps[i].dev && comps[i].pre_playback_hook) 87 + comps[i].pre_playback_hook(comps[i].dev, action); 88 + } 89 + for (i = 0; i < num_comps; i++) { 90 + if (comps[i].dev && comps[i].playback_hook) 91 + comps[i].playback_hook(comps[i].dev, action); 92 + } 93 + for (i = 0; i < num_comps; i++) { 94 + if (comps[i].dev && comps[i].post_playback_hook) 95 + comps[i].post_playback_hook(comps[i].dev, action); 96 + } 97 + } 98 + EXPORT_SYMBOL_NS_GPL(hda_component_manager_playback_hook, SND_HDA_SCODEC_COMPONENT); 99 + 100 + struct hda_scodec_match { 101 + const char *bus; 102 + const char *hid; 103 + const char *match_str; 104 + int index; 105 + }; 106 + 107 + /* match the device name in a slightly relaxed manner */ 108 + static int hda_comp_match_dev_name(struct device *dev, void *data) 109 + { 110 + struct hda_scodec_match *p = data; 111 + const char *d = dev_name(dev); 112 + int n = strlen(p->bus); 113 + char tmp[32]; 114 + 115 + /* check the bus name */ 116 + if (strncmp(d, p->bus, n)) 117 + return 0; 118 + /* skip the bus number */ 119 + if (isdigit(d[n])) 120 + n++; 121 + /* the rest must be exact matching */ 122 + snprintf(tmp, sizeof(tmp), p->match_str, p->hid, p->index); 123 + return !strcmp(d + n, tmp); 124 + } 125 + 126 + int hda_component_manager_init(struct hda_codec *cdc, 127 + struct hda_component *comps, int count, 128 + const char *bus, const char *hid, 129 + const char *match_str, 130 + const struct component_master_ops *ops) 131 + { 132 + struct device *dev = hda_codec_dev(cdc); 133 + struct component_match *match = NULL; 134 + struct hda_scodec_match *sm; 135 + int ret, i; 136 + 137 + for (i = 0; i < count; i++) { 138 + sm = devm_kmalloc(dev, sizeof(*sm), GFP_KERNEL); 139 + if (!sm) 140 + return -ENOMEM; 141 + 142 + sm->bus = bus; 143 + sm->hid = hid; 144 + sm->match_str = match_str; 145 + sm->index = i; 146 + comps[i].codec = cdc; 147 + component_match_add(dev, &match, hda_comp_match_dev_name, sm); 148 + } 149 + 150 + ret = component_master_add_with_match(dev, ops, match); 151 + if (ret) 152 + codec_err(cdc, "Fail to register component aggregator %d\n", ret); 153 + 154 + return ret; 155 + } 156 + EXPORT_SYMBOL_NS_GPL(hda_component_manager_init, SND_HDA_SCODEC_COMPONENT); 157 + 158 + void hda_component_manager_free(struct hda_codec *cdc, 159 + const struct component_master_ops *ops) 160 + { 161 + struct device *dev = hda_codec_dev(cdc); 162 + 163 + component_master_del(dev, ops); 164 + } 165 + EXPORT_SYMBOL_NS_GPL(hda_component_manager_free, SND_HDA_SCODEC_COMPONENT); 166 + 167 + MODULE_DESCRIPTION("HD Audio component binding library"); 168 + MODULE_AUTHOR("Richard Fitzgerald <rf@opensource.cirrus.com>"); 169 + MODULE_LICENSE("GPL");
+65
sound/pci/hda/hda_component.h
··· 6 6 * Cirrus Logic International Semiconductor Ltd. 7 7 */ 8 8 9 + #ifndef __HDA_COMPONENT_H__ 10 + #define __HDA_COMPONENT_H__ 11 + 9 12 #include <linux/acpi.h> 10 13 #include <linux/component.h> 14 + #include <sound/hda_codec.h> 11 15 12 16 #define HDA_MAX_COMPONENTS 4 13 17 #define HDA_MAX_NAME_SIZE 50 ··· 27 23 void (*playback_hook)(struct device *dev, int action); 28 24 void (*post_playback_hook)(struct device *dev, int action); 29 25 }; 26 + 27 + #ifdef CONFIG_ACPI 28 + void hda_component_acpi_device_notify(struct hda_component *comps, int num_comps, 29 + acpi_handle handle, u32 event, void *data); 30 + int hda_component_manager_bind_acpi_notifications(struct hda_codec *cdc, 31 + struct hda_component *comps, int num_comps, 32 + acpi_notify_handler handler, void *data); 33 + void hda_component_manager_unbind_acpi_notifications(struct hda_codec *cdc, 34 + struct hda_component *comps, 35 + acpi_notify_handler handler); 36 + #else 37 + static inline void hda_component_acpi_device_notify(struct hda_component *comps, 38 + int num_comps, 39 + acpi_handle handle, 40 + u32 event, 41 + void *data) 42 + { 43 + } 44 + 45 + static inline int hda_component_manager_bind_acpi_notifications(struct hda_codec *cdc, 46 + struct hda_component *comps, 47 + int num_comps, 48 + acpi_notify_handler handler, 49 + void *data) 50 + 51 + { 52 + return 0; 53 + } 54 + 55 + static inline void hda_component_manager_unbind_acpi_notifications(struct hda_codec *cdc, 56 + struct hda_component *comps, 57 + acpi_notify_handler handler) 58 + { 59 + } 60 + #endif /* ifdef CONFIG_ACPI */ 61 + 62 + void hda_component_manager_playback_hook(struct hda_component *comps, int num_comps, 63 + int action); 64 + 65 + int hda_component_manager_init(struct hda_codec *cdc, 66 + struct hda_component *comps, int count, 67 + const char *bus, const char *hid, 68 + const char *match_str, 69 + const struct component_master_ops *ops); 70 + 71 + void hda_component_manager_free(struct hda_codec *cdc, 72 + const struct component_master_ops *ops); 73 + 74 + static inline int hda_component_manager_bind(struct hda_codec *cdc, 75 + struct hda_component *comps) 76 + { 77 + return component_bind_all(hda_codec_dev(cdc), comps); 78 + } 79 + 80 + static inline void hda_component_manager_unbind(struct hda_codec *cdc, 81 + struct hda_component *comps) 82 + { 83 + component_unbind_all(hda_codec_dev(cdc), comps); 84 + } 85 + 86 + #endif /* ifndef __HDA_COMPONENT_H__ */
+11 -3
sound/pci/hda/hda_controller.c
··· 24 24 25 25 #include <sound/core.h> 26 26 #include <sound/initval.h> 27 + #include <sound/pcm_params.h> 27 28 #include "hda_controller.h" 28 29 #include "hda_local.h" 29 30 ··· 109 108 struct azx_pcm *apcm = snd_pcm_substream_chip(substream); 110 109 struct azx *chip = apcm->chip; 111 110 struct azx_dev *azx_dev = get_azx_dev(substream); 111 + struct hdac_stream *hdas = azx_stream(azx_dev); 112 112 int ret = 0; 113 113 114 114 trace_azx_pcm_hw_params(chip, azx_dev); ··· 119 117 goto unlock; 120 118 } 121 119 122 - azx_dev->core.bufsize = 0; 123 - azx_dev->core.period_bytes = 0; 124 - azx_dev->core.format_val = 0; 120 + /* Set up BDLEs here, return -ENOMEM if too many BDLEs are required */ 121 + hdas->bufsize = params_buffer_bytes(hw_params); 122 + hdas->period_bytes = params_period_bytes(hw_params); 123 + hdas->format_val = 0; 124 + hdas->no_period_wakeup = 125 + (hw_params->info & SNDRV_PCM_INFO_NO_PERIOD_WAKEUP) && 126 + (hw_params->flags & SNDRV_PCM_HW_PARAMS_NO_PERIOD_WAKEUP); 127 + if (snd_hdac_stream_setup_periods(hdas) < 0) 128 + ret = -ENOMEM; 125 129 126 130 unlock: 127 131 dsp_unlock(azx_dev);
+79 -191
sound/pci/hda/patch_realtek.c
··· 133 133 u8 alc_mute_keycode_map[1]; 134 134 135 135 /* component binding */ 136 - struct component_match *match; 137 136 struct hda_component comps[HDA_MAX_COMPONENTS]; 138 137 }; 139 138 ··· 6719 6720 } 6720 6721 } 6721 6722 6722 - #ifdef CONFIG_ACPI 6723 6723 static void comp_acpi_device_notify(acpi_handle handle, u32 event, void *data) 6724 6724 { 6725 6725 struct hda_codec *cdc = data; 6726 6726 struct alc_spec *spec = cdc->spec; 6727 - int i; 6728 6727 6729 6728 codec_info(cdc, "ACPI Notification %d\n", event); 6730 6729 6731 - for (i = 0; i < HDA_MAX_COMPONENTS; i++) { 6732 - if (spec->comps[i].dev && spec->comps[i].acpi_notify) 6733 - spec->comps[i].acpi_notify(acpi_device_handle(spec->comps[i].adev), event, 6734 - spec->comps[i].dev); 6735 - } 6730 + hda_component_acpi_device_notify(spec->comps, ARRAY_SIZE(spec->comps), 6731 + handle, event, data); 6736 6732 } 6737 - 6738 - static int comp_bind_acpi(struct device *dev) 6739 - { 6740 - struct hda_codec *cdc = dev_to_hda_codec(dev); 6741 - struct alc_spec *spec = cdc->spec; 6742 - bool support_notifications = false; 6743 - struct acpi_device *adev; 6744 - int ret; 6745 - int i; 6746 - 6747 - adev = spec->comps[0].adev; 6748 - if (!acpi_device_handle(adev)) 6749 - return 0; 6750 - 6751 - for (i = 0; i < HDA_MAX_COMPONENTS; i++) 6752 - support_notifications = support_notifications || 6753 - spec->comps[i].acpi_notifications_supported; 6754 - 6755 - if (support_notifications) { 6756 - ret = acpi_install_notify_handler(adev->handle, ACPI_DEVICE_NOTIFY, 6757 - comp_acpi_device_notify, cdc); 6758 - if (ret < 0) { 6759 - codec_warn(cdc, "Failed to install notify handler: %d\n", ret); 6760 - return 0; 6761 - } 6762 - 6763 - codec_dbg(cdc, "Notify handler installed\n"); 6764 - } 6765 - 6766 - return 0; 6767 - } 6768 - 6769 - static void comp_unbind_acpi(struct device *dev) 6770 - { 6771 - struct hda_codec *cdc = dev_to_hda_codec(dev); 6772 - struct alc_spec *spec = cdc->spec; 6773 - struct acpi_device *adev; 6774 - int ret; 6775 - 6776 - adev = spec->comps[0].adev; 6777 - if (!acpi_device_handle(adev)) 6778 - return; 6779 - 6780 - ret = acpi_remove_notify_handler(adev->handle, ACPI_DEVICE_NOTIFY, 6781 - comp_acpi_device_notify); 6782 - if (ret < 0) 6783 - codec_warn(cdc, "Failed to uninstall notify handler: %d\n", ret); 6784 - } 6785 - #else 6786 - static int comp_bind_acpi(struct device *dev) 6787 - { 6788 - return 0; 6789 - } 6790 - 6791 - static void comp_unbind_acpi(struct device *dev) 6792 - { 6793 - } 6794 - #endif 6795 6733 6796 6734 static int comp_bind(struct device *dev) 6797 6735 { ··· 6736 6800 struct alc_spec *spec = cdc->spec; 6737 6801 int ret; 6738 6802 6739 - ret = component_bind_all(dev, spec->comps); 6803 + ret = hda_component_manager_bind(cdc, spec->comps); 6740 6804 if (ret) 6741 6805 return ret; 6742 6806 6743 - return comp_bind_acpi(dev); 6807 + return hda_component_manager_bind_acpi_notifications(cdc, 6808 + spec->comps, ARRAY_SIZE(spec->comps), 6809 + comp_acpi_device_notify, cdc); 6744 6810 } 6745 6811 6746 6812 static void comp_unbind(struct device *dev) ··· 6750 6812 struct hda_codec *cdc = dev_to_hda_codec(dev); 6751 6813 struct alc_spec *spec = cdc->spec; 6752 6814 6753 - comp_unbind_acpi(dev); 6754 - component_unbind_all(dev, spec->comps); 6815 + hda_component_manager_unbind_acpi_notifications(cdc, spec->comps, comp_acpi_device_notify); 6816 + hda_component_manager_unbind(cdc, spec->comps); 6755 6817 } 6756 6818 6757 6819 static const struct component_master_ops comp_master_ops = { ··· 6763 6825 struct snd_pcm_substream *sub, int action) 6764 6826 { 6765 6827 struct alc_spec *spec = cdc->spec; 6766 - int i; 6767 6828 6768 - for (i = 0; i < HDA_MAX_COMPONENTS; i++) { 6769 - if (spec->comps[i].dev && spec->comps[i].pre_playback_hook) 6770 - spec->comps[i].pre_playback_hook(spec->comps[i].dev, action); 6771 - } 6772 - for (i = 0; i < HDA_MAX_COMPONENTS; i++) { 6773 - if (spec->comps[i].dev && spec->comps[i].playback_hook) 6774 - spec->comps[i].playback_hook(spec->comps[i].dev, action); 6775 - } 6776 - for (i = 0; i < HDA_MAX_COMPONENTS; i++) { 6777 - if (spec->comps[i].dev && spec->comps[i].post_playback_hook) 6778 - spec->comps[i].post_playback_hook(spec->comps[i].dev, action); 6779 - } 6829 + hda_component_manager_playback_hook(spec->comps, ARRAY_SIZE(spec->comps), action); 6780 6830 } 6781 6831 6782 - struct scodec_dev_name { 6783 - const char *bus; 6784 - const char *hid; 6785 - int index; 6786 - }; 6787 - 6788 - /* match the device name in a slightly relaxed manner */ 6789 - static int comp_match_cs35l41_dev_name(struct device *dev, void *data) 6832 + static void comp_generic_fixup(struct hda_codec *cdc, int action, const char *bus, 6833 + const char *hid, const char *match_str, int count) 6790 6834 { 6791 - struct scodec_dev_name *p = data; 6792 - const char *d = dev_name(dev); 6793 - int n = strlen(p->bus); 6794 - char tmp[32]; 6795 - 6796 - /* check the bus name */ 6797 - if (strncmp(d, p->bus, n)) 6798 - return 0; 6799 - /* skip the bus number */ 6800 - if (isdigit(d[n])) 6801 - n++; 6802 - /* the rest must be exact matching */ 6803 - snprintf(tmp, sizeof(tmp), "-%s:00-cs35l41-hda.%d", p->hid, p->index); 6804 - return !strcmp(d + n, tmp); 6805 - } 6806 - 6807 - static int comp_match_tas2781_dev_name(struct device *dev, 6808 - void *data) 6809 - { 6810 - struct scodec_dev_name *p = data; 6811 - const char *d = dev_name(dev); 6812 - int n = strlen(p->bus); 6813 - char tmp[32]; 6814 - 6815 - /* check the bus name */ 6816 - if (strncmp(d, p->bus, n)) 6817 - return 0; 6818 - /* skip the bus number */ 6819 - if (isdigit(d[n])) 6820 - n++; 6821 - /* the rest must be exact matching */ 6822 - snprintf(tmp, sizeof(tmp), "-%s:00", p->hid); 6823 - 6824 - return !strcmp(d + n, tmp); 6825 - } 6826 - 6827 - static void cs35l41_generic_fixup(struct hda_codec *cdc, int action, const char *bus, 6828 - const char *hid, int count) 6829 - { 6830 - struct device *dev = hda_codec_dev(cdc); 6831 6835 struct alc_spec *spec = cdc->spec; 6832 - struct scodec_dev_name *rec; 6833 - int ret, i; 6834 - 6835 - switch (action) { 6836 - case HDA_FIXUP_ACT_PRE_PROBE: 6837 - for (i = 0; i < count; i++) { 6838 - rec = devm_kmalloc(dev, sizeof(*rec), GFP_KERNEL); 6839 - if (!rec) 6840 - return; 6841 - rec->bus = bus; 6842 - rec->hid = hid; 6843 - rec->index = i; 6844 - spec->comps[i].codec = cdc; 6845 - component_match_add(dev, &spec->match, 6846 - comp_match_cs35l41_dev_name, rec); 6847 - } 6848 - ret = component_master_add_with_match(dev, &comp_master_ops, spec->match); 6849 - if (ret) 6850 - codec_err(cdc, "Fail to register component aggregator %d\n", ret); 6851 - else 6852 - spec->gen.pcm_playback_hook = comp_generic_playback_hook; 6853 - break; 6854 - case HDA_FIXUP_ACT_FREE: 6855 - component_master_del(dev, &comp_master_ops); 6856 - break; 6857 - } 6858 - } 6859 - 6860 - static void tas2781_generic_fixup(struct hda_codec *cdc, int action, 6861 - const char *bus, const char *hid) 6862 - { 6863 - struct device *dev = hda_codec_dev(cdc); 6864 - struct alc_spec *spec = cdc->spec; 6865 - struct scodec_dev_name *rec; 6866 6836 int ret; 6867 6837 6868 6838 switch (action) { 6869 6839 case HDA_FIXUP_ACT_PRE_PROBE: 6870 - rec = devm_kmalloc(dev, sizeof(*rec), GFP_KERNEL); 6871 - if (!rec) 6872 - return; 6873 - rec->bus = bus; 6874 - rec->hid = hid; 6875 - rec->index = 0; 6876 - spec->comps[0].codec = cdc; 6877 - component_match_add(dev, &spec->match, 6878 - comp_match_tas2781_dev_name, rec); 6879 - ret = component_master_add_with_match(dev, &comp_master_ops, 6880 - spec->match); 6840 + ret = hda_component_manager_init(cdc, spec->comps, count, bus, hid, 6841 + match_str, &comp_master_ops); 6881 6842 if (ret) 6882 - codec_err(cdc, 6883 - "Fail to register component aggregator %d\n", 6884 - ret); 6885 - else 6886 - spec->gen.pcm_playback_hook = 6887 - comp_generic_playback_hook; 6843 + return; 6844 + 6845 + spec->gen.pcm_playback_hook = comp_generic_playback_hook; 6888 6846 break; 6889 6847 case HDA_FIXUP_ACT_FREE: 6890 - component_master_del(dev, &comp_master_ops); 6848 + hda_component_manager_free(cdc, &comp_master_ops); 6891 6849 break; 6892 6850 } 6893 6851 } 6894 6852 6895 6853 static void cs35l41_fixup_i2c_two(struct hda_codec *cdc, const struct hda_fixup *fix, int action) 6896 6854 { 6897 - cs35l41_generic_fixup(cdc, action, "i2c", "CSC3551", 2); 6855 + comp_generic_fixup(cdc, action, "i2c", "CSC3551", "-%s:00-cs35l41-hda.%d", 2); 6898 6856 } 6899 6857 6900 6858 static void cs35l41_fixup_i2c_four(struct hda_codec *cdc, const struct hda_fixup *fix, int action) 6901 6859 { 6902 - cs35l41_generic_fixup(cdc, action, "i2c", "CSC3551", 4); 6860 + comp_generic_fixup(cdc, action, "i2c", "CSC3551", "-%s:00-cs35l41-hda.%d", 4); 6903 6861 } 6904 6862 6905 6863 static void cs35l41_fixup_spi_two(struct hda_codec *codec, const struct hda_fixup *fix, int action) 6906 6864 { 6907 - cs35l41_generic_fixup(codec, action, "spi", "CSC3551", 2); 6865 + comp_generic_fixup(codec, action, "spi", "CSC3551", "-%s:00-cs35l41-hda.%d", 2); 6908 6866 } 6909 6867 6910 6868 static void cs35l41_fixup_spi_four(struct hda_codec *codec, const struct hda_fixup *fix, int action) 6911 6869 { 6912 - cs35l41_generic_fixup(codec, action, "spi", "CSC3551", 4); 6870 + comp_generic_fixup(codec, action, "spi", "CSC3551", "-%s:00-cs35l41-hda.%d", 4); 6913 6871 } 6914 6872 6915 6873 static void alc287_fixup_legion_16achg6_speakers(struct hda_codec *cdc, const struct hda_fixup *fix, 6916 6874 int action) 6917 6875 { 6918 - cs35l41_generic_fixup(cdc, action, "i2c", "CLSA0100", 2); 6876 + comp_generic_fixup(cdc, action, "i2c", "CLSA0100", "-%s:00-cs35l41-hda.%d", 2); 6919 6877 } 6920 6878 6921 6879 static void alc287_fixup_legion_16ithg6_speakers(struct hda_codec *cdc, const struct hda_fixup *fix, 6922 6880 int action) 6923 6881 { 6924 - cs35l41_generic_fixup(cdc, action, "i2c", "CLSA0101", 2); 6882 + comp_generic_fixup(cdc, action, "i2c", "CLSA0101", "-%s:00-cs35l41-hda.%d", 2); 6883 + } 6884 + 6885 + static void cs35l56_fixup_spi_four(struct hda_codec *cdc, const struct hda_fixup *fix, int action) 6886 + { 6887 + comp_generic_fixup(cdc, action, "spi", "CSC3556", "-%s:00-cs35l56-hda.%d", 4); 6925 6888 } 6926 6889 6927 6890 static void tas2781_fixup_i2c(struct hda_codec *cdc, 6928 6891 const struct hda_fixup *fix, int action) 6929 6892 { 6930 - tas2781_generic_fixup(cdc, action, "i2c", "TIAS2781"); 6893 + comp_generic_fixup(cdc, action, "i2c", "TIAS2781", "-%s:00", 1); 6931 6894 } 6932 6895 6933 6896 static void yoga7_14arb7_fixup_i2c(struct hda_codec *cdc, 6934 6897 const struct hda_fixup *fix, int action) 6935 6898 { 6936 - tas2781_generic_fixup(cdc, action, "i2c", "INT8866"); 6899 + comp_generic_fixup(cdc, action, "i2c", "INT8866", "-%s:00", 1); 6937 6900 } 6938 6901 6939 6902 /* for alc295_fixup_hp_top_speakers */ ··· 7317 7478 ALC2XX_FIXUP_HEADSET_MIC, 7318 7479 ALC289_FIXUP_DELL_CS35L41_SPI_2, 7319 7480 ALC294_FIXUP_CS35L41_I2C_2, 7481 + ALC245_FIXUP_CS35L56_SPI_4_HP_GPIO_LED, 7320 7482 }; 7321 7483 7322 7484 /* A special fixup for Lenovo C940 and Yoga Duet 7; ··· 9495 9655 .type = HDA_FIXUP_FUNC, 9496 9656 .v.func = cs35l41_fixup_i2c_two, 9497 9657 }, 9658 + [ALC245_FIXUP_CS35L56_SPI_4_HP_GPIO_LED] = { 9659 + .type = HDA_FIXUP_FUNC, 9660 + .v.func = cs35l56_fixup_spi_four, 9661 + .chained = true, 9662 + .chain_id = ALC285_FIXUP_HP_GPIO_LED, 9663 + }, 9498 9664 }; 9499 9665 9500 9666 static const struct snd_pci_quirk alc269_fixup_tbl[] = { ··· 9793 9947 SND_PCI_QUIRK(0x103c, 0x89c6, "Zbook Fury 17 G9", ALC245_FIXUP_CS35L41_SPI_2_HP_GPIO_LED), 9794 9948 SND_PCI_QUIRK(0x103c, 0x89ca, "HP", ALC236_FIXUP_HP_MUTE_LED_MICMUTE_VREF), 9795 9949 SND_PCI_QUIRK(0x103c, 0x89d3, "HP EliteBook 645 G9 (MB 89D2)", ALC236_FIXUP_HP_MUTE_LED_MICMUTE_VREF), 9950 + SND_PCI_QUIRK(0x103c, 0x89e7, "HP Elite x2 G9", ALC245_FIXUP_CS35L41_SPI_2_HP_GPIO_LED), 9796 9951 SND_PCI_QUIRK(0x103c, 0x8a0f, "HP Pavilion 14-ec1xxx", ALC287_FIXUP_HP_GPIO_LED), 9797 9952 SND_PCI_QUIRK(0x103c, 0x8a20, "HP Laptop 15s-fq5xxx", ALC236_FIXUP_HP_MUTE_LED_COEFBIT2), 9798 9953 SND_PCI_QUIRK(0x103c, 0x8a25, "HP Victus 16-d1xxx (MB 8A25)", ALC245_FIXUP_HP_MUTE_LED_COEFBIT), 9954 + SND_PCI_QUIRK(0x103c, 0x8a28, "HP Envy 13", ALC287_FIXUP_CS35L41_I2C_2), 9955 + SND_PCI_QUIRK(0x103c, 0x8a29, "HP Envy 15", ALC287_FIXUP_CS35L41_I2C_2), 9956 + SND_PCI_QUIRK(0x103c, 0x8a2a, "HP Envy 15", ALC287_FIXUP_CS35L41_I2C_2), 9957 + SND_PCI_QUIRK(0x103c, 0x8a2b, "HP Envy 15", ALC287_FIXUP_CS35L41_I2C_2), 9958 + SND_PCI_QUIRK(0x103c, 0x8a2c, "HP Envy 16", ALC287_FIXUP_CS35L41_I2C_2), 9959 + SND_PCI_QUIRK(0x103c, 0x8a2d, "HP Envy 16", ALC287_FIXUP_CS35L41_I2C_2), 9960 + SND_PCI_QUIRK(0x103c, 0x8a2e, "HP Envy 16", ALC287_FIXUP_CS35L41_I2C_2), 9961 + SND_PCI_QUIRK(0x103c, 0x8a2e, "HP Envy 17", ALC287_FIXUP_CS35L41_I2C_2), 9962 + SND_PCI_QUIRK(0x103c, 0x8a30, "HP Envy 17", ALC287_FIXUP_CS35L41_I2C_2), 9963 + SND_PCI_QUIRK(0x103c, 0x8a31, "HP Envy 15", ALC287_FIXUP_CS35L41_I2C_2), 9964 + SND_PCI_QUIRK(0x103c, 0x8a6e, "HP EDNA 360", ALC287_FIXUP_CS35L41_I2C_4), 9799 9965 SND_PCI_QUIRK(0x103c, 0x8a78, "HP Dev One", ALC285_FIXUP_HP_LIMIT_INT_MIC_BOOST), 9800 9966 SND_PCI_QUIRK(0x103c, 0x8aa0, "HP ProBook 440 G9 (MB 8A9E)", ALC236_FIXUP_HP_GPIO_LED), 9801 9967 SND_PCI_QUIRK(0x103c, 0x8aa3, "HP ProBook 450 G9 (MB 8AA1)", ALC236_FIXUP_HP_GPIO_LED), ··· 9817 9959 SND_PCI_QUIRK(0x103c, 0x8abb, "HP ZBook Firefly 14 G9", ALC245_FIXUP_CS35L41_SPI_2_HP_GPIO_LED), 9818 9960 SND_PCI_QUIRK(0x103c, 0x8ad1, "HP EliteBook 840 14 inch G9 Notebook PC", ALC245_FIXUP_CS35L41_SPI_2_HP_GPIO_LED), 9819 9961 SND_PCI_QUIRK(0x103c, 0x8ad2, "HP EliteBook 860 16 inch G9 Notebook PC", ALC245_FIXUP_CS35L41_SPI_2_HP_GPIO_LED), 9962 + SND_PCI_QUIRK(0x103c, 0x8ad8, "HP 800 G9", ALC245_FIXUP_CS35L41_SPI_2_HP_GPIO_LED), 9820 9963 SND_PCI_QUIRK(0x103c, 0x8b0f, "HP Elite mt645 G7 Mobile Thin Client U81", ALC236_FIXUP_HP_MUTE_LED_MICMUTE_VREF), 9821 9964 SND_PCI_QUIRK(0x103c, 0x8b2f, "HP 255 15.6 inch G10 Notebook PC", ALC236_FIXUP_HP_MUTE_LED_COEFBIT2), 9965 + SND_PCI_QUIRK(0x103c, 0x8b3a, "HP Envy 15", ALC287_FIXUP_CS35L41_I2C_2), 9822 9966 SND_PCI_QUIRK(0x103c, 0x8b3f, "HP mt440 Mobile Thin Client U91", ALC236_FIXUP_HP_GPIO_LED), 9823 9967 SND_PCI_QUIRK(0x103c, 0x8b42, "HP", ALC245_FIXUP_CS35L41_SPI_2_HP_GPIO_LED), 9824 9968 SND_PCI_QUIRK(0x103c, 0x8b43, "HP", ALC245_FIXUP_CS35L41_SPI_2_HP_GPIO_LED), ··· 9848 9988 SND_PCI_QUIRK(0x103c, 0x8b92, "HP", ALC245_FIXUP_CS35L41_SPI_2_HP_GPIO_LED), 9849 9989 SND_PCI_QUIRK(0x103c, 0x8b96, "HP", ALC236_FIXUP_HP_MUTE_LED_MICMUTE_VREF), 9850 9990 SND_PCI_QUIRK(0x103c, 0x8b97, "HP", ALC236_FIXUP_HP_MUTE_LED_MICMUTE_VREF), 9991 + SND_PCI_QUIRK(0x103c, 0x8bdd, "HP Envy 17", ALC287_FIXUP_CS35L41_I2C_2), 9992 + SND_PCI_QUIRK(0x103c, 0x8bde, "HP Envy 17", ALC287_FIXUP_CS35L41_I2C_2), 9993 + SND_PCI_QUIRK(0x103c, 0x8bdf, "HP Envy 15", ALC287_FIXUP_CS35L41_I2C_2), 9994 + SND_PCI_QUIRK(0x103c, 0x8be0, "HP Envy 15", ALC287_FIXUP_CS35L41_I2C_2), 9995 + SND_PCI_QUIRK(0x103c, 0x8be1, "HP Envy 15", ALC287_FIXUP_CS35L41_I2C_2), 9996 + SND_PCI_QUIRK(0x103c, 0x8be2, "HP Envy 15", ALC287_FIXUP_CS35L41_I2C_2), 9997 + SND_PCI_QUIRK(0x103c, 0x8be3, "HP Envy 15", ALC287_FIXUP_CS35L41_I2C_2), 9998 + SND_PCI_QUIRK(0x103c, 0x8be5, "HP Envy 16", ALC287_FIXUP_CS35L41_I2C_2), 9999 + SND_PCI_QUIRK(0x103c, 0x8be6, "HP Envy 16", ALC287_FIXUP_CS35L41_I2C_2), 10000 + SND_PCI_QUIRK(0x103c, 0x8be7, "HP Envy 17", ALC287_FIXUP_CS35L41_I2C_2), 10001 + SND_PCI_QUIRK(0x103c, 0x8be8, "HP Envy 17", ALC287_FIXUP_CS35L41_I2C_2), 10002 + SND_PCI_QUIRK(0x103c, 0x8be9, "HP Envy 15", ALC287_FIXUP_CS35L41_I2C_2), 9851 10003 SND_PCI_QUIRK(0x103c, 0x8bf0, "HP", ALC236_FIXUP_HP_GPIO_LED), 10004 + SND_PCI_QUIRK(0x103c, 0x8c15, "HP Spectre 14", ALC287_FIXUP_CS35L41_I2C_2), 10005 + SND_PCI_QUIRK(0x103c, 0x8c16, "HP Spectre 16", ALC287_FIXUP_CS35L41_I2C_2), 10006 + SND_PCI_QUIRK(0x103c, 0x8c17, "HP Spectre 16", ALC287_FIXUP_CS35L41_I2C_2), 9852 10007 SND_PCI_QUIRK(0x103c, 0x8c46, "HP EliteBook 830 G11", ALC245_FIXUP_CS35L41_SPI_2_HP_GPIO_LED), 9853 10008 SND_PCI_QUIRK(0x103c, 0x8c47, "HP EliteBook 840 G11", ALC245_FIXUP_CS35L41_SPI_2_HP_GPIO_LED), 9854 10009 SND_PCI_QUIRK(0x103c, 0x8c48, "HP EliteBook 860 G11", ALC245_FIXUP_CS35L41_SPI_2_HP_GPIO_LED), 9855 10010 SND_PCI_QUIRK(0x103c, 0x8c49, "HP Elite x360 830 2-in-1 G11", ALC245_FIXUP_CS35L41_SPI_2_HP_GPIO_LED), 10011 + SND_PCI_QUIRK(0x103c, 0x8c4f, "HP Envy 15", ALC287_FIXUP_CS35L41_I2C_2), 10012 + SND_PCI_QUIRK(0x103c, 0x8c50, "HP Envy 17", ALC287_FIXUP_CS35L41_I2C_2), 10013 + SND_PCI_QUIRK(0x103c, 0x8c51, "HP Envy 17", ALC287_FIXUP_CS35L41_I2C_2), 10014 + SND_PCI_QUIRK(0x103c, 0x8c52, "HP EliteBook 1040 G11", ALC245_FIXUP_CS35L56_SPI_4_HP_GPIO_LED), 10015 + SND_PCI_QUIRK(0x103c, 0x8c53, "HP Elite x360 1040 2-in-1 G11", ALC245_FIXUP_CS35L56_SPI_4_HP_GPIO_LED), 10016 + SND_PCI_QUIRK(0x103c, 0x8c66, "HP Envy 16", ALC287_FIXUP_CS35L41_I2C_2), 10017 + SND_PCI_QUIRK(0x103c, 0x8c67, "HP Envy 17", ALC287_FIXUP_CS35L41_I2C_2), 10018 + SND_PCI_QUIRK(0x103c, 0x8c68, "HP Envy 17", ALC287_FIXUP_CS35L41_I2C_2), 10019 + SND_PCI_QUIRK(0x103c, 0x8c6a, "HP Envy 16", ALC287_FIXUP_CS35L41_I2C_2), 9856 10020 SND_PCI_QUIRK(0x103c, 0x8c70, "HP EliteBook 835 G11", ALC287_FIXUP_CS35L41_I2C_2_HP_GPIO_LED), 9857 10021 SND_PCI_QUIRK(0x103c, 0x8c71, "HP EliteBook 845 G11", ALC287_FIXUP_CS35L41_I2C_2_HP_GPIO_LED), 9858 10022 SND_PCI_QUIRK(0x103c, 0x8c72, "HP EliteBook 865 G11", ALC287_FIXUP_CS35L41_I2C_2_HP_GPIO_LED), ··· 9890 10006 SND_PCI_QUIRK(0x103c, 0x8ca2, "HP ZBook Power", ALC236_FIXUP_HP_GPIO_LED), 9891 10007 SND_PCI_QUIRK(0x103c, 0x8ca4, "HP ZBook Fury", ALC245_FIXUP_CS35L41_SPI_2_HP_GPIO_LED), 9892 10008 SND_PCI_QUIRK(0x103c, 0x8ca7, "HP ZBook Fury", ALC245_FIXUP_CS35L41_SPI_2_HP_GPIO_LED), 10009 + SND_PCI_QUIRK(0x103c, 0x8cdd, "HP Spectre", ALC287_FIXUP_CS35L41_I2C_2), 10010 + SND_PCI_QUIRK(0x103c, 0x8cde, "HP Spectre", ALC287_FIXUP_CS35L41_I2C_2), 9893 10011 SND_PCI_QUIRK(0x103c, 0x8cf5, "HP ZBook Studio 16", ALC245_FIXUP_CS35L41_SPI_4_HP_GPIO_LED), 9894 10012 SND_PCI_QUIRK(0x1043, 0x103e, "ASUS X540SA", ALC256_FIXUP_ASUS_MIC), 9895 10013 SND_PCI_QUIRK(0x1043, 0x103f, "ASUS TX300", ALC282_FIXUP_ASUS_TX300), ··· 10013 10127 SND_PCI_QUIRK(0x10ec, 0x1252, "Intel Reference board", ALC295_FIXUP_CHROME_BOOK), 10014 10128 SND_PCI_QUIRK(0x10ec, 0x1254, "Intel Reference board", ALC295_FIXUP_CHROME_BOOK), 10015 10129 SND_PCI_QUIRK(0x10ec, 0x12cc, "Intel Reference board", ALC295_FIXUP_CHROME_BOOK), 10130 + SND_PCI_QUIRK(0x10ec, 0x12f6, "Intel Reference board", ALC295_FIXUP_CHROME_BOOK), 10016 10131 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-SZ6", ALC269_FIXUP_HEADSET_MODE), 10017 10132 SND_PCI_QUIRK(0x144d, 0xc109, "Samsung Ativ book 9 (NP900X3G)", ALC269_FIXUP_INV_DMIC), 10018 10133 SND_PCI_QUIRK(0x144d, 0xc169, "Samsung Notebook 9 Pen (NP930SBE-K01US)", ALC298_FIXUP_SAMSUNG_AMP), ··· 12561 12674 12562 12675 MODULE_LICENSE("GPL"); 12563 12676 MODULE_DESCRIPTION("Realtek HD-audio codec"); 12677 + MODULE_IMPORT_NS(SND_HDA_SCODEC_COMPONENT); 12564 12678 12565 12679 static struct hda_codec_driver realtek_driver = { 12566 12680 .id = snd_hda_id_realtek,
+2 -7
sound/pci/intel8x0.c
··· 2555 2555 free_irq(chip->irq, chip); 2556 2556 } 2557 2557 2558 - #ifdef CONFIG_PM_SLEEP 2559 2558 /* 2560 2559 * power management 2561 2560 */ ··· 2627 2628 return 0; 2628 2629 } 2629 2630 2630 - static SIMPLE_DEV_PM_OPS(intel8x0_pm, intel8x0_suspend, intel8x0_resume); 2631 - #define INTEL8X0_PM_OPS &intel8x0_pm 2632 - #else 2633 - #define INTEL8X0_PM_OPS NULL 2634 - #endif /* CONFIG_PM_SLEEP */ 2631 + static DEFINE_SIMPLE_DEV_PM_OPS(intel8x0_pm, intel8x0_suspend, intel8x0_resume); 2635 2632 2636 2633 #define INTEL8X0_TESTBUF_SIZE 32768 /* enough large for one shot */ 2637 2634 ··· 3195 3200 .id_table = snd_intel8x0_ids, 3196 3201 .probe = snd_intel8x0_probe, 3197 3202 .driver = { 3198 - .pm = INTEL8X0_PM_OPS, 3203 + .pm = &intel8x0_pm, 3199 3204 }, 3200 3205 }; 3201 3206
+2 -7
sound/pci/intel8x0m.c
··· 965 965 free_irq(chip->irq, chip); 966 966 } 967 967 968 - #ifdef CONFIG_PM_SLEEP 969 968 /* 970 969 * power management 971 970 */ ··· 1005 1006 return 0; 1006 1007 } 1007 1008 1008 - static SIMPLE_DEV_PM_OPS(intel8x0m_pm, intel8x0m_suspend, intel8x0m_resume); 1009 - #define INTEL8X0M_PM_OPS &intel8x0m_pm 1010 - #else 1011 - #define INTEL8X0M_PM_OPS NULL 1012 - #endif /* CONFIG_PM_SLEEP */ 1009 + static DEFINE_SIMPLE_DEV_PM_OPS(intel8x0m_pm, intel8x0m_suspend, intel8x0m_resume); 1013 1010 1014 1011 static void snd_intel8x0m_proc_read(struct snd_info_entry * entry, 1015 1012 struct snd_info_buffer *buffer) ··· 1231 1236 .id_table = snd_intel8x0m_ids, 1232 1237 .probe = snd_intel8x0m_probe, 1233 1238 .driver = { 1234 - .pm = INTEL8X0M_PM_OPS, 1239 + .pm = &intel8x0m_pm, 1235 1240 }, 1236 1241 }; 1237 1242
+10 -19
sound/pci/maestro3.c
··· 769 769 770 770 unsigned int in_suspend; 771 771 772 - #ifdef CONFIG_PM_SLEEP 773 772 u16 *suspend_mem; 774 - #endif 775 773 776 774 const struct firmware *assp_kernel_image; 777 775 const struct firmware *assp_minisrc_image; ··· 2352 2354 outw(0, chip->iobase + HOST_INT_CTRL); /* disable ints */ 2353 2355 } 2354 2356 2355 - #ifdef CONFIG_PM_SLEEP 2356 2357 vfree(chip->suspend_mem); 2357 - #endif 2358 2358 release_firmware(chip->assp_kernel_image); 2359 2359 release_firmware(chip->assp_minisrc_image); 2360 2360 } ··· 2361 2365 /* 2362 2366 * APM support 2363 2367 */ 2364 - #ifdef CONFIG_PM_SLEEP 2365 2368 static int m3_suspend(struct device *dev) 2366 2369 { 2367 2370 struct snd_card *card = dev_get_drvdata(dev); ··· 2434 2439 return 0; 2435 2440 } 2436 2441 2437 - static SIMPLE_DEV_PM_OPS(m3_pm, m3_suspend, m3_resume); 2438 - #define M3_PM_OPS &m3_pm 2439 - #else 2440 - #define M3_PM_OPS NULL 2441 - #endif /* CONFIG_PM_SLEEP */ 2442 + static DEFINE_SIMPLE_DEV_PM_OPS(m3_pm, m3_suspend, m3_resume); 2442 2443 2443 2444 #ifdef CONFIG_SND_MAESTRO3_INPUT 2444 2445 static int snd_m3_input_register(struct snd_m3 *chip) ··· 2578 2587 chip->irq = pci->irq; 2579 2588 card->sync_irq = chip->irq; 2580 2589 2581 - #ifdef CONFIG_PM_SLEEP 2582 - chip->suspend_mem = 2583 - vmalloc(array_size(sizeof(u16), 2584 - REV_B_CODE_MEMORY_LENGTH + 2585 - REV_B_DATA_MEMORY_LENGTH)); 2586 - if (chip->suspend_mem == NULL) 2587 - dev_warn(card->dev, "can't allocate apm buffer\n"); 2588 - #endif 2590 + if (IS_ENABLED(CONFIG_PM_SLEEP)) { 2591 + chip->suspend_mem = 2592 + vmalloc(array_size(sizeof(u16), 2593 + REV_B_CODE_MEMORY_LENGTH + 2594 + REV_B_DATA_MEMORY_LENGTH)); 2595 + if (!chip->suspend_mem) 2596 + dev_warn(card->dev, "can't allocate apm buffer\n"); 2597 + } 2589 2598 2590 2599 err = snd_m3_mixer(chip); 2591 2600 if (err < 0) ··· 2697 2706 .id_table = snd_m3_ids, 2698 2707 .probe = snd_m3_probe, 2699 2708 .driver = { 2700 - .pm = M3_PM_OPS, 2709 + .pm = &m3_pm, 2701 2710 }, 2702 2711 }; 2703 2712
+2 -7
sound/pci/nm256/nm256.c
··· 1356 1356 return 0; 1357 1357 } 1358 1358 1359 - #ifdef CONFIG_PM_SLEEP 1360 1359 /* 1361 1360 * APM event handler, so the card is properly reinitialized after a power 1362 1361 * event. ··· 1399 1400 return 0; 1400 1401 } 1401 1402 1402 - static SIMPLE_DEV_PM_OPS(nm256_pm, nm256_suspend, nm256_resume); 1403 - #define NM256_PM_OPS &nm256_pm 1404 - #else 1405 - #define NM256_PM_OPS NULL 1406 - #endif /* CONFIG_PM_SLEEP */ 1403 + static DEFINE_SIMPLE_DEV_PM_OPS(nm256_pm, nm256_suspend, nm256_resume); 1407 1404 1408 1405 static void snd_nm256_free(struct snd_card *card) 1409 1406 { ··· 1655 1660 .id_table = snd_nm256_ids, 1656 1661 .probe = snd_nm256_probe, 1657 1662 .driver = { 1658 - .pm = NM256_PM_OPS, 1663 + .pm = &nm256_pm, 1659 1664 }, 1660 1665 }; 1661 1666
+2 -9
sound/pci/riptide/riptide.c
··· 448 448 449 449 unsigned long received_irqs; 450 450 unsigned long handled_irqs; 451 - #ifdef CONFIG_PM_SLEEP 452 451 int in_suspend; 453 - #endif 454 452 }; 455 453 456 454 struct sgd { /* scatter gather desriptor */ ··· 1140 1142 return IRQ_HANDLED; 1141 1143 } 1142 1144 1143 - #ifdef CONFIG_PM_SLEEP 1144 1145 static int riptide_suspend(struct device *dev) 1145 1146 { 1146 1147 struct snd_card *card = dev_get_drvdata(dev); ··· 1163 1166 return 0; 1164 1167 } 1165 1168 1166 - static SIMPLE_DEV_PM_OPS(riptide_pm, riptide_suspend, riptide_resume); 1167 - #define RIPTIDE_PM_OPS &riptide_pm 1168 - #else 1169 - #define RIPTIDE_PM_OPS NULL 1170 - #endif /* CONFIG_PM_SLEEP */ 1169 + static DEFINE_SIMPLE_DEV_PM_OPS(riptide_pm, riptide_suspend, riptide_resume); 1171 1170 1172 1171 static int try_to_load_firmware(struct cmdif *cif, struct snd_riptide *chip) 1173 1172 { ··· 2128 2135 .id_table = snd_riptide_ids, 2129 2136 .probe = snd_card_riptide_probe, 2130 2137 .driver = { 2131 - .pm = RIPTIDE_PM_OPS, 2138 + .pm = &riptide_pm, 2132 2139 }, 2133 2140 }; 2134 2141
+10 -20
sound/pci/rme96.c
··· 220 220 221 221 u8 rev; /* card revision number */ 222 222 223 - #ifdef CONFIG_PM_SLEEP 224 223 u32 playback_pointer; 225 224 u32 capture_pointer; 226 225 void *playback_suspend_buffer; 227 226 void *capture_suspend_buffer; 228 - #endif 229 227 230 228 struct snd_pcm_substream *playback_substream; 231 229 struct snd_pcm_substream *capture_substream; ··· 1541 1543 rme96->areg &= ~RME96_AR_DAC_EN; 1542 1544 writel(rme96->areg, rme96->iobase + RME96_IO_ADDITIONAL_REG); 1543 1545 } 1544 - #ifdef CONFIG_PM_SLEEP 1545 1546 vfree(rme96->playback_suspend_buffer); 1546 1547 vfree(rme96->capture_suspend_buffer); 1547 - #endif 1548 1548 } 1549 1549 1550 1550 static void ··· 2325 2329 * Card initialisation 2326 2330 */ 2327 2331 2328 - #ifdef CONFIG_PM_SLEEP 2329 - 2330 2332 static int rme96_suspend(struct device *dev) 2331 2333 { 2332 2334 struct snd_card *card = dev_get_drvdata(dev); ··· 2386 2392 return 0; 2387 2393 } 2388 2394 2389 - static SIMPLE_DEV_PM_OPS(rme96_pm, rme96_suspend, rme96_resume); 2390 - #define RME96_PM_OPS &rme96_pm 2391 - #else 2392 - #define RME96_PM_OPS NULL 2393 - #endif /* CONFIG_PM_SLEEP */ 2395 + static DEFINE_SIMPLE_DEV_PM_OPS(rme96_pm, rme96_suspend, rme96_resume); 2394 2396 2395 2397 static void snd_rme96_card_free(struct snd_card *card) 2396 2398 { ··· 2422 2432 if (err) 2423 2433 return err; 2424 2434 2425 - #ifdef CONFIG_PM_SLEEP 2426 - rme96->playback_suspend_buffer = vmalloc(RME96_BUFFER_SIZE); 2427 - if (!rme96->playback_suspend_buffer) 2428 - return -ENOMEM; 2429 - rme96->capture_suspend_buffer = vmalloc(RME96_BUFFER_SIZE); 2430 - if (!rme96->capture_suspend_buffer) 2431 - return -ENOMEM; 2432 - #endif 2435 + if (IS_ENABLED(CONFIG_PM_SLEEP)) { 2436 + rme96->playback_suspend_buffer = vmalloc(RME96_BUFFER_SIZE); 2437 + if (!rme96->playback_suspend_buffer) 2438 + return -ENOMEM; 2439 + rme96->capture_suspend_buffer = vmalloc(RME96_BUFFER_SIZE); 2440 + if (!rme96->capture_suspend_buffer) 2441 + return -ENOMEM; 2442 + } 2433 2443 2434 2444 strcpy(card->driver, "Digi96"); 2435 2445 switch (rme96->pci->device) { ··· 2473 2483 .id_table = snd_rme96_ids, 2474 2484 .probe = snd_rme96_probe, 2475 2485 .driver = { 2476 - .pm = RME96_PM_OPS, 2486 + .pm = &rme96_pm, 2477 2487 }, 2478 2488 }; 2479 2489
+2 -11
sound/pci/sis7019.c
··· 90 90 * we're not doing power management, we still need to allocate a page 91 91 * for the silence buffer. 92 92 */ 93 - #ifdef CONFIG_PM_SLEEP 94 93 #define SIS_SUSPEND_PAGES 4 95 - #else 96 - #define SIS_SUSPEND_PAGES 1 97 - #endif 98 94 99 95 struct sis7019 { 100 96 unsigned long ioport; ··· 1148 1152 return 0; 1149 1153 } 1150 1154 1151 - #ifdef CONFIG_PM_SLEEP 1152 1155 static int sis_suspend(struct device *dev) 1153 1156 { 1154 1157 struct snd_card *card = dev_get_drvdata(dev); ··· 1226 1231 return -EIO; 1227 1232 } 1228 1233 1229 - static SIMPLE_DEV_PM_OPS(sis_pm, sis_suspend, sis_resume); 1230 - #define SIS_PM_OPS &sis_pm 1231 - #else 1232 - #define SIS_PM_OPS NULL 1233 - #endif /* CONFIG_PM_SLEEP */ 1234 + static DEFINE_SIMPLE_DEV_PM_OPS(sis_pm, sis_suspend, sis_resume); 1234 1235 1235 1236 static int sis_alloc_suspend(struct sis7019 *sis) 1236 1237 { ··· 1388 1397 .id_table = snd_sis7019_ids, 1389 1398 .probe = snd_sis7019_probe, 1390 1399 .driver = { 1391 - .pm = SIS_PM_OPS, 1400 + .pm = &sis_pm, 1392 1401 }, 1393 1402 }; 1394 1403
+2 -13
sound/pci/via82xx.c
··· 347 347 348 348 unsigned char old_legacy; 349 349 unsigned char old_legacy_cfg; 350 - #ifdef CONFIG_PM_SLEEP 351 350 unsigned char legacy_saved; 352 351 unsigned char legacy_cfg_saved; 353 352 unsigned char spdif_ctrl_saved; 354 353 unsigned char capture_src_saved[2]; 355 354 unsigned int mpu_port_saved; 356 - #endif 357 355 358 356 unsigned char playback_volume[4][2]; /* for VIA8233/C/8235; default = 0 */ 359 357 unsigned char playback_volume_c[2]; /* for VIA8233/C/8235; default = 0 */ ··· 2029 2031 if (mpu_port >= 0x200) { /* force MIDI */ 2030 2032 mpu_port &= 0xfffc; 2031 2033 pci_write_config_dword(chip->pci, 0x18, mpu_port | 0x01); 2032 - #ifdef CONFIG_PM_SLEEP 2033 2034 chip->mpu_port_saved = mpu_port; 2034 - #endif 2035 2035 } else { 2036 2036 mpu_port = pci_resource_start(chip->pci, 2); 2037 2037 } ··· 2081 2085 2082 2086 snd_via686_create_gameport(chip, &legacy); 2083 2087 2084 - #ifdef CONFIG_PM_SLEEP 2085 2088 chip->legacy_saved = legacy; 2086 2089 chip->legacy_cfg_saved = legacy_cfg; 2087 - #endif 2088 2090 2089 2091 return 0; 2090 2092 } ··· 2228 2234 return 0; 2229 2235 } 2230 2236 2231 - #ifdef CONFIG_PM_SLEEP 2232 2237 /* 2233 2238 * power management 2234 2239 */ ··· 2280 2287 return 0; 2281 2288 } 2282 2289 2283 - static SIMPLE_DEV_PM_OPS(snd_via82xx_pm, snd_via82xx_suspend, snd_via82xx_resume); 2284 - #define SND_VIA82XX_PM_OPS &snd_via82xx_pm 2285 - #else 2286 - #define SND_VIA82XX_PM_OPS NULL 2287 - #endif /* CONFIG_PM_SLEEP */ 2290 + static DEFINE_SIMPLE_DEV_PM_OPS(snd_via82xx_pm, snd_via82xx_suspend, snd_via82xx_resume); 2288 2291 2289 2292 static void snd_via82xx_free(struct snd_card *card) 2290 2293 { ··· 2565 2576 .id_table = snd_via82xx_ids, 2566 2577 .probe = snd_via82xx_probe, 2567 2578 .driver = { 2568 - .pm = SND_VIA82XX_PM_OPS, 2579 + .pm = &snd_via82xx_pm, 2569 2580 }, 2570 2581 }; 2571 2582
+2 -7
sound/pci/via82xx_modem.c
··· 1008 1008 return 0; 1009 1009 } 1010 1010 1011 - #ifdef CONFIG_PM_SLEEP 1012 1011 /* 1013 1012 * power management 1014 1013 */ ··· 1041 1042 return 0; 1042 1043 } 1043 1044 1044 - static SIMPLE_DEV_PM_OPS(snd_via82xx_pm, snd_via82xx_suspend, snd_via82xx_resume); 1045 - #define SND_VIA82XX_PM_OPS &snd_via82xx_pm 1046 - #else 1047 - #define SND_VIA82XX_PM_OPS NULL 1048 - #endif /* CONFIG_PM_SLEEP */ 1045 + static DEFINE_SIMPLE_DEV_PM_OPS(snd_via82xx_pm, snd_via82xx_suspend, snd_via82xx_resume); 1049 1046 1050 1047 static void snd_via82xx_free(struct snd_card *card) 1051 1048 { ··· 1163 1168 .id_table = snd_via82xx_modem_ids, 1164 1169 .probe = snd_via82xx_probe, 1165 1170 .driver = { 1166 - .pm = SND_VIA82XX_PM_OPS, 1171 + .pm = &snd_via82xx_pm, 1167 1172 }, 1168 1173 }; 1169 1174
+2 -1
sound/soc/codecs/cs35l56-sdw.c
··· 366 366 dev_dbg(cs35l56->base.dev, "%s: sclk=%u c=%u r=%u\n", 367 367 __func__, sclk, params->col, params->row); 368 368 369 - if (cs35l56->base.rev < 0xb0) 369 + if ((cs35l56->base.type == 0x56) && (cs35l56->base.rev < 0xb0)) 370 370 return cs35l56_a1_kick_divider(cs35l56, peripheral); 371 371 372 372 return 0; ··· 543 543 544 544 static const struct sdw_device_id cs35l56_sdw_id[] = { 545 545 SDW_SLAVE_ENTRY(0x01FA, 0x3556, 0), 546 + SDW_SLAVE_ENTRY(0x01FA, 0x3557, 0), 546 547 {}, 547 548 }; 548 549 MODULE_DEVICE_TABLE(sdw, cs35l56_sdw_id);
+6 -2
sound/soc/codecs/cs35l56-shared.c
··· 693 693 devid &= CS35L56_DEVID_MASK; 694 694 695 695 switch (devid) { 696 + case 0x35A54: 696 697 case 0x35A56: 698 + case 0x35A57: 697 699 break; 698 700 default: 699 701 dev_err(cs35l56_base->dev, "Unknown device %x\n", devid); 700 702 return ret; 701 703 } 704 + 705 + cs35l56_base->type = devid & 0xFF; 702 706 703 707 ret = regmap_read(cs35l56_base->regmap, CS35L56_DSP_RESTRICT_STS1, &secured); 704 708 if (ret) { ··· 724 720 if (ret) 725 721 return ret; 726 722 727 - dev_info(cs35l56_base->dev, "Cirrus Logic CS35L56%s Rev %02X OTP%d fw:%d.%d.%d (patched=%u)\n", 728 - cs35l56_base->secured ? "s" : "", cs35l56_base->rev, otpid, 723 + dev_info(cs35l56_base->dev, "Cirrus Logic CS35L%02X%s Rev %02X OTP%d fw:%d.%d.%d (patched=%u)\n", 724 + cs35l56_base->type, cs35l56_base->secured ? "s" : "", cs35l56_base->rev, otpid, 729 725 fw_ver >> 16, (fw_ver >> 8) & 0xff, fw_ver & 0xff, !fw_missing); 730 726 731 727 /* Wake source and *_BLOCKED interrupts default to unmasked, so mask them */
+13 -1
sound/soc/codecs/cs35l56.c
··· 972 972 return -ENODEV; 973 973 } 974 974 975 + cs35l56->dsp.part = kasprintf(GFP_KERNEL, "cs35l%02x", cs35l56->base.type); 976 + if (!cs35l56->dsp.part) 977 + return -ENOMEM; 978 + 975 979 cs35l56->component = component; 976 980 wm_adsp2_component_probe(&cs35l56->dsp, component); 977 981 ··· 1005 1001 wm_adsp_power_down(&cs35l56->dsp); 1006 1002 1007 1003 wm_adsp2_component_remove(&cs35l56->dsp, component); 1004 + 1005 + kfree(cs35l56->dsp.part); 1006 + cs35l56->dsp.part = NULL; 1008 1007 1009 1008 kfree(cs35l56->dsp.fwf_name); 1010 1009 cs35l56->dsp.fwf_name = NULL; ··· 1228 1221 1229 1222 dsp = &cs35l56->dsp; 1230 1223 cs35l56_init_cs_dsp(&cs35l56->base, &dsp->cs_dsp); 1231 - dsp->part = "cs35l56"; 1224 + 1225 + /* 1226 + * dsp->part is filled in later as it is based on the DEVID. In a 1227 + * SoundWire system that cannot be read until enumeration has occurred 1228 + * and the device has attached. 1229 + */ 1232 1230 dsp->fw = 12; 1233 1231 dsp->wmfw_optional = true; 1234 1232
+10 -5
sound/soc/codecs/hda.c
··· 198 198 ret = snd_hda_codec_device_new(codec->bus, component->card->snd_card, hdev->addr, codec, 199 199 false); 200 200 if (ret < 0) { 201 - dev_err(&hdev->dev, "create hda codec failed: %d\n", ret); 201 + dev_err(&hdev->dev, "codec create failed: %d\n", ret); 202 202 goto device_new_err; 203 203 } 204 204 205 205 ret = snd_hda_codec_set_name(codec, codec->preset->name); 206 206 if (ret < 0) { 207 - dev_err(&hdev->dev, "name failed %s\n", codec->preset->name); 207 + dev_err(&hdev->dev, "set name: %s failed: %d\n", codec->preset->name, ret); 208 208 goto err; 209 209 } 210 210 211 211 ret = snd_hdac_regmap_init(&codec->core); 212 212 if (ret < 0) { 213 - dev_err(&hdev->dev, "regmap init failed\n"); 213 + dev_err(&hdev->dev, "regmap init failed: %d\n", ret); 214 214 goto err; 215 215 } 216 216 ··· 223 223 224 224 ret = patch(codec); 225 225 if (ret < 0) { 226 - dev_err(&hdev->dev, "patch failed %d\n", ret); 226 + dev_err(&hdev->dev, "codec init failed: %d\n", ret); 227 227 goto err; 228 228 } 229 229 230 230 ret = snd_hda_codec_parse_pcms(codec); 231 231 if (ret < 0) { 232 - dev_err(&hdev->dev, "unable to map pcms to dai %d\n", ret); 232 + dev_err(&hdev->dev, "unable to map pcms to dai: %d\n", ret); 233 233 goto parse_pcms_err; 234 234 } 235 235 ··· 349 349 { 350 350 struct hda_codec *codec = dev_to_hda_codec(&hdev->dev); 351 351 struct snd_soc_component_driver *comp_drv; 352 + 353 + if (hda_codec_is_display(codec) && !hdev->bus->audio_component) { 354 + dev_dbg(&hdev->dev, "no i915, skip registration for 0x%08x\n", hdev->vendor_id); 355 + return -ENODEV; 356 + } 352 357 353 358 comp_drv = devm_kzalloc(&hdev->dev, sizeof(*comp_drv), GFP_KERNEL); 354 359 if (!comp_drv)
+5 -4
sound/soc/intel/avs/core.c
··· 144 144 /* configure effectively creates new ASoC component */ 145 145 ret = snd_hda_codec_configure(codec); 146 146 if (ret < 0) { 147 - dev_err(bus->dev, "failed to config codec %d\n", ret); 147 + dev_warn(bus->dev, "failed to config codec #%d: %d\n", addr, ret); 148 148 return ret; 149 149 } 150 150 ··· 153 153 154 154 static void avs_hdac_bus_probe_codecs(struct hdac_bus *bus) 155 155 { 156 - int c; 156 + int ret, c; 157 157 158 158 /* First try to probe all given codec slots */ 159 159 for (c = 0; c < HDA_MAX_CODECS; c++) { 160 160 if (!(bus->codec_mask & BIT(c))) 161 161 continue; 162 162 163 - if (!probe_codec(bus, c)) 164 - /* success, continue probing */ 163 + ret = probe_codec(bus, c); 164 + /* Ignore codecs with no supporting driver. */ 165 + if (!ret || ret == -ENODEV) 165 166 continue; 166 167 167 168 /*
+1 -5
sound/soc/pxa/pxa2xx-ac97.c
··· 271 271 pxa2xx_ac97_hw_remove(pdev); 272 272 } 273 273 274 - #ifdef CONFIG_PM_SLEEP 275 274 static int pxa2xx_ac97_dev_suspend(struct device *dev) 276 275 { 277 276 return pxa2xx_ac97_hw_suspend(); ··· 281 282 return pxa2xx_ac97_hw_resume(); 282 283 } 283 284 284 - static SIMPLE_DEV_PM_OPS(pxa2xx_ac97_pm_ops, 285 + static DEFINE_SIMPLE_DEV_PM_OPS(pxa2xx_ac97_pm_ops, 285 286 pxa2xx_ac97_dev_suspend, pxa2xx_ac97_dev_resume); 286 - #endif 287 287 288 288 static struct platform_driver pxa2xx_ac97_driver = { 289 289 .probe = pxa2xx_ac97_dev_probe, 290 290 .remove_new = pxa2xx_ac97_dev_remove, 291 291 .driver = { 292 292 .name = "pxa2xx-ac97", 293 - #ifdef CONFIG_PM_SLEEP 294 293 .pm = &pxa2xx_ac97_pm_ops, 295 - #endif 296 294 .of_match_table = of_match_ptr(pxa2xx_ac97_dt_ids), 297 295 }, 298 296 };
+2 -9
sound/spi/at73c213.c
··· 1076 1076 snd_card_free(card); 1077 1077 } 1078 1078 1079 - #ifdef CONFIG_PM_SLEEP 1080 - 1081 1079 static int snd_at73c213_suspend(struct device *dev) 1082 1080 { 1083 1081 struct snd_card *card = dev_get_drvdata(dev); ··· 1107 1109 return 0; 1108 1110 } 1109 1111 1110 - static SIMPLE_DEV_PM_OPS(at73c213_pm_ops, snd_at73c213_suspend, 1112 + static DEFINE_SIMPLE_DEV_PM_OPS(at73c213_pm_ops, snd_at73c213_suspend, 1111 1113 snd_at73c213_resume); 1112 - #define AT73C213_PM_OPS (&at73c213_pm_ops) 1113 - 1114 - #else 1115 - #define AT73C213_PM_OPS NULL 1116 - #endif 1117 1114 1118 1115 static struct spi_driver at73c213_driver = { 1119 1116 .driver = { 1120 1117 .name = "at73c213", 1121 - .pm = AT73C213_PM_OPS, 1118 + .pm = &at73c213_pm_ops, 1122 1119 }, 1123 1120 .probe = snd_at73c213_probe, 1124 1121 .remove = snd_at73c213_remove,
+2 -2
sound/synth/emux/emux.c
··· 85 85 return -EINVAL; 86 86 87 87 emu->card = card; 88 - emu->name = kstrdup(name, GFP_KERNEL); 88 + emu->name = kstrdup_const(name, GFP_KERNEL); 89 89 emu->voices = kcalloc(emu->max_voices, sizeof(struct snd_emux_voice), 90 90 GFP_KERNEL); 91 91 if (emu->name == NULL || emu->voices == NULL) ··· 140 140 snd_emux_delete_hwdep(emu); 141 141 snd_sf_free(emu->sflist); 142 142 kfree(emu->voices); 143 - kfree(emu->name); 143 + kfree_const(emu->name); 144 144 kfree(emu); 145 145 return 0; 146 146 }
+35 -14
sound/usb/mixer.c
··· 1652 1652 return NULL; 1653 1653 } 1654 1654 1655 + static int feature_unit_mutevol_ctl_name(struct usb_mixer_interface *mixer, 1656 + struct snd_kcontrol *kctl, 1657 + struct usb_audio_term *iterm, 1658 + struct usb_audio_term *oterm) 1659 + { 1660 + struct usb_audio_term *aterm, *bterm; 1661 + bool output_first; 1662 + int len = 0; 1663 + 1664 + /* 1665 + * If the input terminal is USB Streaming, we try getting the name of 1666 + * the output terminal first in hopes of getting something more 1667 + * descriptive than "PCM". 1668 + */ 1669 + output_first = iterm && !(iterm->type >> 16) && (iterm->type & 0xff00) == 0x0100; 1670 + 1671 + aterm = output_first ? oterm : iterm; 1672 + bterm = output_first ? iterm : oterm; 1673 + 1674 + if (aterm) 1675 + len = get_term_name(mixer->chip, aterm, kctl->id.name, 1676 + sizeof(kctl->id.name), 1); 1677 + if (!len && bterm) 1678 + len = get_term_name(mixer->chip, bterm, kctl->id.name, 1679 + sizeof(kctl->id.name), 1); 1680 + return len; 1681 + } 1682 + 1655 1683 static void __build_feature_ctl(struct usb_mixer_interface *mixer, 1656 1684 const struct usbmix_name_map *imap, 1657 1685 unsigned int ctl_mask, int control, ··· 1761 1733 case UAC_FU_MUTE: 1762 1734 case UAC_FU_VOLUME: 1763 1735 /* 1764 - * determine the control name. the rule is: 1765 - * - if a name id is given in descriptor, use it. 1766 - * - if the connected input can be determined, then use the name 1767 - * of terminal type. 1768 - * - if the connected output can be determined, use it. 1769 - * - otherwise, anonymous name. 1736 + * Determine the control name: 1737 + * - If a name id is given in descriptor, use it. 1738 + * - If input and output terminals are present, try to derive 1739 + * the name from either of these. 1740 + * - Otherwise, make up a name using the feature unit ID. 1770 1741 */ 1771 1742 if (!len) { 1772 - if (iterm) 1773 - len = get_term_name(mixer->chip, iterm, 1774 - kctl->id.name, 1775 - sizeof(kctl->id.name), 1); 1776 - if (!len && oterm) 1777 - len = get_term_name(mixer->chip, oterm, 1778 - kctl->id.name, 1779 - sizeof(kctl->id.name), 1); 1743 + len = feature_unit_mutevol_ctl_name(mixer, kctl, iterm, 1744 + oterm); 1780 1745 if (!len) 1781 1746 snprintf(kctl->id.name, sizeof(kctl->id.name), 1782 1747 "Feature %d", unitid);
+1
sound/virtio/Makefile
··· 7 7 virtio_chmap.o \ 8 8 virtio_ctl_msg.o \ 9 9 virtio_jack.o \ 10 + virtio_kctl.o \ 10 11 virtio_pcm.o \ 11 12 virtio_pcm_msg.o \ 12 13 virtio_pcm_ops.o
+21
sound/virtio/virtio_card.c
··· 64 64 case VIRTIO_SND_EVT_PCM_XRUN: 65 65 virtsnd_pcm_event(snd, event); 66 66 break; 67 + case VIRTIO_SND_EVT_CTL_NOTIFY: 68 + virtsnd_kctl_event(snd, event); 69 + break; 67 70 } 68 71 } 69 72 ··· 236 233 if (rc) 237 234 return rc; 238 235 236 + if (virtio_has_feature(vdev, VIRTIO_SND_F_CTLS)) { 237 + rc = virtsnd_kctl_parse_cfg(snd); 238 + if (rc) 239 + return rc; 240 + } 241 + 239 242 if (snd->njacks) { 240 243 rc = virtsnd_jack_build_devs(snd); 241 244 if (rc) ··· 256 247 257 248 if (snd->nchmaps) { 258 249 rc = virtsnd_chmap_build_devs(snd); 250 + if (rc) 251 + return rc; 252 + } 253 + 254 + if (snd->nkctls) { 255 + rc = virtsnd_kctl_build_devs(snd); 259 256 if (rc) 260 257 return rc; 261 258 } ··· 432 417 { 0 }, 433 418 }; 434 419 420 + static unsigned int features[] = { 421 + VIRTIO_SND_F_CTLS 422 + }; 423 + 435 424 static struct virtio_driver virtsnd_driver = { 436 425 .driver.name = KBUILD_MODNAME, 437 426 .driver.owner = THIS_MODULE, 438 427 .id_table = id_table, 428 + .feature_table = features, 429 + .feature_table_size = ARRAY_SIZE(features), 439 430 .validate = virtsnd_validate, 440 431 .probe = virtsnd_probe, 441 432 .remove = virtsnd_remove,
+22
sound/virtio/virtio_card.h
··· 32 32 }; 33 33 34 34 /** 35 + * struct virtio_kctl - VirtIO control element. 36 + * @kctl: ALSA control element. 37 + * @items: Items for the ENUMERATED element type. 38 + */ 39 + struct virtio_kctl { 40 + struct snd_kcontrol *kctl; 41 + struct virtio_snd_ctl_enum_item *items; 42 + }; 43 + 44 + /** 35 45 * struct virtio_snd - VirtIO sound card device. 36 46 * @vdev: Underlying virtio device. 37 47 * @queues: Virtqueue wrappers. ··· 55 45 * @nsubstreams: Number of PCM substreams. 56 46 * @chmaps: VirtIO channel maps. 57 47 * @nchmaps: Number of channel maps. 48 + * @kctl_infos: VirtIO control element information. 49 + * @kctls: VirtIO control elements. 50 + * @nkctls: Number of control elements. 58 51 */ 59 52 struct virtio_snd { 60 53 struct virtio_device *vdev; ··· 72 59 u32 nsubstreams; 73 60 struct virtio_snd_chmap_info *chmaps; 74 61 u32 nchmaps; 62 + struct virtio_snd_ctl_info *kctl_infos; 63 + struct virtio_kctl *kctls; 64 + u32 nkctls; 75 65 }; 76 66 77 67 /* Message completion timeout in milliseconds (module parameter). */ ··· 123 107 int virtsnd_chmap_parse_cfg(struct virtio_snd *snd); 124 108 125 109 int virtsnd_chmap_build_devs(struct virtio_snd *snd); 110 + 111 + int virtsnd_kctl_parse_cfg(struct virtio_snd *snd); 112 + 113 + int virtsnd_kctl_build_devs(struct virtio_snd *snd); 114 + 115 + void virtsnd_kctl_event(struct virtio_snd *snd, struct virtio_snd_event *event); 126 116 127 117 #endif /* VIRTIO_SND_CARD_H */
+477
sound/virtio/virtio_kctl.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + /* 3 + * virtio-snd: Virtio sound device 4 + * Copyright (C) 2022 OpenSynergy GmbH 5 + */ 6 + #include <sound/control.h> 7 + #include <linux/virtio_config.h> 8 + 9 + #include "virtio_card.h" 10 + 11 + /* Map for converting VirtIO types to ALSA types. */ 12 + static const snd_ctl_elem_type_t g_v2a_type_map[] = { 13 + [VIRTIO_SND_CTL_TYPE_BOOLEAN] = SNDRV_CTL_ELEM_TYPE_BOOLEAN, 14 + [VIRTIO_SND_CTL_TYPE_INTEGER] = SNDRV_CTL_ELEM_TYPE_INTEGER, 15 + [VIRTIO_SND_CTL_TYPE_INTEGER64] = SNDRV_CTL_ELEM_TYPE_INTEGER64, 16 + [VIRTIO_SND_CTL_TYPE_ENUMERATED] = SNDRV_CTL_ELEM_TYPE_ENUMERATED, 17 + [VIRTIO_SND_CTL_TYPE_BYTES] = SNDRV_CTL_ELEM_TYPE_BYTES, 18 + [VIRTIO_SND_CTL_TYPE_IEC958] = SNDRV_CTL_ELEM_TYPE_IEC958 19 + }; 20 + 21 + /* Map for converting VirtIO access rights to ALSA access rights. */ 22 + static const unsigned int g_v2a_access_map[] = { 23 + [VIRTIO_SND_CTL_ACCESS_READ] = SNDRV_CTL_ELEM_ACCESS_READ, 24 + [VIRTIO_SND_CTL_ACCESS_WRITE] = SNDRV_CTL_ELEM_ACCESS_WRITE, 25 + [VIRTIO_SND_CTL_ACCESS_VOLATILE] = SNDRV_CTL_ELEM_ACCESS_VOLATILE, 26 + [VIRTIO_SND_CTL_ACCESS_INACTIVE] = SNDRV_CTL_ELEM_ACCESS_INACTIVE, 27 + [VIRTIO_SND_CTL_ACCESS_TLV_READ] = SNDRV_CTL_ELEM_ACCESS_TLV_READ, 28 + [VIRTIO_SND_CTL_ACCESS_TLV_WRITE] = SNDRV_CTL_ELEM_ACCESS_TLV_WRITE, 29 + [VIRTIO_SND_CTL_ACCESS_TLV_COMMAND] = SNDRV_CTL_ELEM_ACCESS_TLV_COMMAND 30 + }; 31 + 32 + /* Map for converting VirtIO event masks to ALSA event masks. */ 33 + static const unsigned int g_v2a_mask_map[] = { 34 + [VIRTIO_SND_CTL_EVT_MASK_VALUE] = SNDRV_CTL_EVENT_MASK_VALUE, 35 + [VIRTIO_SND_CTL_EVT_MASK_INFO] = SNDRV_CTL_EVENT_MASK_INFO, 36 + [VIRTIO_SND_CTL_EVT_MASK_TLV] = SNDRV_CTL_EVENT_MASK_TLV 37 + }; 38 + 39 + /** 40 + * virtsnd_kctl_info() - Returns information about the control. 41 + * @kcontrol: ALSA control element. 42 + * @uinfo: Element information. 43 + * 44 + * Context: Process context. 45 + * Return: 0 on success, -errno on failure. 46 + */ 47 + static int virtsnd_kctl_info(struct snd_kcontrol *kcontrol, 48 + struct snd_ctl_elem_info *uinfo) 49 + { 50 + struct virtio_snd *snd = kcontrol->private_data; 51 + struct virtio_kctl *kctl = &snd->kctls[kcontrol->private_value]; 52 + struct virtio_snd_ctl_info *kinfo = 53 + &snd->kctl_infos[kcontrol->private_value]; 54 + unsigned int i; 55 + 56 + uinfo->type = g_v2a_type_map[le32_to_cpu(kinfo->type)]; 57 + uinfo->count = le32_to_cpu(kinfo->count); 58 + 59 + switch (uinfo->type) { 60 + case SNDRV_CTL_ELEM_TYPE_INTEGER: 61 + uinfo->value.integer.min = 62 + le32_to_cpu(kinfo->value.integer.min); 63 + uinfo->value.integer.max = 64 + le32_to_cpu(kinfo->value.integer.max); 65 + uinfo->value.integer.step = 66 + le32_to_cpu(kinfo->value.integer.step); 67 + 68 + break; 69 + case SNDRV_CTL_ELEM_TYPE_INTEGER64: 70 + uinfo->value.integer64.min = 71 + le64_to_cpu(kinfo->value.integer64.min); 72 + uinfo->value.integer64.max = 73 + le64_to_cpu(kinfo->value.integer64.max); 74 + uinfo->value.integer64.step = 75 + le64_to_cpu(kinfo->value.integer64.step); 76 + 77 + break; 78 + case SNDRV_CTL_ELEM_TYPE_ENUMERATED: 79 + uinfo->value.enumerated.items = 80 + le32_to_cpu(kinfo->value.enumerated.items); 81 + i = uinfo->value.enumerated.item; 82 + if (i >= uinfo->value.enumerated.items) 83 + return -EINVAL; 84 + 85 + strscpy(uinfo->value.enumerated.name, kctl->items[i].item, 86 + sizeof(uinfo->value.enumerated.name)); 87 + 88 + break; 89 + } 90 + 91 + return 0; 92 + } 93 + 94 + /** 95 + * virtsnd_kctl_get() - Read the value from the control. 96 + * @kcontrol: ALSA control element. 97 + * @uvalue: Element value. 98 + * 99 + * Context: Process context. 100 + * Return: 0 on success, -errno on failure. 101 + */ 102 + static int virtsnd_kctl_get(struct snd_kcontrol *kcontrol, 103 + struct snd_ctl_elem_value *uvalue) 104 + { 105 + struct virtio_snd *snd = kcontrol->private_data; 106 + struct virtio_snd_ctl_info *kinfo = 107 + &snd->kctl_infos[kcontrol->private_value]; 108 + unsigned int type = le32_to_cpu(kinfo->type); 109 + unsigned int count = le32_to_cpu(kinfo->count); 110 + struct virtio_snd_msg *msg; 111 + struct virtio_snd_ctl_hdr *hdr; 112 + struct virtio_snd_ctl_value *kvalue; 113 + size_t request_size = sizeof(*hdr); 114 + size_t response_size = sizeof(struct virtio_snd_hdr) + sizeof(*kvalue); 115 + unsigned int i; 116 + int rc; 117 + 118 + msg = virtsnd_ctl_msg_alloc(request_size, response_size, GFP_KERNEL); 119 + if (!msg) 120 + return -ENOMEM; 121 + 122 + virtsnd_ctl_msg_ref(msg); 123 + 124 + hdr = virtsnd_ctl_msg_request(msg); 125 + hdr->hdr.code = cpu_to_le32(VIRTIO_SND_R_CTL_READ); 126 + hdr->control_id = cpu_to_le32(kcontrol->private_value); 127 + 128 + rc = virtsnd_ctl_msg_send_sync(snd, msg); 129 + if (rc) 130 + goto on_failure; 131 + 132 + kvalue = (void *)((u8 *)virtsnd_ctl_msg_response(msg) + 133 + sizeof(struct virtio_snd_hdr)); 134 + 135 + switch (type) { 136 + case VIRTIO_SND_CTL_TYPE_BOOLEAN: 137 + case VIRTIO_SND_CTL_TYPE_INTEGER: 138 + for (i = 0; i < count; ++i) 139 + uvalue->value.integer.value[i] = 140 + le32_to_cpu(kvalue->value.integer[i]); 141 + break; 142 + case VIRTIO_SND_CTL_TYPE_INTEGER64: 143 + for (i = 0; i < count; ++i) 144 + uvalue->value.integer64.value[i] = 145 + le64_to_cpu(kvalue->value.integer64[i]); 146 + break; 147 + case VIRTIO_SND_CTL_TYPE_ENUMERATED: 148 + for (i = 0; i < count; ++i) 149 + uvalue->value.enumerated.item[i] = 150 + le32_to_cpu(kvalue->value.enumerated[i]); 151 + break; 152 + case VIRTIO_SND_CTL_TYPE_BYTES: 153 + memcpy(uvalue->value.bytes.data, kvalue->value.bytes, count); 154 + break; 155 + case VIRTIO_SND_CTL_TYPE_IEC958: 156 + memcpy(&uvalue->value.iec958, &kvalue->value.iec958, 157 + sizeof(uvalue->value.iec958)); 158 + break; 159 + } 160 + 161 + on_failure: 162 + virtsnd_ctl_msg_unref(msg); 163 + 164 + return rc; 165 + } 166 + 167 + /** 168 + * virtsnd_kctl_put() - Write the value to the control. 169 + * @kcontrol: ALSA control element. 170 + * @uvalue: Element value. 171 + * 172 + * Context: Process context. 173 + * Return: 0 on success, -errno on failure. 174 + */ 175 + static int virtsnd_kctl_put(struct snd_kcontrol *kcontrol, 176 + struct snd_ctl_elem_value *uvalue) 177 + { 178 + struct virtio_snd *snd = kcontrol->private_data; 179 + struct virtio_snd_ctl_info *kinfo = 180 + &snd->kctl_infos[kcontrol->private_value]; 181 + unsigned int type = le32_to_cpu(kinfo->type); 182 + unsigned int count = le32_to_cpu(kinfo->count); 183 + struct virtio_snd_msg *msg; 184 + struct virtio_snd_ctl_hdr *hdr; 185 + struct virtio_snd_ctl_value *kvalue; 186 + size_t request_size = sizeof(*hdr) + sizeof(*kvalue); 187 + size_t response_size = sizeof(struct virtio_snd_hdr); 188 + unsigned int i; 189 + 190 + msg = virtsnd_ctl_msg_alloc(request_size, response_size, GFP_KERNEL); 191 + if (!msg) 192 + return -ENOMEM; 193 + 194 + hdr = virtsnd_ctl_msg_request(msg); 195 + hdr->hdr.code = cpu_to_le32(VIRTIO_SND_R_CTL_WRITE); 196 + hdr->control_id = cpu_to_le32(kcontrol->private_value); 197 + 198 + kvalue = (void *)((u8 *)hdr + sizeof(*hdr)); 199 + 200 + switch (type) { 201 + case VIRTIO_SND_CTL_TYPE_BOOLEAN: 202 + case VIRTIO_SND_CTL_TYPE_INTEGER: 203 + for (i = 0; i < count; ++i) 204 + kvalue->value.integer[i] = 205 + cpu_to_le32(uvalue->value.integer.value[i]); 206 + break; 207 + case VIRTIO_SND_CTL_TYPE_INTEGER64: 208 + for (i = 0; i < count; ++i) 209 + kvalue->value.integer64[i] = 210 + cpu_to_le64(uvalue->value.integer64.value[i]); 211 + break; 212 + case VIRTIO_SND_CTL_TYPE_ENUMERATED: 213 + for (i = 0; i < count; ++i) 214 + kvalue->value.enumerated[i] = 215 + cpu_to_le32(uvalue->value.enumerated.item[i]); 216 + break; 217 + case VIRTIO_SND_CTL_TYPE_BYTES: 218 + memcpy(kvalue->value.bytes, uvalue->value.bytes.data, count); 219 + break; 220 + case VIRTIO_SND_CTL_TYPE_IEC958: 221 + memcpy(&kvalue->value.iec958, &uvalue->value.iec958, 222 + sizeof(kvalue->value.iec958)); 223 + break; 224 + } 225 + 226 + return virtsnd_ctl_msg_send_sync(snd, msg); 227 + } 228 + 229 + /** 230 + * virtsnd_kctl_tlv_op() - Perform an operation on the control's metadata. 231 + * @kcontrol: ALSA control element. 232 + * @op_flag: Operation code (SNDRV_CTL_TLV_OP_XXX). 233 + * @size: Size of the TLV data in bytes. 234 + * @utlv: TLV data. 235 + * 236 + * Context: Process context. 237 + * Return: 0 on success, -errno on failure. 238 + */ 239 + static int virtsnd_kctl_tlv_op(struct snd_kcontrol *kcontrol, int op_flag, 240 + unsigned int size, unsigned int __user *utlv) 241 + { 242 + struct virtio_snd *snd = kcontrol->private_data; 243 + struct virtio_snd_msg *msg; 244 + struct virtio_snd_ctl_hdr *hdr; 245 + unsigned int *tlv; 246 + struct scatterlist sg; 247 + int rc; 248 + 249 + msg = virtsnd_ctl_msg_alloc(sizeof(*hdr), sizeof(struct virtio_snd_hdr), 250 + GFP_KERNEL); 251 + if (!msg) 252 + return -ENOMEM; 253 + 254 + tlv = kzalloc(size, GFP_KERNEL); 255 + if (!tlv) { 256 + rc = -ENOMEM; 257 + goto on_msg_unref; 258 + } 259 + 260 + sg_init_one(&sg, tlv, size); 261 + 262 + hdr = virtsnd_ctl_msg_request(msg); 263 + hdr->control_id = cpu_to_le32(kcontrol->private_value); 264 + 265 + switch (op_flag) { 266 + case SNDRV_CTL_TLV_OP_READ: 267 + hdr->hdr.code = cpu_to_le32(VIRTIO_SND_R_CTL_TLV_READ); 268 + 269 + rc = virtsnd_ctl_msg_send(snd, msg, NULL, &sg, false); 270 + if (!rc) { 271 + if (copy_to_user(utlv, tlv, size)) 272 + rc = -EFAULT; 273 + } 274 + 275 + break; 276 + case SNDRV_CTL_TLV_OP_WRITE: 277 + case SNDRV_CTL_TLV_OP_CMD: 278 + if (op_flag == SNDRV_CTL_TLV_OP_WRITE) 279 + hdr->hdr.code = cpu_to_le32(VIRTIO_SND_R_CTL_TLV_WRITE); 280 + else 281 + hdr->hdr.code = 282 + cpu_to_le32(VIRTIO_SND_R_CTL_TLV_COMMAND); 283 + 284 + if (copy_from_user(tlv, utlv, size)) { 285 + rc = -EFAULT; 286 + goto on_msg_unref; 287 + } else { 288 + rc = virtsnd_ctl_msg_send(snd, msg, &sg, NULL, false); 289 + } 290 + 291 + break; 292 + default: 293 + rc = -EINVAL; 294 + /* We never get here - we listed all values for op_flag */ 295 + WARN_ON(1); 296 + goto on_msg_unref; 297 + } 298 + kfree(tlv); 299 + return rc; 300 + 301 + on_msg_unref: 302 + virtsnd_ctl_msg_unref(msg); 303 + kfree(tlv); 304 + 305 + return rc; 306 + } 307 + 308 + /** 309 + * virtsnd_kctl_get_enum_items() - Query items for the ENUMERATED element type. 310 + * @snd: VirtIO sound device. 311 + * @cid: Control element ID. 312 + * 313 + * This function is called during initial device initialization. 314 + * 315 + * Context: Any context that permits to sleep. 316 + * Return: 0 on success, -errno on failure. 317 + */ 318 + static int virtsnd_kctl_get_enum_items(struct virtio_snd *snd, unsigned int cid) 319 + { 320 + struct virtio_device *vdev = snd->vdev; 321 + struct virtio_snd_ctl_info *kinfo = &snd->kctl_infos[cid]; 322 + struct virtio_kctl *kctl = &snd->kctls[cid]; 323 + struct virtio_snd_msg *msg; 324 + struct virtio_snd_ctl_hdr *hdr; 325 + unsigned int n = le32_to_cpu(kinfo->value.enumerated.items); 326 + struct scatterlist sg; 327 + 328 + msg = virtsnd_ctl_msg_alloc(sizeof(*hdr), 329 + sizeof(struct virtio_snd_hdr), GFP_KERNEL); 330 + if (!msg) 331 + return -ENOMEM; 332 + 333 + kctl->items = devm_kcalloc(&vdev->dev, n, sizeof(*kctl->items), 334 + GFP_KERNEL); 335 + if (!kctl->items) { 336 + virtsnd_ctl_msg_unref(msg); 337 + return -ENOMEM; 338 + } 339 + 340 + sg_init_one(&sg, kctl->items, n * sizeof(*kctl->items)); 341 + 342 + hdr = virtsnd_ctl_msg_request(msg); 343 + hdr->hdr.code = cpu_to_le32(VIRTIO_SND_R_CTL_ENUM_ITEMS); 344 + hdr->control_id = cpu_to_le32(cid); 345 + 346 + return virtsnd_ctl_msg_send(snd, msg, NULL, &sg, false); 347 + } 348 + 349 + /** 350 + * virtsnd_kctl_parse_cfg() - Parse the control element configuration. 351 + * @snd: VirtIO sound device. 352 + * 353 + * This function is called during initial device initialization. 354 + * 355 + * Context: Any context that permits to sleep. 356 + * Return: 0 on success, -errno on failure. 357 + */ 358 + int virtsnd_kctl_parse_cfg(struct virtio_snd *snd) 359 + { 360 + struct virtio_device *vdev = snd->vdev; 361 + u32 i; 362 + int rc; 363 + 364 + virtio_cread_le(vdev, struct virtio_snd_config, controls, 365 + &snd->nkctls); 366 + if (!snd->nkctls) 367 + return 0; 368 + 369 + snd->kctl_infos = devm_kcalloc(&vdev->dev, snd->nkctls, 370 + sizeof(*snd->kctl_infos), GFP_KERNEL); 371 + if (!snd->kctl_infos) 372 + return -ENOMEM; 373 + 374 + snd->kctls = devm_kcalloc(&vdev->dev, snd->nkctls, sizeof(*snd->kctls), 375 + GFP_KERNEL); 376 + if (!snd->kctls) 377 + return -ENOMEM; 378 + 379 + rc = virtsnd_ctl_query_info(snd, VIRTIO_SND_R_CTL_INFO, 0, snd->nkctls, 380 + sizeof(*snd->kctl_infos), snd->kctl_infos); 381 + if (rc) 382 + return rc; 383 + 384 + for (i = 0; i < snd->nkctls; ++i) { 385 + struct virtio_snd_ctl_info *kinfo = &snd->kctl_infos[i]; 386 + unsigned int type = le32_to_cpu(kinfo->type); 387 + 388 + if (type == VIRTIO_SND_CTL_TYPE_ENUMERATED) { 389 + rc = virtsnd_kctl_get_enum_items(snd, i); 390 + if (rc) 391 + return rc; 392 + } 393 + } 394 + 395 + return 0; 396 + } 397 + 398 + /** 399 + * virtsnd_kctl_build_devs() - Build ALSA control elements. 400 + * @snd: VirtIO sound device. 401 + * 402 + * Context: Any context that permits to sleep. 403 + * Return: 0 on success, -errno on failure. 404 + */ 405 + int virtsnd_kctl_build_devs(struct virtio_snd *snd) 406 + { 407 + unsigned int cid; 408 + 409 + for (cid = 0; cid < snd->nkctls; ++cid) { 410 + struct virtio_snd_ctl_info *kinfo = &snd->kctl_infos[cid]; 411 + struct virtio_kctl *kctl = &snd->kctls[cid]; 412 + struct snd_kcontrol_new kctl_new; 413 + unsigned int i; 414 + int rc; 415 + 416 + memset(&kctl_new, 0, sizeof(kctl_new)); 417 + 418 + kctl_new.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 419 + kctl_new.name = kinfo->name; 420 + kctl_new.index = le32_to_cpu(kinfo->index); 421 + 422 + for (i = 0; i < ARRAY_SIZE(g_v2a_access_map); ++i) 423 + if (le32_to_cpu(kinfo->access) & (1 << i)) 424 + kctl_new.access |= g_v2a_access_map[i]; 425 + 426 + if (kctl_new.access & (SNDRV_CTL_ELEM_ACCESS_TLV_READ | 427 + SNDRV_CTL_ELEM_ACCESS_TLV_WRITE | 428 + SNDRV_CTL_ELEM_ACCESS_TLV_COMMAND)) { 429 + kctl_new.access |= SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK; 430 + kctl_new.tlv.c = virtsnd_kctl_tlv_op; 431 + } 432 + 433 + kctl_new.info = virtsnd_kctl_info; 434 + kctl_new.get = virtsnd_kctl_get; 435 + kctl_new.put = virtsnd_kctl_put; 436 + kctl_new.private_value = cid; 437 + 438 + kctl->kctl = snd_ctl_new1(&kctl_new, snd); 439 + if (!kctl->kctl) 440 + return -ENOMEM; 441 + 442 + rc = snd_ctl_add(snd->card, kctl->kctl); 443 + if (rc) 444 + return rc; 445 + } 446 + 447 + return 0; 448 + } 449 + 450 + /** 451 + * virtsnd_kctl_event() - Handle the control element event notification. 452 + * @snd: VirtIO sound device. 453 + * @event: VirtIO sound event. 454 + * 455 + * Context: Interrupt context. 456 + */ 457 + void virtsnd_kctl_event(struct virtio_snd *snd, struct virtio_snd_event *event) 458 + { 459 + struct virtio_snd_ctl_event *kevent = 460 + (struct virtio_snd_ctl_event *)event; 461 + struct virtio_kctl *kctl; 462 + unsigned int cid = le16_to_cpu(kevent->control_id); 463 + unsigned int mask = 0; 464 + unsigned int i; 465 + 466 + if (cid >= snd->nkctls) 467 + return; 468 + 469 + for (i = 0; i < ARRAY_SIZE(g_v2a_mask_map); ++i) 470 + if (le16_to_cpu(kevent->mask) & (1 << i)) 471 + mask |= g_v2a_mask_map[i]; 472 + 473 + 474 + kctl = &snd->kctls[cid]; 475 + 476 + snd_ctl_notify(snd->card, mask, &kctl->kctl->id); 477 + }