summaryrefslogtreecommitdiff
path: root/sound/ac97
diff options
context:
space:
mode:
Diffstat (limited to 'sound/ac97')
-rw-r--r--sound/ac97/bus.c45
-rw-r--r--sound/ac97/snd_ac97_compat.c2
2 files changed, 19 insertions, 28 deletions
diff --git a/sound/ac97/bus.c b/sound/ac97/bus.c
index 8dfffdc101a2..15487837e894 100644
--- a/sound/ac97/bus.c
+++ b/sound/ac97/bus.c
@@ -104,7 +104,7 @@ static int ac97_codec_add(struct ac97_controller *ac97_ctrl, int idx,
struct ac97_codec_device *codec;
int ret;
- codec = kzalloc(sizeof(*codec), GFP_KERNEL);
+ codec = kzalloc_obj(*codec);
if (!codec)
return -ENOMEM;
ac97_ctrl->codecs[idx] = codec;
@@ -241,10 +241,9 @@ static ssize_t cold_reset_store(struct device *dev,
{
struct ac97_controller *ac97_ctrl;
- mutex_lock(&ac97_controllers_mutex);
+ guard(mutex)(&ac97_controllers_mutex);
ac97_ctrl = to_ac97_controller(dev);
ac97_ctrl->ops->reset(ac97_ctrl);
- mutex_unlock(&ac97_controllers_mutex);
return len;
}
static DEVICE_ATTR_WO(cold_reset);
@@ -258,10 +257,9 @@ static ssize_t warm_reset_store(struct device *dev,
if (!dev)
return -ENODEV;
- mutex_lock(&ac97_controllers_mutex);
+ guard(mutex)(&ac97_controllers_mutex);
ac97_ctrl = to_ac97_controller(dev);
ac97_ctrl->ops->warm_reset(ac97_ctrl);
- mutex_unlock(&ac97_controllers_mutex);
return len;
}
static DEVICE_ATTR_WO(warm_reset);
@@ -284,10 +282,10 @@ static const struct attribute_group *ac97_adapter_groups[] = {
static void ac97_del_adapter(struct ac97_controller *ac97_ctrl)
{
- mutex_lock(&ac97_controllers_mutex);
- ac97_ctrl_codecs_unregister(ac97_ctrl);
- list_del(&ac97_ctrl->controllers);
- mutex_unlock(&ac97_controllers_mutex);
+ scoped_guard(mutex, &ac97_controllers_mutex) {
+ ac97_ctrl_codecs_unregister(ac97_ctrl);
+ list_del(&ac97_ctrl->controllers);
+ }
device_unregister(&ac97_ctrl->adap);
}
@@ -300,6 +298,7 @@ static void ac97_adapter_release(struct device *dev)
idr_remove(&ac97_adapter_idr, ac97_ctrl->nr);
dev_dbg(&ac97_ctrl->adap, "adapter unregistered by %s\n",
dev_name(ac97_ctrl->parent));
+ kfree(ac97_ctrl);
}
static const struct device_type ac97_adapter_type = {
@@ -311,7 +310,7 @@ static int ac97_add_adapter(struct ac97_controller *ac97_ctrl)
{
int ret;
- mutex_lock(&ac97_controllers_mutex);
+ guard(mutex)(&ac97_controllers_mutex);
ret = idr_alloc(&ac97_adapter_idr, ac97_ctrl, 0, 0, GFP_KERNEL);
ac97_ctrl->nr = ret;
if (ret >= 0) {
@@ -321,14 +320,14 @@ static int ac97_add_adapter(struct ac97_controller *ac97_ctrl)
ret = device_register(&ac97_ctrl->adap);
if (ret)
put_device(&ac97_ctrl->adap);
- }
- if (!ret)
- list_add(&ac97_ctrl->controllers, &ac97_controllers);
- mutex_unlock(&ac97_controllers_mutex);
+ } else
+ kfree(ac97_ctrl);
- if (!ret)
+ if (!ret) {
+ list_add(&ac97_ctrl->controllers, &ac97_controllers);
dev_dbg(&ac97_ctrl->adap, "adapter registered by %s\n",
dev_name(ac97_ctrl->parent));
+ }
return ret;
}
@@ -352,7 +351,7 @@ struct ac97_controller *snd_ac97_controller_register(
struct ac97_controller *ac97_ctrl;
int ret, i;
- ac97_ctrl = kzalloc(sizeof(*ac97_ctrl), GFP_KERNEL);
+ ac97_ctrl = kzalloc_obj(*ac97_ctrl);
if (!ac97_ctrl)
return ERR_PTR(-ENOMEM);
@@ -365,14 +364,11 @@ struct ac97_controller *snd_ac97_controller_register(
ret = ac97_add_adapter(ac97_ctrl);
if (ret)
- goto err;
+ return ERR_PTR(ret);
ac97_bus_reset(ac97_ctrl);
ac97_bus_scan(ac97_ctrl);
return ac97_ctrl;
-err:
- kfree(ac97_ctrl);
- return ERR_PTR(ret);
}
EXPORT_SYMBOL_GPL(snd_ac97_controller_register);
@@ -387,7 +383,6 @@ void snd_ac97_controller_unregister(struct ac97_controller *ac97_ctrl)
}
EXPORT_SYMBOL_GPL(snd_ac97_controller_unregister);
-#ifdef CONFIG_PM
static int ac97_pm_runtime_suspend(struct device *dev)
{
struct ac97_codec_device *codec = to_ac97_device(dev);
@@ -419,7 +414,6 @@ static int ac97_pm_runtime_resume(struct device *dev)
return pm_generic_runtime_resume(dev);
}
-#endif /* CONFIG_PM */
static const struct dev_pm_ops ac97_pm = {
.suspend = pm_generic_suspend,
@@ -428,10 +422,7 @@ static const struct dev_pm_ops ac97_pm = {
.thaw = pm_generic_thaw,
.poweroff = pm_generic_poweroff,
.restore = pm_generic_restore,
- SET_RUNTIME_PM_OPS(
- ac97_pm_runtime_suspend,
- ac97_pm_runtime_resume,
- NULL)
+ RUNTIME_PM_OPS(ac97_pm_runtime_suspend, ac97_pm_runtime_resume, NULL)
};
static int ac97_get_enable_clk(struct ac97_codec_device *adev)
@@ -535,7 +526,7 @@ const struct bus_type ac97_bus_type = {
.name = "ac97bus",
.dev_groups = ac97_dev_groups,
.match = ac97_bus_match,
- .pm = &ac97_pm,
+ .pm = pm_ptr(&ac97_pm),
.probe = ac97_bus_probe,
.remove = ac97_bus_remove,
};
diff --git a/sound/ac97/snd_ac97_compat.c b/sound/ac97/snd_ac97_compat.c
index d2479bba75bf..1a89286d1b67 100644
--- a/sound/ac97/snd_ac97_compat.c
+++ b/sound/ac97/snd_ac97_compat.c
@@ -69,7 +69,7 @@ struct snd_ac97 *snd_ac97_compat_alloc(struct ac97_codec_device *adev)
struct snd_ac97 *ac97;
int ret;
- ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL);
+ ac97 = kzalloc_obj(struct snd_ac97);
if (ac97 == NULL)
return ERR_PTR(-ENOMEM);