diff options
author | Dan Williams <dan.j.williams@intel.com> | 2016-01-05 10:50:23 +0300 |
---|---|---|
committer | Dan Williams <dan.j.williams@intel.com> | 2016-01-09 19:39:04 +0300 |
commit | 16263ff6c72eb4cc00aa287230144dda12ccad12 (patch) | |
tree | b92a29f5508d3dd5f494e4399bf0be799b93e319 /include/linux/badblocks.h | |
parent | 20a308f09e0d29ce6f5a4114cc476a998d569bfb (diff) |
block, badblocks: introduce devm_init_badblocks
Provide a devres interface for initializing a badblocks instance. The
pmem driver has several scenarios where it will be beneficial to have
this structure automatically freed when the device is disabled / fails
probe.
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Diffstat (limited to 'include/linux/badblocks.h')
-rw-r--r-- | include/linux/badblocks.h | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/include/linux/badblocks.h b/include/linux/badblocks.h index 2d98c026c57f..c3bdf8c59480 100644 --- a/include/linux/badblocks.h +++ b/include/linux/badblocks.h @@ -2,6 +2,7 @@ #define _LINUX_BADBLOCKS_H #include <linux/seqlock.h> +#include <linux/device.h> #include <linux/kernel.h> #include <linux/stddef.h> #include <linux/types.h> @@ -23,6 +24,7 @@ #define MAX_BADBLOCKS (PAGE_SIZE/8) struct badblocks { + struct device *dev; /* set by devm_init_badblocks */ int count; /* count of bad blocks */ int unacked_exist; /* there probably are unacknowledged * bad blocks. This is only cleared @@ -49,5 +51,15 @@ ssize_t badblocks_store(struct badblocks *bb, const char *page, size_t len, int unack); int badblocks_init(struct badblocks *bb, int enable); void badblocks_exit(struct badblocks *bb); - +struct device; +int devm_init_badblocks(struct device *dev, struct badblocks *bb); +static inline void devm_exit_badblocks(struct device *dev, struct badblocks *bb) +{ + if (bb->dev != dev) { + dev_WARN_ONCE(dev, 1, "%s: badblocks instance not associated\n", + __func__); + return; + } + badblocks_exit(bb); +} #endif |