[PATCH 06/16] mtd: Introduce mtd_check_pattern

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Sascha Hauer <s.hauer@xxxxxxxxxxxxxx>
---
 drivers/mtd/core.c      | 19 +++++++++++++++++++
 include/linux/mtd/mtd.h |  1 +
 2 files changed, 20 insertions(+)

diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c
index ff53a4a..dcf94bf 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 4374882..18d8866 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
-- 
2.7.0


_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux