Skip to content

Commit

Permalink
lib: introduce crc_t10dif_update()
Browse files Browse the repository at this point in the history
This introduces crc_t10dif_update() which enables to calculate CRC
for a block which straddles multiple SG elements by calling multiple
times.  This also converts crc_t10dif() to use crc_t10dif_update() as
they are almost same.

(remove extra function call in crc_t10dif() and crc_t10dif_update -
 Tim + Herbert)

Signed-off-by: Akinobu Mita <[email protected]>
Acked-by: Martin K. Petersen <[email protected]>
Cc: Tim Chen <[email protected]>
Cc: Herbert Xu <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: [email protected]
Cc: Nicholas Bellinger <[email protected]>
Cc: Sagi Grimberg <[email protected]>
Cc: "Martin K. Petersen" <[email protected]>
Cc: Christoph Hellwig <[email protected]>
Cc: "James E.J. Bottomley" <[email protected]>
Cc: [email protected]
Signed-off-by: Nicholas Bellinger <[email protected]>
  • Loading branch information
mita authored and Nicholas Bellinger committed May 31, 2015
1 parent 5835812 commit 10081fb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/linux/crc-t10dif.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
extern __u16 crc_t10dif_generic(__u16 crc, const unsigned char *buffer,
size_t len);
extern __u16 crc_t10dif(unsigned char const *, size_t);
extern __u16 crc_t10dif_update(__u16 crc, unsigned char const *, size_t);

#endif
12 changes: 9 additions & 3 deletions lib/crc-t10dif.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
static struct crypto_shash *crct10dif_tfm;
static struct static_key crct10dif_fallback __read_mostly;

__u16 crc_t10dif(const unsigned char *buffer, size_t len)
__u16 crc_t10dif_update(__u16 crc, const unsigned char *buffer, size_t len)
{
struct {
struct shash_desc shash;
Expand All @@ -28,17 +28,23 @@ __u16 crc_t10dif(const unsigned char *buffer, size_t len)
int err;

if (static_key_false(&crct10dif_fallback))
return crc_t10dif_generic(0, buffer, len);
return crc_t10dif_generic(crc, buffer, len);

desc.shash.tfm = crct10dif_tfm;
desc.shash.flags = 0;
*(__u16 *)desc.ctx = 0;
*(__u16 *)desc.ctx = crc;

err = crypto_shash_update(&desc.shash, buffer, len);
BUG_ON(err);

return *(__u16 *)desc.ctx;
}
EXPORT_SYMBOL(crc_t10dif_update);

__u16 crc_t10dif(const unsigned char *buffer, size_t len)
{
return crc_t10dif_update(0, buffer, len);
}
EXPORT_SYMBOL(crc_t10dif);

static int __init crc_t10dif_mod_init(void)
Expand Down

0 comments on commit 10081fb

Please sign in to comment.