]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/md/dm-exception-store.c
Merge branch 'topic/tlv-minmax' into for-linus
[karo-tx-linux.git] / drivers / md / dm-exception-store.c
index c3ae51584b12f52fc1de3434965329c43a930363..556acff3952fe450e73e4673f46bcac84b453a47 100644 (file)
@@ -171,6 +171,14 @@ static int set_chunk_size(struct dm_exception_store *store,
         */
        chunk_size_ulong = round_up(chunk_size_ulong, PAGE_SIZE >> 9);
 
+       return dm_exception_store_set_chunk_size(store, chunk_size_ulong,
+                                                error);
+}
+
+int dm_exception_store_set_chunk_size(struct dm_exception_store *store,
+                                     unsigned long chunk_size_ulong,
+                                     char **error)
+{
        /* Check chunk_size is a power of 2 */
        if (!is_power_of_2(chunk_size_ulong)) {
                *error = "Chunk size is not a power of 2";
@@ -183,6 +191,11 @@ static int set_chunk_size(struct dm_exception_store *store,
                return -EINVAL;
        }
 
+       if (chunk_size_ulong > INT_MAX >> SECTOR_SHIFT) {
+               *error = "Chunk size is too high";
+               return -EINVAL;
+       }
+
        store->chunk_size = chunk_size_ulong;
        store->chunk_mask = chunk_size_ulong - 1;
        store->chunk_shift = ffs(chunk_size_ulong) - 1;
@@ -195,7 +208,7 @@ int dm_exception_store_create(struct dm_target *ti, int argc, char **argv,
                              struct dm_exception_store **store)
 {
        int r = 0;
-       struct dm_exception_store_type *type;
+       struct dm_exception_store_type *type = NULL;
        struct dm_exception_store *tmp_store;
        char persistent;
 
@@ -211,12 +224,15 @@ int dm_exception_store_create(struct dm_target *ti, int argc, char **argv,
        }
 
        persistent = toupper(*argv[1]);
-       if (persistent != 'P' && persistent != 'N') {
+       if (persistent == 'P')
+               type = get_type("P");
+       else if (persistent == 'N')
+               type = get_type("N");
+       else {
                ti->error = "Persistent flag is not P or N";
                return -EINVAL;
        }
 
-       type = get_type(&persistent);
        if (!type) {
                ti->error = "Exception store type not recognised";
                r = -EINVAL;