Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6f3c3f0a authored by vignesh babu's avatar vignesh babu Committed by Alasdair G Kergon
Browse files

dm: use is_power_of_2



Replacing n & (n - 1) for power of 2 check by is_power_of_2(n)

Signed-off-by: default avatarvignesh babu <vignesh.babu@wipro.com>
Signed-off-by: default avatarAlasdair G Kergon <agk@redhat.com>
parent ae9da83f
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -19,6 +19,7 @@
#include <linux/time.h>
#include <linux/time.h>
#include <linux/vmalloc.h>
#include <linux/vmalloc.h>
#include <linux/workqueue.h>
#include <linux/workqueue.h>
#include <linux/log2.h>


#define DM_MSG_PREFIX "raid1"
#define DM_MSG_PREFIX "raid1"
#define DM_IO_PAGES 64
#define DM_IO_PAGES 64
@@ -995,7 +996,7 @@ static void free_context(struct mirror_set *ms, struct dm_target *ti,


static inline int _check_region_size(struct dm_target *ti, uint32_t size)
static inline int _check_region_size(struct dm_target *ti, uint32_t size)
{
{
	return !(size % (PAGE_SIZE >> 9) || (size & (size - 1)) ||
	return !(size % (PAGE_SIZE >> 9) || !is_power_of_2(size) ||
		 size > ti->len);
		 size > ti->len);
}
}


+2 −1
Original line number Original line Diff line number Diff line
@@ -17,6 +17,7 @@
#include <linux/module.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/slab.h>
#include <linux/vmalloc.h>
#include <linux/vmalloc.h>
#include <linux/log2.h>


#include "dm-snap.h"
#include "dm-snap.h"
#include "dm-bio-list.h"
#include "dm-bio-list.h"
@@ -415,7 +416,7 @@ static int set_chunk_size(struct dm_snapshot *s, const char *chunk_size_arg,
	chunk_size = round_up(chunk_size, PAGE_SIZE >> 9);
	chunk_size = round_up(chunk_size, PAGE_SIZE >> 9);


	/* Check chunk_size is a power of 2 */
	/* Check chunk_size is a power of 2 */
	if (chunk_size & (chunk_size - 1)) {
	if (!is_power_of_2(chunk_size)) {
		*error = "Chunk size is not a power of 2";
		*error = "Chunk size is not a power of 2";
		return -EINVAL;
		return -EINVAL;
	}
	}
+2 −1
Original line number Original line Diff line number Diff line
@@ -11,6 +11,7 @@
#include <linux/blkdev.h>
#include <linux/blkdev.h>
#include <linux/bio.h>
#include <linux/bio.h>
#include <linux/slab.h>
#include <linux/slab.h>
#include <linux/log2.h>


#define DM_MSG_PREFIX "striped"
#define DM_MSG_PREFIX "striped"


@@ -99,7 +100,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
	/*
	/*
	 * chunk_size is a power of two
	 * chunk_size is a power of two
	 */
	 */
	if (!chunk_size || (chunk_size & (chunk_size - 1)) ||
	if (!is_power_of_2(chunk_size) ||
	    (chunk_size < (PAGE_SIZE >> SECTOR_SHIFT))) {
	    (chunk_size < (PAGE_SIZE >> SECTOR_SHIFT))) {
		ti->error = "Invalid chunk size";
		ti->error = "Invalid chunk size";
		return -EINVAL;
		return -EINVAL;