Commit 15996eea authored by Alasdair G. Kergon's avatar Alasdair G. Kergon Committed by Linus Torvalds

[PATCH] device-mapper: dm-crypt tidy-ups

Small dm-crypt tidy-ups:
- Use unsigned consistently
- Simplify crypt_iv_plain memset
- Use DMEMIT macro
Signed-Off-By: default avatarAlasdair G Kergon <agk@redhat.com>
Signed-Off-By: default avatarChristophe Saout <christophe@saout.de>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 2c8833a3
...@@ -40,8 +40,8 @@ struct convert_context { ...@@ -40,8 +40,8 @@ struct convert_context {
struct bio *bio_out; struct bio *bio_out;
unsigned int offset_in; unsigned int offset_in;
unsigned int offset_out; unsigned int offset_out;
int idx_in; unsigned int idx_in;
int idx_out; unsigned int idx_out;
sector_t sector; sector_t sector;
int write; int write;
}; };
...@@ -64,11 +64,12 @@ struct crypt_config { ...@@ -64,11 +64,12 @@ struct crypt_config {
/* /*
* crypto related data * crypto related data
*/ */
struct crypto_tfm *tfm;
sector_t iv_offset;
int (*iv_generator)(struct crypt_config *cc, u8 *iv, sector_t sector); int (*iv_generator)(struct crypt_config *cc, u8 *iv, sector_t sector);
int iv_size; sector_t iv_offset;
int key_size; unsigned int iv_size;
struct crypto_tfm *tfm;
unsigned int key_size;
u8 key[0]; u8 key[0];
}; };
...@@ -97,10 +98,8 @@ static void mempool_free_page(void *page, void *data) ...@@ -97,10 +98,8 @@ static void mempool_free_page(void *page, void *data)
*/ */
static int crypt_iv_plain(struct crypt_config *cc, u8 *iv, sector_t sector) static int crypt_iv_plain(struct crypt_config *cc, u8 *iv, sector_t sector)
{ {
memset(iv, 0, cc->iv_size);
*(u32 *)iv = cpu_to_le32(sector & 0xffffffff); *(u32 *)iv = cpu_to_le32(sector & 0xffffffff);
if (cc->iv_size > sizeof(u32) / sizeof(u8))
memset(iv + (sizeof(u32) / sizeof(u8)), 0,
cc->iv_size - (sizeof(u32) / sizeof(u8)));
return 0; return 0;
} }
...@@ -200,13 +199,13 @@ static int crypt_convert(struct crypt_config *cc, ...@@ -200,13 +199,13 @@ static int crypt_convert(struct crypt_config *cc,
*/ */
static struct bio * static struct bio *
crypt_alloc_buffer(struct crypt_config *cc, unsigned int size, crypt_alloc_buffer(struct crypt_config *cc, unsigned int size,
struct bio *base_bio, int *bio_vec_idx) struct bio *base_bio, unsigned int *bio_vec_idx)
{ {
struct bio *bio; struct bio *bio;
int nr_iovecs = dm_div_up(size, PAGE_SIZE); unsigned int nr_iovecs = dm_div_up(size, PAGE_SIZE);
int gfp_mask = GFP_NOIO | __GFP_HIGHMEM; int gfp_mask = GFP_NOIO | __GFP_HIGHMEM;
int flags = current->flags; unsigned long flags = current->flags;
int i; unsigned int i;
/* /*
* Tell VM to act less aggressively and fail earlier. * Tell VM to act less aggressively and fail earlier.
...@@ -280,9 +279,8 @@ crypt_alloc_buffer(struct crypt_config *cc, unsigned int size, ...@@ -280,9 +279,8 @@ crypt_alloc_buffer(struct crypt_config *cc, unsigned int size,
static void crypt_free_buffer_pages(struct crypt_config *cc, static void crypt_free_buffer_pages(struct crypt_config *cc,
struct bio *bio, unsigned int bytes) struct bio *bio, unsigned int bytes)
{ {
unsigned int start, end; unsigned int i, start, end;
struct bio_vec *bv; struct bio_vec *bv;
int i;
/* /*
* This is ugly, but Jens Axboe thinks that using bi_idx in the * This is ugly, but Jens Axboe thinks that using bi_idx in the
...@@ -366,11 +364,11 @@ static void kcryptd_queue_io(struct crypt_io *io) ...@@ -366,11 +364,11 @@ static void kcryptd_queue_io(struct crypt_io *io)
/* /*
* Decode key from its hex representation * Decode key from its hex representation
*/ */
static int crypt_decode_key(u8 *key, char *hex, int size) static int crypt_decode_key(u8 *key, char *hex, unsigned int size)
{ {
char buffer[3]; char buffer[3];
char *endp; char *endp;
int i; unsigned int i;
buffer[2] = '\0'; buffer[2] = '\0';
...@@ -393,9 +391,9 @@ static int crypt_decode_key(u8 *key, char *hex, int size) ...@@ -393,9 +391,9 @@ static int crypt_decode_key(u8 *key, char *hex, int size)
/* /*
* Encode key into its hex representation * Encode key into its hex representation
*/ */
static void crypt_encode_key(char *hex, u8 *key, int size) static void crypt_encode_key(char *hex, u8 *key, unsigned int size)
{ {
int i; unsigned int i;
for(i = 0; i < size; i++) { for(i = 0; i < size; i++) {
sprintf(hex, "%02x", *key); sprintf(hex, "%02x", *key);
...@@ -415,8 +413,8 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv) ...@@ -415,8 +413,8 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
char *tmp; char *tmp;
char *cipher; char *cipher;
char *mode; char *mode;
int crypto_flags; unsigned int crypto_flags;
int key_size; unsigned int key_size;
if (argc != 5) { if (argc != 5) {
ti->error = PFX "Not enough arguments"; ti->error = PFX "Not enough arguments";
...@@ -577,7 +575,8 @@ static int crypt_endio(struct bio *bio, unsigned int done, int error) ...@@ -577,7 +575,8 @@ static int crypt_endio(struct bio *bio, unsigned int done, int error)
static inline struct bio * static inline struct bio *
crypt_clone(struct crypt_config *cc, struct crypt_io *io, struct bio *bio, crypt_clone(struct crypt_config *cc, struct crypt_io *io, struct bio *bio,
sector_t sector, int *bvec_idx, struct convert_context *ctx) sector_t sector, unsigned int *bvec_idx,
struct convert_context *ctx)
{ {
struct bio *clone; struct bio *clone;
...@@ -630,7 +629,7 @@ static int crypt_map(struct dm_target *ti, struct bio *bio, ...@@ -630,7 +629,7 @@ static int crypt_map(struct dm_target *ti, struct bio *bio,
struct bio *clone; struct bio *clone;
unsigned int remaining = bio->bi_size; unsigned int remaining = bio->bi_size;
sector_t sector = bio->bi_sector - ti->begin; sector_t sector = bio->bi_sector - ti->begin;
int bvec_idx = 0; unsigned int bvec_idx = 0;
io->target = ti; io->target = ti;
io->bio = bio; io->bio = bio;
...@@ -693,7 +692,7 @@ static int crypt_status(struct dm_target *ti, status_type_t type, ...@@ -693,7 +692,7 @@ static int crypt_status(struct dm_target *ti, status_type_t type,
char buffer[32]; char buffer[32];
const char *cipher; const char *cipher;
const char *mode = NULL; const char *mode = NULL;
int offset; unsigned int sz = 0;
switch (type) { switch (type) {
case STATUSTYPE_INFO: case STATUSTYPE_INFO:
...@@ -714,25 +713,23 @@ static int crypt_status(struct dm_target *ti, status_type_t type, ...@@ -714,25 +713,23 @@ static int crypt_status(struct dm_target *ti, status_type_t type,
BUG(); BUG();
} }
snprintf(result, maxlen, "%s-%s ", cipher, mode); DMEMIT("%s-%s ", cipher, mode);
offset = strlen(result);
if (cc->key_size > 0) { if (cc->key_size > 0) {
if ((maxlen - offset) < ((cc->key_size << 1) + 1)) if ((maxlen - sz) < ((cc->key_size << 1) + 1))
return -ENOMEM; return -ENOMEM;
crypt_encode_key(result + offset, cc->key, cc->key_size); crypt_encode_key(result + sz, cc->key, cc->key_size);
offset += cc->key_size << 1; sz += cc->key_size << 1;
} else { } else {
if (offset >= maxlen) if (sz >= maxlen)
return -ENOMEM; return -ENOMEM;
result[offset++] = '-'; result[sz++] = '-';
} }
format_dev_t(buffer, cc->dev->bdev->bd_dev); format_dev_t(buffer, cc->dev->bdev->bd_dev);
snprintf(result + offset, maxlen - offset, " " SECTOR_FORMAT DMEMIT(" " SECTOR_FORMAT " %s " SECTOR_FORMAT,
" %s " SECTOR_FORMAT, cc->iv_offset, cc->iv_offset, buffer, cc->start);
buffer, cc->start);
break; break;
} }
return 0; return 0;
......
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