LCOV - code coverage report
Current view: top level - fs/btrfs - hash.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 16 0.0 %
Date: 2014-04-16 Functions: 0 3 0.0 %
Branches: 0 4 0.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright (C) 2014 Filipe David Borba Manana <fdmanana@gmail.com>
       3                 :            :  *
       4                 :            :  * This program is free software; you can redistribute it and/or
       5                 :            :  * modify it under the terms of the GNU General Public
       6                 :            :  * License v2 as published by the Free Software Foundation.
       7                 :            :  *
       8                 :            :  * This program is distributed in the hope that it will be useful,
       9                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      10                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      11                 :            :  * General Public License for more details.
      12                 :            :  */
      13                 :            : 
      14                 :            : #include <crypto/hash.h>
      15                 :            : #include <linux/err.h>
      16                 :            : #include "hash.h"
      17                 :            : 
      18                 :            : static struct crypto_shash *tfm;
      19                 :            : 
      20                 :          0 : int __init btrfs_hash_init(void)
      21                 :            : {
      22                 :          0 :         tfm = crypto_alloc_shash("crc32c", 0, 0);
      23         [ #  # ]:          0 :         if (IS_ERR(tfm))
      24                 :          0 :                 return PTR_ERR(tfm);
      25                 :            : 
      26                 :            :         return 0;
      27                 :            : }
      28                 :            : 
      29                 :          0 : void btrfs_hash_exit(void)
      30                 :            : {
      31                 :          0 :         crypto_free_shash(tfm);
      32                 :          0 : }
      33                 :            : 
      34                 :          0 : u32 btrfs_crc32c(u32 crc, const void *address, unsigned int length)
      35                 :            : {
      36                 :            :         struct {
      37                 :            :                 struct shash_desc shash;
      38                 :          0 :                 char ctx[crypto_shash_descsize(tfm)];
      39                 :          0 :         } desc;
      40                 :            :         int err;
      41                 :            : 
      42                 :          0 :         desc.shash.tfm = tfm;
      43                 :          0 :         desc.shash.flags = 0;
      44                 :          0 :         *(u32 *)desc.ctx = crc;
      45                 :            : 
      46                 :          0 :         err = crypto_shash_update(&desc.shash, address, length);
      47         [ #  # ]:          0 :         BUG_ON(err);
      48                 :            : 
      49                 :          0 :         return *(u32 *)desc.ctx;
      50                 :            : }

Generated by: LCOV version 1.9