#include <linux/module.h>
 #include <linux/init.h>
 #include <linux/async.h>
+#include <linux/cleanup.h>
 #include <linux/delay.h>
 #include <linux/pm.h>
 #include <linux/bitops.h>
        const struct snd_soc_dapm_widget *_widget,
        const char *prefix)
 {
-       struct snd_soc_dapm_widget *w;
-
-       w = kmemdup(_widget, sizeof(*_widget), GFP_KERNEL);
+       struct snd_soc_dapm_widget *w __free(kfree) = kmemdup(_widget,
+                                                             sizeof(*_widget),
+                                                             GFP_KERNEL);
        if (!w)
                return NULL;
 
                w->name = kasprintf(GFP_KERNEL, "%s %s", prefix, _widget->name);
        else
                w->name = kstrdup_const(_widget->name, GFP_KERNEL);
-       if (!w->name) {
-               kfree(w);
+       if (!w->name)
                return NULL;
-       }
 
        if (_widget->sname) {
                w->sname = kstrdup_const(_widget->sname, GFP_KERNEL);
                if (!w->sname) {
                        kfree_const(w->name);
-                       kfree(w);
                        return NULL;
                }
        }
-       return w;
+
+       return_ptr(w);
 }
 
 struct dapm_kcontrol_data {