btrfs-progs: crypto: clean up types and includes for crc32c

There are some stale headers that we don't need and the int types are
using the kernel types and pull kerncompat.h. As this is a basic header
that should minimize dependencies use the standard int types.

Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Sterba 2023-02-14 22:45:54 +01:00
parent 076891943a
commit 6048ff5a47
2 changed files with 10 additions and 17 deletions

View File

@ -8,18 +8,11 @@
*
*/
#include "kerncompat.h"
#include "crypto/crc32c.h"
#include <inttypes.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>
#include "crypto/crc32c.h"
u32 __crc32c_le(u32 crc, unsigned char const *data, size_t length);
static u32 (*crc_function)(u32 crc, unsigned char const *data, size_t length) = __crc32c_le;
uint32_t __crc32c_le(uint32_t crc, unsigned char const *data, uint32_t length);
static uint32_t (*crc_function)(uint32_t crc, unsigned char const *data, uint32_t length) = __crc32c_le;
#ifdef __x86_64__
@ -45,7 +38,7 @@ static int crc32c_probed = 0;
static int crc32c_intel_available = 0;
static uint32_t crc32c_intel_le_hw_byte(uint32_t crc, unsigned char const *data,
unsigned long length)
uint32_t length)
{
while (length--) {
__asm__ __volatile__(
@ -63,7 +56,7 @@ static uint32_t crc32c_intel_le_hw_byte(uint32_t crc, unsigned char const *data,
* Steps through buffer one byte at at time, calculates reflected
* crc using table.
*/
static uint32_t crc32c_intel(u32 crc, unsigned char const *data, unsigned long length)
static uint32_t crc32c_intel(uint32_t crc, unsigned char const *data, uint32_t length)
{
unsigned int iquotient = length / SCALE_F;
unsigned int iremainder = length % SCALE_F;
@ -137,7 +130,7 @@ void crc32c_optimization_init(void)
* reflect output bytes = true
*/
static const u32 crc32c_table[256] = {
static const uint32_t crc32c_table[256] = {
0x00000000L, 0xF26B8303L, 0xE13B70F7L, 0x1350F3F4L,
0xC79A971FL, 0x35F1141CL, 0x26A1E7E8L, 0xD4CA64EBL,
0x8AD958CFL, 0x78B2DBCCL, 0x6BE22838L, 0x9989AB3BL,
@ -209,7 +202,7 @@ static const u32 crc32c_table[256] = {
* crc using table.
*/
u32 __crc32c_le(u32 crc, unsigned char const *data, size_t length)
uint32_t __crc32c_le(uint32_t crc, unsigned char const *data, uint32_t length)
{
while (length--)
crc =
@ -217,7 +210,7 @@ u32 __crc32c_le(u32 crc, unsigned char const *data, size_t length)
return crc;
}
u32 crc32c_le(u32 crc, unsigned char const *data, size_t length)
uint32_t crc32c_le(uint32_t crc, unsigned char const *data, uint32_t length)
{
/* Use by-byte access for unaligned buffers */
if ((unsigned long)data % sizeof(unsigned long))

View File

@ -19,9 +19,9 @@
#ifndef __CRC32C__
#define __CRC32C__
#include "kerncompat.h"
#include <inttypes.h>
u32 crc32c_le(u32 seed, unsigned char const *data, size_t length);
uint32_t crc32c_le(uint32_t seed, unsigned char const *data, uint32_t length);
void crc32c_optimization_init(void);
#define crc32c(seed, data, length) crc32c_le(seed, (unsigned char const *)data, length)