ALSA: hda - Add new GPU codec ID 0x10de0083 to snd-hda
[linux-2.6-block.git] / block / badblocks.c
index fabf6b64c2d17692b511336de3e113c18c3e95e6..7be53cb1cc3cebf3e9f5c30e004f6f74b50bfdbf 100644 (file)
@@ -17,6 +17,7 @@
 
 #include <linux/badblocks.h>
 #include <linux/seqlock.h>
+#include <linux/device.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/stddef.h>
@@ -522,24 +523,20 @@ ssize_t badblocks_store(struct badblocks *bb, const char *page, size_t len,
 }
 EXPORT_SYMBOL_GPL(badblocks_store);
 
-/**
- * badblocks_init() - initialize the badblocks structure
- * @bb:                the badblocks structure that holds all badblock information
- * @enable:    weather to enable badblocks accounting
- *
- * Return:
- *  0: success
- *  -ve errno: on error
- */
-int badblocks_init(struct badblocks *bb, int enable)
+static int __badblocks_init(struct device *dev, struct badblocks *bb,
+               int enable)
 {
+       bb->dev = dev;
        bb->count = 0;
        if (enable)
                bb->shift = 0;
        else
                bb->shift = -1;
-       bb->page = kzalloc(PAGE_SIZE, GFP_KERNEL);
-       if (bb->page == (u64 *)0) {
+       if (dev)
+               bb->page = devm_kzalloc(dev, PAGE_SIZE, GFP_KERNEL);
+       else
+               bb->page = kzalloc(PAGE_SIZE, GFP_KERNEL);
+       if (!bb->page) {
                bb->shift = -1;
                return -ENOMEM;
        }
@@ -547,15 +544,42 @@ int badblocks_init(struct badblocks *bb, int enable)
 
        return 0;
 }
+
+/**
+ * badblocks_init() - initialize the badblocks structure
+ * @bb:                the badblocks structure that holds all badblock information
+ * @enable:    weather to enable badblocks accounting
+ *
+ * Return:
+ *  0: success
+ *  -ve errno: on error
+ */
+int badblocks_init(struct badblocks *bb, int enable)
+{
+       return __badblocks_init(NULL, bb, enable);
+}
 EXPORT_SYMBOL_GPL(badblocks_init);
 
+int devm_init_badblocks(struct device *dev, struct badblocks *bb)
+{
+       if (!bb)
+               return -EINVAL;
+       return __badblocks_init(dev, bb, 1);
+}
+EXPORT_SYMBOL_GPL(devm_init_badblocks);
+
 /**
  * badblocks_exit() - free the badblocks structure
  * @bb:                the badblocks structure that holds all badblock information
  */
 void badblocks_exit(struct badblocks *bb)
 {
-       kfree(bb->page);
+       if (!bb)
+               return;
+       if (bb->dev)
+               devm_kfree(bb->dev, bb->page);
+       else
+               kfree(bb->page);
        bb->page = NULL;
 }
 EXPORT_SYMBOL_GPL(badblocks_exit);