linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 3/4 v2] lib: add crc16_le helper
@ 2010-08-18 12:01 Florian Fainelli
  2010-08-18 15:43 ` Joakim Tjernlund
  0 siblings, 1 reply; 7+ messages in thread
From: Florian Fainelli @ 2010-08-18 12:01 UTC (permalink / raw)
  To: linux-mtd, Artem Bityutskiy, Brian Norris, Matthieu CASTET,
	Maxime Bizon
  Cc: David Woodhouse

This patch adds a crc16_le helper function to lib/crc16.c

Signed-off-by: Matthieu CASTET <matthieu.castet@parrot.com>
Signed-off-by: Florian Fainelli <ffainelli@freebox.fr>
--
diff --git a/include/linux/crc16.h b/include/linux/crc16.h
index 9443c08..6c1c61f 100644
--- a/include/linux/crc16.h
+++ b/include/linux/crc16.h
@@ -26,5 +26,7 @@ static inline u16 crc16_byte(u16 crc, const u8 data)
 	return (crc >> 8) ^ crc16_table[(crc ^ data) & 0xff];
 }
 
+extern u16 crc16_le(u16 crc, const u8 *buffer, size_t len);
+
 #endif /* __CRC16_H */
 
diff --git a/lib/crc16.c b/lib/crc16.c
index 8737b08..ec4a95c 100644
--- a/lib/crc16.c
+++ b/lib/crc16.c
@@ -62,6 +62,18 @@ u16 crc16(u16 crc, u8 const *buffer, size_t len)
 }
 EXPORT_SYMBOL(crc16);
 
+u16 crc16_le(u16 crc, u8 const *p, size_t len)
+{
+	int i;
+	while (len--) {
+		crc ^= *p++ << 8;
+		for (i = 0; i < 8; i++)
+			crc = (crc << 1) ^ ((crc & 0x8000) ? 0x8005 : 0);
+	}
+	return crc;
+}
+EXPORT_SYMBOL(crc16_le);
+
 MODULE_DESCRIPTION("CRC16 calculations");
 MODULE_LICENSE("GPL");
 

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2010-08-20  7:25 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-18 12:01 [PATCH 3/4 v2] lib: add crc16_le helper Florian Fainelli
2010-08-18 15:43 ` Joakim Tjernlund
2010-08-18 16:10   ` Matthieu CASTET
2010-08-18 16:34     ` Joakim Tjernlund
2010-08-19  7:42       ` Matthieu CASTET
2010-08-19  9:41         ` Joakim Tjernlund
2010-08-20  7:24           ` Florian Fainelli

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).