summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/core/devres.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/drivers/core/devres.c b/drivers/core/devres.c
index 49c270c57c..f235c1bcfd 100644
--- a/drivers/core/devres.c
+++ b/drivers/core/devres.c
@@ -194,3 +194,37 @@ void devres_release_all(struct udevice *dev)
{
release_nodes(dev, &dev->devres_head, false);
}
+
+/*
+ * Managed kmalloc/kfree
+ */
+static void devm_kmalloc_release(struct udevice *dev, void *res)
+{
+ /* noop */
+}
+
+static int devm_kmalloc_match(struct udevice *dev, void *res, void *data)
+{
+ return res == data;
+}
+
+void *devm_kmalloc(struct udevice *dev, size_t size, gfp_t gfp)
+{
+ void *data;
+
+ data = _devres_alloc(devm_kmalloc_release, size, gfp);
+ if (unlikely(!data))
+ return NULL;
+
+ devres_add(dev, data);
+
+ return data;
+}
+
+void devm_kfree(struct udevice *dev, void *p)
+{
+ int rc;
+
+ rc = devres_destroy(dev, devm_kmalloc_release, devm_kmalloc_match, p);
+ WARN_ON(rc);
+}
OpenPOWER on IntegriCloud