aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md/dm-exception-store.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/md/dm-exception-store.c')
-rw-r--r--drivers/md/dm-exception-store.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/drivers/md/dm-exception-store.c b/drivers/md/dm-exception-store.c
index e5de7627c52d..932d1b123143 100644
--- a/drivers/md/dm-exception-store.c
+++ b/drivers/md/dm-exception-store.c
@@ -155,7 +155,8 @@ static int set_chunk_size(struct dm_exception_store *store,
155 char *value; 155 char *value;
156 156
157 chunk_size_ulong = simple_strtoul(chunk_size_arg, &value, 10); 157 chunk_size_ulong = simple_strtoul(chunk_size_arg, &value, 10);
158 if (*chunk_size_arg == '\0' || *value != '\0') { 158 if (*chunk_size_arg == '\0' || *value != '\0' ||
159 chunk_size_ulong > UINT_MAX) {
159 *error = "Invalid chunk size"; 160 *error = "Invalid chunk size";
160 return -EINVAL; 161 return -EINVAL;
161 } 162 }
@@ -171,34 +172,35 @@ static int set_chunk_size(struct dm_exception_store *store,
171 */ 172 */
172 chunk_size_ulong = round_up(chunk_size_ulong, PAGE_SIZE >> 9); 173 chunk_size_ulong = round_up(chunk_size_ulong, PAGE_SIZE >> 9);
173 174
174 return dm_exception_store_set_chunk_size(store, chunk_size_ulong, 175 return dm_exception_store_set_chunk_size(store,
176 (unsigned) chunk_size_ulong,
175 error); 177 error);
176} 178}
177 179
178int dm_exception_store_set_chunk_size(struct dm_exception_store *store, 180int dm_exception_store_set_chunk_size(struct dm_exception_store *store,
179 unsigned long chunk_size_ulong, 181 unsigned chunk_size,
180 char **error) 182 char **error)
181{ 183{
182 /* Check chunk_size is a power of 2 */ 184 /* Check chunk_size is a power of 2 */
183 if (!is_power_of_2(chunk_size_ulong)) { 185 if (!is_power_of_2(chunk_size)) {
184 *error = "Chunk size is not a power of 2"; 186 *error = "Chunk size is not a power of 2";
185 return -EINVAL; 187 return -EINVAL;
186 } 188 }
187 189
188 /* Validate the chunk size against the device block size */ 190 /* Validate the chunk size against the device block size */
189 if (chunk_size_ulong % (bdev_logical_block_size(store->cow->bdev) >> 9)) { 191 if (chunk_size % (bdev_logical_block_size(store->cow->bdev) >> 9)) {
190 *error = "Chunk size is not a multiple of device blocksize"; 192 *error = "Chunk size is not a multiple of device blocksize";
191 return -EINVAL; 193 return -EINVAL;
192 } 194 }
193 195
194 if (chunk_size_ulong > INT_MAX >> SECTOR_SHIFT) { 196 if (chunk_size > INT_MAX >> SECTOR_SHIFT) {
195 *error = "Chunk size is too high"; 197 *error = "Chunk size is too high";
196 return -EINVAL; 198 return -EINVAL;
197 } 199 }
198 200
199 store->chunk_size = chunk_size_ulong; 201 store->chunk_size = chunk_size;
200 store->chunk_mask = chunk_size_ulong - 1; 202 store->chunk_mask = chunk_size - 1;
201 store->chunk_shift = ffs(chunk_size_ulong) - 1; 203 store->chunk_shift = ffs(chunk_size) - 1;
202 204
203 return 0; 205 return 0;
204} 206}