diff options
-rw-r--r-- | drivers/mtd/core.c | 19 | ||||
-rw-r--r-- | include/linux/mtd/mtd.h | 1 |
2 files changed, 20 insertions, 0 deletions
diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c index ff53a4a1b6..dcf94bfc0d 100644 --- a/drivers/mtd/core.c +++ b/drivers/mtd/core.c @@ -74,6 +74,25 @@ int mtd_buf_all_ff(const void *buf, unsigned int len) return 1; } +/** + * mtd_buf_check_pattern - check if buffer contains only a certain byte pattern. + * @buf: buffer to check + * @patt: the pattern to check + * @size: buffer size in bytes + * + * This function returns %1 in there are only @patt bytes in @buf, and %0 if + * something else was also found. + */ +int mtd_buf_check_pattern(const void *buf, uint8_t patt, int size) +{ + int i; + + for (i = 0; i < size; i++) + if (((const uint8_t *)buf)[i] != patt) + return 0; + return 1; +} + static ssize_t mtd_op_read(struct cdev *cdev, void* buf, size_t count, loff_t offset, ulong flags) { diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index 4374882288..18d886649a 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -313,6 +313,7 @@ int mtd_block_markbad(struct mtd_info *mtd, loff_t ofs); int mtd_block_markgood(struct mtd_info *mtd, loff_t ofs); int mtd_buf_all_ff(const void *buf, unsigned int len); +int mtd_buf_check_pattern(const void *buf, uint8_t patt, int size); /* * Debugging macro and defines |