Commit 3664d169 authored by Andrey Panin's avatar Andrey Panin Committed by Linus Torvalds

[PATCH] fix CRC16 misnaming

As pointed by Thomas Sailer, crc16.c module contains CRC16-CCITT (x^16 + x^12
+ x^5 + 1) implementation, not IBM CRC16 (x^16 + x^15 + x^2 + 1) one.  Looks
like we need to rename it accordingly and this patchset does exactly this.
Signed-off-by: default avatarAndrey Panin <pazke@donpac.ru>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 161cd3dd
#ifndef _LINUX_CRC_CCITT_H
#define _LINUX_CRC_CCITT_H
#include <linux/types.h>
extern u16 const crc_ccitt_table[256];
extern u16 crc_ccitt(u16 crc, const u8 *buffer, size_t len);
static inline u16 crc_ccitt_byte(u16 crc, const u8 c)
{
return (crc >> 8) ^ crc_ccitt_table[(crc ^ c) & 0xff];
}
#endif /* _LINUX_CRC_CCITT_H */
#ifndef _LINUX_CRC16_H
#define _LINUX_CRC16_H
#include <linux/types.h>
extern u16 const crc16_table[256];
extern u16 crc16(u16 crc, const u8 *buffer, size_t len);
static inline u16 crc16_byte(u16 crc, const u8 c)
{
return (crc >> 8) ^ crc16_table[(crc ^ c) & 0xff];
}
#endif /* _LINUX_CRC16_H */
......@@ -4,13 +4,13 @@
menu "Library routines"
config CRC16
tristate "CRC16 functions"
config CRC_CCITT
tristate "CRC-CCITT functions"
help
This option is provided for the case where no in-kernel-tree
modules require CRC16 functions, but a module built outside the
kernel tree does. Such modules that use library CRC16 functions
require M here.
modules require CRC-CCITT functions, but a module built outside
the kernel tree does. Such modules that use library CRC-CCITT
functions require M here.
config CRC32
tristate "CRC32 functions"
......
......@@ -18,7 +18,7 @@ ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
lib-y += dec_and_lock.o
endif
obj-$(CONFIG_CRC16) += crc16.o
obj-$(CONFIG_CRC_CCITT) += crc-ccitt.o
obj-$(CONFIG_CRC32) += crc32.o
obj-$(CONFIG_LIBCRC32C) += libcrc32c.o
......
/*
* linux/lib/crc16.c
* linux/lib/crc-ccitt.c
*
* This source code is licensed under the GNU General Public License,
* Version 2. See the file COPYING for more details.
......@@ -7,7 +7,7 @@
#include <linux/types.h>
#include <linux/module.h>
#include <linux/crc16.h>
#include <linux/crc-ccitt.h>
/*
* This mysterious table is just the CRC of each possible byte. It can be
......@@ -15,7 +15,7 @@
* be seen in entry 128, 0x8408. This corresponds to x^0 + x^5 + x^12.
* Add the implicit x^16, and you have the standard CRC-CCITT.
*/
u16 const crc16_table[256] = {
u16 const crc_ccitt_table[256] = {
0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
......@@ -49,21 +49,21 @@ u16 const crc16_table[256] = {
0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
};
EXPORT_SYMBOL(crc16_table);
EXPORT_SYMBOL(crc_ccitt_table);
/**
* crc16 - recompute the CRC for the data buffer
* crc_ccitt - recompute the CRC for the data buffer
* @crc - previous CRC value
* @buffer - data pointer
* @len - number of bytes in the buffer
*/
u16 crc16(u16 crc, u8 const *buffer, size_t len)
u16 crc_ccitt(u16 crc, u8 const *buffer, size_t len)
{
while (len--)
crc = crc16_byte(crc, *buffer++);
crc = crc_ccitt_byte(crc, *buffer++);
return crc;
}
EXPORT_SYMBOL(crc16);
EXPORT_SYMBOL(crc_ccitt);
MODULE_DESCRIPTION("CRC16 calculations");
MODULE_DESCRIPTION("CRC-CCITT calculations");
MODULE_LICENSE("GPL");
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment