Fix misspellings of "system", "controller", "interrupt" and "necessary".
[linux-block.git] / drivers / md / dm-crypt.c
index ba952a032598c2411bb3f7ff793f6d00baec92bc..4a5849b551970391554738f43d72424badee898a 100644 (file)
@@ -112,7 +112,7 @@ static void clone_init(struct dm_crypt_io *, struct bio *);
  * Different IV generation algorithms:
  *
  * plain: the initial vector is the 32-bit little-endian version of the sector
- *        number, padded with zeros if neccessary.
+ *        number, padded with zeros if necessary.
  *
  * essiv: "encrypted sector|salt initial vector", the sector number is
  *        encrypted with the bulk cipher using a salt as key. The salt
@@ -441,33 +441,12 @@ static struct bio *crypt_alloc_buffer(struct dm_crypt_io *io, unsigned size)
        return clone;
 }
 
-static void crypt_free_buffer_pages(struct crypt_config *cc,
-                                    struct bio *clone, unsigned int bytes)
+static void crypt_free_buffer_pages(struct crypt_config *cc, struct bio *clone)
 {
-       unsigned int i, start, end;
+       unsigned int i;
        struct bio_vec *bv;
 
-       /*
-        * This is ugly, but Jens Axboe thinks that using bi_idx in the
-        * endio function is too dangerous at the moment, so I calculate the
-        * correct position using bi_vcnt and bi_size.
-        * The bv_offset and bv_len fields might already be modified but we
-        * know that we always allocated whole pages.
-        * A fix to the bi_idx issue in the kernel is in the works, so
-        * we will hopefully be able to revert to the cleaner solution soon.
-        */
-       i = clone->bi_vcnt - 1;
-       bv = bio_iovec_idx(clone, i);
-       end = (i << PAGE_SHIFT) + (bv->bv_offset + bv->bv_len) - clone->bi_size;
-       start = end - bytes;
-
-       start >>= PAGE_SHIFT;
-       if (!clone->bi_size)
-               end = clone->bi_vcnt;
-       else
-               end >>= PAGE_SHIFT;
-
-       for (i = start; i < end; i++) {
+       for (i = 0; i < clone->bi_vcnt; i++) {
                bv = bio_iovec_idx(clone, i);
                BUG_ON(!bv->bv_page);
                mempool_free(bv->bv_page, cc->page_pool);
@@ -489,7 +468,7 @@ static void dec_pending(struct dm_crypt_io *io, int error)
        if (!atomic_dec_and_test(&io->pending))
                return;
 
-       bio_endio(io->base_bio, io->base_bio->bi_size, io->error);
+       bio_endio(io->base_bio, io->error);
 
        mempool_free(io, cc->io_pool);
 }
@@ -509,25 +488,19 @@ static void kcryptd_queue_io(struct dm_crypt_io *io)
        queue_work(_kcryptd_workqueue, &io->work);
 }
 
-static int crypt_endio(struct bio *clone, unsigned int done, int error)
+static void crypt_endio(struct bio *clone, int error)
 {
        struct dm_crypt_io *io = clone->bi_private;
        struct crypt_config *cc = io->target->private;
        unsigned read_io = bio_data_dir(clone) == READ;
 
        /*
-        * free the processed pages, even if
-        * it's only a partially completed write
+        * free the processed pages
         */
-       if (!read_io)
-               crypt_free_buffer_pages(cc, clone, done);
-
-       /* keep going - not finished yet */
-       if (unlikely(clone->bi_size))
-               return 1;
-
-       if (!read_io)
+       if (!read_io) {
+               crypt_free_buffer_pages(cc, clone);
                goto out;
+       }
 
        if (unlikely(!bio_flagged(clone, BIO_UPTODATE))) {
                error = -EIO;
@@ -537,12 +510,11 @@ static int crypt_endio(struct bio *clone, unsigned int done, int error)
        bio_put(clone);
        io->post_process = 1;
        kcryptd_queue_io(io);
-       return 0;
+       return;
 
 out:
        bio_put(clone);
        dec_pending(io, error);
-       return error;
 }
 
 static void clone_init(struct dm_crypt_io *io, struct bio *clone)
@@ -615,7 +587,7 @@ static void process_write(struct dm_crypt_io *io)
                ctx.idx_out = 0;
 
                if (unlikely(crypt_convert(cc, &ctx) < 0)) {
-                       crypt_free_buffer_pages(cc, clone, clone->bi_size);
+                       crypt_free_buffer_pages(cc, clone);
                        bio_put(clone);
                        dec_pending(io, -EIO);
                        return;
@@ -920,6 +892,8 @@ static void crypt_dtr(struct dm_target *ti)
 {
        struct crypt_config *cc = (struct crypt_config *) ti->private;
 
+       flush_workqueue(_kcryptd_workqueue);
+
        bioset_free(cc->bs);
        mempool_destroy(cc->page_pool);
        mempool_destroy(cc->io_pool);