Compare
8e8cd9a4c6dc006e9bd51b8ad0079fb4576b48d3..d5a821f66047c2effd06147b84775f9b2ce0f4aa
regmap: Fix cache lifecycle locking and teardown
Michael Reeves <michael.reeves077@gmail.com> says: Fix an "Invalid wait context" lockdep warning during Apple GPIO probe and correct debugfs ordering during cache teardown. Tested on Apple M3 MacBook Air (T8122): - All 4 GPIO controllers probe successfully with lockdep enabled. - The "Invalid wait context" warning no longer occurs. - The regmap KUnit suite passes and lockdep remains enabled. Link: https://patch.msgid.link/20261006-regcache-lifecycle-submit-v3-0-37bdd82fd47c@gmail.com
Mark Brown <broonie@kernel.org> · 2026-10-12 23:11 UTC
17 files changed,
+40
−70
- drivers/base/regmap/regcache-maple.c
- drivers/base/regmap/regcache.c
- drivers/base/regmap/regmap-debugfs.c
- drivers/base/regmap/regmap-irq.c
- drivers/base/regmap/regmap.c
- include/linux/maple_tree.h
- sound/soc/amd/yc/pci-acp6x.c
- sound/soc/codecs/cs42l52.c
- sound/soc/codecs/cs42l56.c
- sound/soc/codecs/max98371.c
- sound/soc/codecs/nau8822.c
- sound/soc/codecs/pcm3168a.c
- sound/soc/codecs/wm8978.c
- sound/soc/intel/avs/pcm.c
- sound/soc/sof/ipc4-topology.c
- sound/soc/sof/sof-client.c
- sound/soc/stm/stm32_spdifrx.c
modified drivers/base/regmap/regcache-maple.c
| @@ -312,16 +312,21 @@ static void regcache_maple_exit(struct regmap *map) | |||
| 312 | 312 | struct maple_tree *mt = map->cache; | |
| 313 | 313 | MA_STATE(mas, mt, 0, UINT_MAX); | |
| 314 | 314 | unsigned int *entry; | |
| 315 | + | unsigned long flags; | |
| 315 | 316 | ||
| 316 | 317 | /* if we've already been called then just return */ | |
| 317 | 318 | if (!mt) | |
| 318 | 319 | return; | |
| 319 | 320 | ||
| 320 | - | mas_lock(&mas); | |
| 321 | + | /* | |
| 322 | + | * Register access may take the Maple lock from hard IRQ context, so | |
| 323 | + | * preserve its IRQ-safe lockdep state during teardown. | |
| 324 | + | */ | |
| 325 | + | mas_lock_irqsave(&mas, flags); | |
| 321 | 326 | mas_for_each(&mas, entry, UINT_MAX) | |
| 322 | 327 | kfree(entry); | |
| 323 | 328 | __mt_destroy(mt); | |
| 324 | - | mas_unlock(&mas); | |
| 329 | + | mas_unlock_irqrestore(&mas, flags); | |
| 325 | 330 | ||
| 326 | 331 | kfree(mt); | |
| 327 | 332 | map->cache = NULL; | |
modified drivers/base/regmap/regcache.c
| @@ -225,9 +225,7 @@ int regcache_init(struct regmap *map, const struct regmap_config *config) | |||
| 225 | 225 | if (map->cache_ops->init) { | |
| 226 | 226 | dev_dbg(map->dev, "Initializing %s cache\n", | |
| 227 | 227 | map->cache_ops->name); | |
| 228 | - | map->lock(map->lock_arg); | |
| 229 | 228 | ret = map->cache_ops->init(map); | |
| 230 | - | map->unlock(map->lock_arg); | |
| 231 | 229 | if (ret) | |
| 232 | 230 | goto err_free_reg_defaults; | |
| 233 | 231 | } | |
| @@ -259,9 +257,7 @@ err_free: | |||
| 259 | 257 | err_exit: | |
| 260 | 258 | if (map->cache_ops->exit) { | |
| 261 | 259 | dev_dbg(map->dev, "Destroying %s cache\n", map->cache_ops->name); | |
| 262 | - | map->lock(map->lock_arg); | |
| 263 | 260 | map->cache_ops->exit(map); | |
| 264 | - | map->unlock(map->lock_arg); | |
| 265 | 261 | } | |
| 266 | 262 | err_free_reg_defaults: | |
| 267 | 263 | kfree(map->reg_defaults); | |
| @@ -281,9 +277,7 @@ void regcache_exit(struct regmap *map) | |||
| 281 | 277 | if (map->cache_ops->exit) { | |
| 282 | 278 | dev_dbg(map->dev, "Destroying %s cache\n", | |
| 283 | 279 | map->cache_ops->name); | |
| 284 | - | map->lock(map->lock_arg); | |
| 285 | 280 | map->cache_ops->exit(map); | |
| 286 | - | map->unlock(map->lock_arg); | |
| 287 | 281 | } | |
| 288 | 282 | ||
| 289 | 283 | kfree(map->reg_defaults); | |
modified drivers/base/regmap/regmap-debugfs.c
| @@ -664,6 +664,7 @@ void regmap_debugfs_exit(struct regmap *map) | |||
| 664 | 664 | { | |
| 665 | 665 | if (map->debugfs) { | |
| 666 | 666 | debugfs_remove_recursive(map->debugfs); | |
| 667 | + | map->debugfs = NULL; | |
| 667 | 668 | mutex_lock(&map->cache_lock); | |
| 668 | 669 | regmap_debugfs_free_dump_cache(map); | |
| 669 | 670 | mutex_unlock(&map->cache_lock); | |
modified drivers/base/regmap/regmap-irq.c
| @@ -963,7 +963,7 @@ int regmap_add_irq_chip_fwnode(struct fwnode_handle *fwnode, | |||
| 963 | 963 | return 0; | |
| 964 | 964 | ||
| 965 | 965 | err_domain: | |
| 966 | - | /* Should really dispose of the domain but... */ | |
| 966 | + | irq_domain_remove(d->domain); | |
| 967 | 967 | err_mutex: | |
| 968 | 968 | mutex_destroy(&d->lock); | |
| 969 | 969 | lockdep_unregister_key(&d->lock_key); | |
modified drivers/base/regmap/regmap.c
| @@ -1422,8 +1422,8 @@ int regmap_reinit_cache(struct regmap *map, const struct regmap_config *config) | |||
| 1422 | 1422 | { | |
| 1423 | 1423 | int ret; | |
| 1424 | 1424 | ||
| 1425 | - | regcache_exit(map); | |
| 1426 | 1425 | regmap_debugfs_exit(map); | |
| 1426 | + | regcache_exit(map); | |
| 1427 | 1427 | ||
| 1428 | 1428 | map->max_register = config->max_register; | |
| 1429 | 1429 | map->max_register_is_set = map->max_register ?: config->max_register_is_0; | |
| @@ -1440,12 +1440,16 @@ int regmap_reinit_cache(struct regmap *map, const struct regmap_config *config) | |||
| 1440 | 1440 | if (ret) | |
| 1441 | 1441 | return ret; | |
| 1442 | 1442 | ||
| 1443 | - | regmap_debugfs_init(map); | |
| 1444 | - | ||
| 1445 | 1443 | map->cache_bypass = false; | |
| 1446 | 1444 | map->cache_only = false; | |
| 1447 | 1445 | ||
| 1448 | - | return regcache_init(map, config); | |
| 1446 | + | ret = regcache_init(map, config); | |
| 1447 | + | if (ret) | |
| 1448 | + | return ret; | |
| 1449 | + | ||
| 1450 | + | regmap_debugfs_init(map); | |
| 1451 | + | ||
| 1452 | + | return 0; | |
| 1449 | 1453 | } | |
| 1450 | 1454 | EXPORT_SYMBOL_GPL(regmap_reinit_cache); | |
| 1451 | 1455 | ||
| @@ -1459,9 +1463,8 @@ void regmap_exit(struct regmap *map) | |||
| 1459 | 1463 | struct regmap_async *async; | |
| 1460 | 1464 | ||
| 1461 | 1465 | regmap_detach_dev(map->dev, map); | |
| 1462 | - | regcache_exit(map); | |
| 1463 | - | ||
| 1464 | 1466 | regmap_debugfs_exit(map); | |
| 1467 | + | regcache_exit(map); | |
| 1465 | 1468 | regmap_range_exit(map); | |
| 1466 | 1469 | if (map->bus && map->bus->free_context) | |
| 1467 | 1470 | map->bus->free_context(map->bus_context); | |
modified include/linux/maple_tree.h
| @@ -507,9 +507,13 @@ struct ma_wr_state { | |||
| 507 | 507 | }; | |
| 508 | 508 | ||
| 509 | 509 | #define mas_lock(mas) spin_lock(&((mas)->tree->ma_lock)) | |
| 510 | + | #define mas_lock_irqsave(mas, flags) \ | |
| 511 | + | spin_lock_irqsave(&((mas)->tree->ma_lock), flags) | |
| 510 | 512 | #define mas_lock_nested(mas, subclass) \ | |
| 511 | 513 | spin_lock_nested(&((mas)->tree->ma_lock), subclass) | |
| 512 | 514 | #define mas_unlock(mas) spin_unlock(&((mas)->tree->ma_lock)) | |
| 515 | + | #define mas_unlock_irqrestore(mas, flags) \ | |
| 516 | + | spin_unlock_irqrestore(&((mas)->tree->ma_lock), flags) | |
| 513 | 517 | ||
| 514 | 518 | /* | |
| 515 | 519 | * Special values for ma_state.node. | |
modified sound/soc/amd/yc/pci-acp6x.c
| @@ -301,7 +301,7 @@ static int snd_acp6x_suspend(struct device *dev) | |||
| 301 | 301 | return ret; | |
| 302 | 302 | } | |
| 303 | 303 | ||
| 304 | - | static int snd_acp6x_runtime_resume(struct device *dev) | |
| 304 | + | static int snd_acp6x_resume(struct device *dev) | |
| 305 | 305 | { | |
| 306 | 306 | struct acp6x_dev_data *adata; | |
| 307 | 307 | int ret; | |
| @@ -313,42 +313,8 @@ static int snd_acp6x_runtime_resume(struct device *dev) | |||
| 313 | 313 | return ret; | |
| 314 | 314 | } | |
| 315 | 315 | ||
| 316 | - | static void acp6x_disable_msi_on_resume(struct pci_dev *pdev) | |
| 317 | - | { | |
| 318 | - | u16 control; | |
| 319 | - | ||
| 320 | - | if (!pdev->msi_cap) | |
| 321 | - | return; | |
| 322 | - | ||
| 323 | - | pci_read_config_word(pdev, pdev->msi_cap + PCI_MSI_FLAGS, &control); | |
| 324 | - | if (control & PCI_MSI_FLAGS_ENABLE) { | |
| 325 | - | dev_warn(&pdev->dev, | |
| 326 | - | "ACP: MSI unexpectedly enabled after resume (flags=0x%04x), disabling\n", | |
| 327 | - | control); | |
| 328 | - | control &= ~PCI_MSI_FLAGS_ENABLE; | |
| 329 | - | pci_write_config_word(pdev, pdev->msi_cap + PCI_MSI_FLAGS, control); | |
| 330 | - | } | |
| 331 | - | } | |
| 332 | - | ||
| 333 | - | static int snd_acp6x_resume(struct device *dev) | |
| 334 | - | { | |
| 335 | - | struct pci_dev *pdev = to_pci_dev(dev); | |
| 336 | - | ||
| 337 | - | /* | |
| 338 | - | * BIOS/firmware may re-enable MSI in PCI config space during | |
| 339 | - | * system resume even though this driver only uses legacy INTx | |
| 340 | - | * interrupts. If MSI is left enabled with stale address/data | |
| 341 | - | * registers, the device will write interrupts to a bogus address | |
| 342 | - | * causing IOMMU IO_PAGE_FAULT and interrupt delivery failure. | |
| 343 | - | * Explicitly clear the MSI Enable bit before reinitializing | |
| 344 | - | * the ACP hardware. | |
| 345 | - | */ | |
| 346 | - | acp6x_disable_msi_on_resume(pdev); | |
| 347 | - | return snd_acp6x_runtime_resume(dev); | |
| 348 | - | } | |
| 349 | - | ||
| 350 | 316 | static const struct dev_pm_ops acp6x_pm = { | |
| 351 | - | RUNTIME_PM_OPS(snd_acp6x_suspend, snd_acp6x_runtime_resume, NULL) | |
| 317 | + | RUNTIME_PM_OPS(snd_acp6x_suspend, snd_acp6x_resume, NULL) | |
| 352 | 318 | SYSTEM_SLEEP_PM_OPS(snd_acp6x_suspend, snd_acp6x_resume) | |
| 353 | 319 | }; | |
| 354 | 320 | ||
modified sound/soc/codecs/cs42l52.c
| @@ -290,7 +290,7 @@ static const char * const cs42l52_ng_type_text[] = { | |||
| 290 | 290 | }; | |
| 291 | 291 | ||
| 292 | 292 | static SOC_ENUM_SINGLE_DECL(ng_type_enum, | |
| 293 | - | CS42L52_NOISE_GATE_CTL, 7, | |
| 293 | + | CS42L52_NOISE_GATE_CTL, 6, | |
| 294 | 294 | cs42l52_ng_type_text); | |
| 295 | 295 | ||
| 296 | 296 | static const char * const left_swap_text[] = { | |
modified sound/soc/codecs/cs42l56.c
| @@ -481,7 +481,7 @@ static const struct snd_kcontrol_new cs42l56_snd_controls[] = { | |||
| 481 | 481 | 0, 0x3f, 0, 0), | |
| 482 | 482 | SOC_SINGLE_TLV("Limiter MAX", CS42L56_LIM_THRESHOLD_CTL, | |
| 483 | 483 | 5, 0x07, 1, alc_tlv), | |
| 484 | - | SOC_SINGLE_TLV("Limiter Cushion", CS42L56_LIM_THRESHOLD_CTL, | |
| 484 | + | SOC_SINGLE_TLV("Limiter Cushion", CS42L56_ALC_THRESHOLD, | |
| 485 | 485 | 2, 0x07, 1, alc_tlv), | |
| 486 | 486 | ||
| 487 | 487 | SOC_SINGLE("NG Switch", CS42L56_NOISE_GATE_CTL, 6, 1, 1), | |
modified sound/soc/codecs/max98371.c
| @@ -166,7 +166,7 @@ static const struct snd_kcontrol_new max98371_snd_controls[] = { | |||
| 166 | 166 | 0, (1<<MAX98371_DHT_MAX_WIDTH)-1, 0, | |
| 167 | 167 | max98371_dht_max_gain), | |
| 168 | 168 | SOC_SINGLE_TLV("Speaker DHT Min Volume", MAX98371_DHT_GAIN, | |
| 169 | - | 4, (1<<MAX98371_DHT_GAIN_WIDTH)-1, 0, | |
| 169 | + | 0, (1<<MAX98371_DHT_GAIN_WIDTH)-1, 0, | |
| 170 | 170 | max98371_dht_min_gain), | |
| 171 | 171 | SOC_SINGLE_TLV("Speaker DHT Rotation Volume", MAX98371_DHT_GAIN, | |
| 172 | 172 | 0, (1<<MAX98371_DHT_ROT_WIDTH)-1, 0, | |
modified sound/soc/codecs/nau8822.c
| @@ -383,9 +383,9 @@ static const struct snd_kcontrol_new nau8822_snd_controls[] = { | |||
| 383 | 383 | NAU8822_REG_RIGHT_ADC_BOOST_CONTROL, 0, 7, 0, boost_tlv), | |
| 384 | 384 | ||
| 385 | 385 | SOC_SINGLE("DAC 128x Oversampling Switch", | |
| 386 | - | NAU8822_REG_DAC_CONTROL, 3, 1, 0), | |
| 386 | + | NAU8822_REG_DAC_CONTROL, 5, 1, 0), | |
| 387 | 387 | SOC_SINGLE("ADC 128x Oversampling Switch", | |
| 388 | - | NAU8822_REG_ADC_CONTROL, 3, 1, 0), | |
| 388 | + | NAU8822_REG_ADC_CONTROL, 5, 1, 0), | |
| 389 | 389 | }; | |
| 390 | 390 | ||
| 391 | 391 | /* LMAIN and RMAIN Mixer */ | |
modified sound/soc/codecs/pcm3168a.c
| @@ -103,7 +103,7 @@ static SOC_ENUM_SINGLE_DECL(pcm3168a_dac_zf_func, PCM3168A_DAC_ATT_DEMP_ZF, | |||
| 103 | 103 | static const char *const pcm3168a_pol[] = { "Active High", "Active Low" }; | |
| 104 | 104 | ||
| 105 | 105 | static SOC_ENUM_SINGLE_DECL(pcm3168a_dac_zf_pol, PCM3168A_DAC_ATT_DEMP_ZF, | |
| 106 | - | PCM3168A_DAC_ZREV_SHIFT, pcm3168a_pol); | |
| 106 | + | PCM3168A_DAC_ATSPDA_SHIFT, pcm3168a_pol); | |
| 107 | 107 | ||
| 108 | 108 | static const char *const pcm3168a_con[] = { "Differential", "Single-Ended" }; | |
| 109 | 109 | ||
modified sound/soc/codecs/wm8978.c
| @@ -255,9 +255,9 @@ static const struct snd_kcontrol_new wm8978_snd_controls[] = { | |||
| 255 | 255 | ||
| 256 | 256 | /* DAC / ADC oversampling */ | |
| 257 | 257 | SOC_SINGLE("DAC 128x Oversampling Switch", WM8978_DAC_CONTROL, | |
| 258 | - | 3, 1, 0), | |
| 258 | + | 5, 1, 0), | |
| 259 | 259 | SOC_SINGLE("ADC 128x Oversampling Switch", WM8978_ADC_CONTROL, | |
| 260 | - | 3, 1, 0), | |
| 260 | + | 5, 1, 0), | |
| 261 | 261 | }; | |
| 262 | 262 | ||
| 263 | 263 | /* Mixer #1: Output (OUT1, OUT2) Mixer: mix AUX, Input mixer output and DAC */ | |
modified sound/soc/intel/avs/pcm.c
| @@ -756,7 +756,7 @@ static int avs_dai_fe_prepare(struct snd_pcm_substream *substream, struct snd_so | |||
| 756 | 756 | data = snd_soc_dai_get_dma_data(dai, substream); | |
| 757 | 757 | host_stream = data->host_stream; | |
| 758 | 758 | ||
| 759 | - | if (runtime->state != SNDRV_PCM_STATE_PREPARED) | |
| 759 | + | if (runtime->state == SNDRV_PCM_STATE_XRUN) | |
| 760 | 760 | hdac_stream(host_stream)->prepared = false; | |
| 761 | 761 | if (hdac_stream(host_stream)->prepared) | |
| 762 | 762 | return 0; | |
modified sound/soc/sof/ipc4-topology.c
| @@ -2458,14 +2458,11 @@ _sof_ipc4_prepare_copier_module(struct snd_sof_widget *swidget, | |||
| 2458 | 2458 | ch_map >>= 4; | |
| 2459 | 2459 | } | |
| 2460 | 2460 | ||
| 2461 | - | if ((swidget->id == snd_soc_dapm_dai_in && ch_count == out_ref_channels) || | |
| 2462 | - | ch_count < blob->alh_cfg.device_count) { | |
| 2461 | + | if (swidget->id == snd_soc_dapm_dai_in && ch_count == out_ref_channels) { | |
| 2463 | 2462 | /* | |
| 2464 | 2463 | * For playback DAI widgets where the channel number is equal to | |
| 2465 | - | * the output reference channels, or when there are fewer | |
| 2466 | - | * channels than aggregated devices (e.g. a mono capture | |
| 2467 | - | * stream split across multiple links), set step = 0 to | |
| 2468 | - | * ensure all the ch_mask is applied to all alh mappings. | |
| 2464 | + | * the output reference channels, set the step = 0 to ensure all | |
| 2465 | + | * the ch_mask is applied to all alh mappings. | |
| 2469 | 2466 | */ | |
| 2470 | 2467 | mask = ch_mask; | |
| 2471 | 2468 | step = 0; | |
modified sound/soc/sof/sof-client.c
| @@ -576,7 +576,7 @@ void sof_client_unregister_ipc_rx_handler(struct sof_client_dev *cdev, | |||
| 576 | 576 | struct snd_sof_dev *sdev = sof_client_dev_to_sof_dev(cdev); | |
| 577 | 577 | struct sof_ipc_event_entry *event; | |
| 578 | 578 | ||
| 579 | - | guard(mutex)(&sdev->client_event_handler_mutex); | |
| 579 | + | guard(mutex)(&sdev->ipc_client_mutex); | |
| 580 | 580 | ||
| 581 | 581 | list_for_each_entry(event, &sdev->ipc_rx_handler_list, list) { | |
| 582 | 582 | if (event->cdev == cdev && event->ipc_msg_type == ipc_msg_type) { | |
| @@ -593,7 +593,7 @@ void sof_client_fw_state_dispatcher(struct snd_sof_dev *sdev) | |||
| 593 | 593 | { | |
| 594 | 594 | struct sof_state_event_entry *event; | |
| 595 | 595 | ||
| 596 | - | guard(mutex)(&sdev->client_event_handler_mutex); | |
| 596 | + | guard(mutex)(&sdev->ipc_client_mutex); | |
| 597 | 597 | ||
| 598 | 598 | list_for_each_entry(event, &sdev->fw_state_handler_list, list) | |
| 599 | 599 | event->callback(event->cdev, sdev->fw_state); | |
| @@ -628,7 +628,7 @@ void sof_client_unregister_fw_state_handler(struct sof_client_dev *cdev) | |||
| 628 | 628 | struct snd_sof_dev *sdev = sof_client_dev_to_sof_dev(cdev); | |
| 629 | 629 | struct sof_state_event_entry *event; | |
| 630 | 630 | ||
| 631 | - | guard(mutex)(&sdev->client_event_handler_mutex); | |
| 631 | + | guard(mutex)(&sdev->ipc_client_mutex); | |
| 632 | 632 | ||
| 633 | 633 | list_for_each_entry(event, &sdev->fw_state_handler_list, list) { | |
| 634 | 634 | if (event->cdev == cdev) { | |
modified sound/soc/stm/stm32_spdifrx.c
| @@ -720,7 +720,7 @@ static irqreturn_t stm32_spdifrx_isr(int irq, void *devid) | |||
| 720 | 720 | ||
| 721 | 721 | if (err) { | |
| 722 | 722 | regmap_read(spdifrx->regmap, STM32_SPDIFRX_CR, &cr); | |
| 723 | - | sync_state = FIELD_GET(SPDIFRX_CR_SPDIFEN_MASK, cr) == | |
| 723 | + | sync_state = FIELD_GET(SPDIFRX_CR_SPDIFEN_MASK, cr) && | |
| 724 | 724 | SPDIFRX_SPDIFEN_SYNC; | |
| 725 | 725 | ||
| 726 | 726 | /* SPDIFRX is in STATE_STOP. Disable SPDIFRX to clear errors */ | |