Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions include/sound/soc.h
Original file line number Diff line number Diff line change
Expand Up @@ -802,8 +802,13 @@ struct snd_soc_component_driver {
int probe_order;
int remove_order;

/* signal if the module handling the component cannot be removed */
unsigned int ignore_module_refcount:1;
/*
* signal if the module handling the component should not be removed
* if a pcm is open. Setting this would prevent the module
* refcount being incremented in probe() but allow it be incremented
* when a pcm is opened and decremented when it is closed.
*/
unsigned int module_get_upon_open:1;

/* bits */
unsigned int idle_bias_on:1;
Expand Down
2 changes: 1 addition & 1 deletion sound/soc/intel/skylake/skl-pcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1468,7 +1468,7 @@ static const struct snd_soc_component_driver skl_component = {
.ops = &skl_platform_ops,
.pcm_new = skl_pcm_new,
.pcm_free = skl_pcm_free,
.ignore_module_refcount = 1, /* do not increase the refcount in core */
.module_get_upon_open = 1, /* increment refcount when a pcm is opened */
};

int skl_platform_register(struct device *dev)
Expand Down
4 changes: 2 additions & 2 deletions sound/soc/soc-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ static void soc_cleanup_component(struct snd_soc_component *component)
snd_soc_dapm_free(snd_soc_component_get_dapm(component));
soc_cleanup_component_debugfs(component);
component->card = NULL;
if (!component->driver->ignore_module_refcount)
if (!component->driver->module_get_upon_open)
module_put(component->dev->driver->owner);
}

Expand Down Expand Up @@ -1381,7 +1381,7 @@ static int soc_probe_component(struct snd_soc_card *card,
return 0;
}

if (!component->driver->ignore_module_refcount &&
if (!component->driver->module_get_upon_open &&
!try_module_get(component->dev->driver->owner))
return -ENODEV;

Expand Down
8 changes: 8 additions & 0 deletions sound/soc/soc-pcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <linux/delay.h>
#include <linux/pinctrl/consumer.h>
#include <linux/pm_runtime.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/workqueue.h>
#include <linux/export.h>
Expand Down Expand Up @@ -463,6 +464,9 @@ static int soc_pcm_components_close(struct snd_pcm_substream *substream,
continue;

component->driver->ops->close(substream);

if (component->driver->module_get_upon_open)
module_put(component->dev->driver->owner);
}

return 0;
Expand Down Expand Up @@ -513,6 +517,10 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
!component->driver->ops->open)
continue;

if (component->driver->module_get_upon_open &&
!try_module_get(component->dev->driver->owner))
return -ENODEV;

ret = component->driver->ops->open(substream);
if (ret < 0) {
dev_err(component->dev,
Expand Down
4 changes: 2 additions & 2 deletions sound/soc/sof/pcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,6 @@ void snd_sof_new_platform_drv(struct snd_sof_dev *sdev)
pd->use_dai_pcm_id = true;
pd->topology_name_prefix = "sof";

/* do not increase the refcount in core */
pd->ignore_module_refcount = 1;
/* increment module refcount when a pcm is opened */
pd->module_get_upon_open = 1;
}