Merge tag 'gpio-v3.13-3' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw...
[linux-2.6.git] / drivers / clk / clk-devres.c
blob8f571548870f4b46b37854b3a6ebf90105f68154
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License version 2 as
4 * published by the Free Software Foundation.
5 */
7 #include <linux/clk.h>
8 #include <linux/device.h>
9 #include <linux/export.h>
10 #include <linux/gfp.h>
12 static void devm_clk_release(struct device *dev, void *res)
14 clk_put(*(struct clk **)res);
17 struct clk *devm_clk_get(struct device *dev, const char *id)
19 struct clk **ptr, *clk;
21 ptr = devres_alloc(devm_clk_release, sizeof(*ptr), GFP_KERNEL);
22 if (!ptr)
23 return ERR_PTR(-ENOMEM);
25 clk = clk_get(dev, id);
26 if (!IS_ERR(clk)) {
27 *ptr = clk;
28 devres_add(dev, ptr);
29 } else {
30 devres_free(ptr);
33 return clk;
35 EXPORT_SYMBOL(devm_clk_get);
37 static int devm_clk_match(struct device *dev, void *res, void *data)
39 struct clk **c = res;
40 if (!c || !*c) {
41 WARN_ON(!c || !*c);
42 return 0;
44 return *c == data;
47 void devm_clk_put(struct device *dev, struct clk *clk)
49 int ret;
51 ret = devres_release(dev, devm_clk_release, devm_clk_match, clk);
53 WARN_ON(ret);
55 EXPORT_SYMBOL(devm_clk_put);