Commit b4e274e9 authored by Joe Thornber's avatar Joe Thornber Committed by Greg Kroah-Hartman

[PATCH] dm: signed/unsigned audit

parent e1240137
......@@ -351,7 +351,8 @@ static int next_target(struct dm_target_spec *last, uint32_t next,
static int populate_table(struct dm_table *table, struct dm_ioctl *args)
{
int i = 0, r, first = 1;
int r, first = 1;
unsigned int i = 0;
struct dm_target_spec *spec;
char *params;
void *begin, *end;
......@@ -380,7 +381,8 @@ static int populate_table(struct dm_table *table, struct dm_ioctl *args)
}
r = dm_table_add_target(table, spec->target_type,
spec->sector_start, spec->length,
(sector_t) spec->sector_start,
(sector_t) spec->length,
params);
if (r) {
DMWARN("internal error adding target to table");
......@@ -558,7 +560,7 @@ static int create(struct dm_ioctl *param, struct dm_ioctl *user)
int r;
struct dm_table *t;
struct mapped_device *md;
int minor;
unsigned int minor = 0;
r = check_name(param->name);
if (r)
......@@ -574,8 +576,8 @@ static int create(struct dm_ioctl *param, struct dm_ioctl *user)
return r;
}
minor = (param->flags & DM_PERSISTENT_DEV_FLAG) ?
minor(to_kdev_t(param->dev)) : -1;
if (param->flags & DM_PERSISTENT_DEV_FLAG)
minor = minor(to_kdev_t(param->dev));
r = dm_create(minor, t, &md);
if (r) {
......@@ -584,7 +586,7 @@ static int create(struct dm_ioctl *param, struct dm_ioctl *user)
}
dm_table_put(t); /* md will have grabbed its own reference */
set_disk_ro(dm_disk(md), (param->flags & DM_READONLY_FLAG));
set_disk_ro(dm_disk(md), (param->flags & DM_READONLY_FLAG) ? 1 : 0);
r = dm_hash_insert(param->name, *param->uuid ? param->uuid : NULL, md);
dm_put(md);
......@@ -595,9 +597,9 @@ static int create(struct dm_ioctl *param, struct dm_ioctl *user)
* Build up the status struct for each target
*/
static int __status(struct mapped_device *md, struct dm_ioctl *param,
char *outbuf, int *len)
char *outbuf, size_t *len)
{
int i, num_targets;
unsigned int i, num_targets;
struct dm_target_spec *spec;
char *outptr;
status_type_t type;
......@@ -657,7 +659,7 @@ static int __status(struct mapped_device *md, struct dm_ioctl *param,
static int get_status(struct dm_ioctl *param, struct dm_ioctl *user)
{
struct mapped_device *md;
int len = 0;
size_t len = 0;
int ret;
char *outbuf = NULL;
......@@ -738,7 +740,8 @@ static int wait_device_event(struct dm_ioctl *param, struct dm_ioctl *user)
*/
static int dep(struct dm_ioctl *param, struct dm_ioctl *user)
{
int count, r;
int r;
unsigned int count;
struct mapped_device *md;
struct list_head *tmp;
size_t len = 0;
......@@ -889,7 +892,7 @@ static int reload(struct dm_ioctl *param, struct dm_ioctl *user)
}
dm_table_put(t); /* md will have taken its own reference */
set_disk_ro(dm_disk(md), (param->flags & DM_READONLY_FLAG));
set_disk_ro(dm_disk(md), (param->flags & DM_READONLY_FLAG) ? 1 : 0);
dm_put(md);
r = info(param, user);
......@@ -945,7 +948,7 @@ static ioctl_fn lookup_ioctl(unsigned int cmd)
* As well as checking the version compatibility this always
* copies the kernel interface version out.
*/
static int check_version(int cmd, struct dm_ioctl *user)
static int check_version(unsigned int cmd, struct dm_ioctl *user)
{
uint32_t version[3];
int r = 0;
......@@ -1028,7 +1031,8 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
static int ctl_ioctl(struct inode *inode, struct file *file,
uint command, ulong u)
{
int r = 0, cmd;
int r = 0;
unsigned int cmd;
struct dm_ioctl *param;
struct dm_ioctl *user = (struct dm_ioctl *) u;
ioctl_fn fn = NULL;
......
......@@ -23,7 +23,7 @@ struct linear_c {
/*
* Construct a linear mapping: <dev_path> <offset>
*/
static int linear_ctr(struct dm_target *ti, int argc, char **argv)
static int linear_ctr(struct dm_target *ti, unsigned int argc, char **argv)
{
struct linear_c *lc;
......@@ -76,7 +76,7 @@ static int linear_map(struct dm_target *ti, struct bio *bio)
}
static int linear_status(struct dm_target *ti, status_type_t type,
char *result, int maxlen)
char *result, unsigned int maxlen)
{
struct linear_c *lc = (struct linear_c *) ti->private;
char b[BDEVNAME_SIZE];
......
......@@ -30,7 +30,7 @@ struct stripe_c {
struct stripe stripe[0];
};
static inline struct stripe_c *alloc_context(int stripes)
static inline struct stripe_c *alloc_context(unsigned int stripes)
{
size_t len;
......@@ -47,7 +47,7 @@ static inline struct stripe_c *alloc_context(int stripes)
* Parse a single <dev> <sector> pair
*/
static int get_stripe(struct dm_target *ti, struct stripe_c *sc,
int stripe, char **argv)
unsigned int stripe, char **argv)
{
sector_t start;
......@@ -91,14 +91,15 @@ static int multiple(sector_t a, sector_t b, sector_t *n)
* Construct a striped mapping.
* <number of stripes> <chunk size (2^^n)> [<dev_path> <offset>]+
*/
static int stripe_ctr(struct dm_target *ti, int argc, char **argv)
static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
{
struct stripe_c *sc;
sector_t width;
uint32_t stripes;
uint32_t chunk_size;
char *end;
int r, i;
int r;
unsigned int i;
if (argc < 2) {
ti->error = "dm-stripe: Not enough arguments";
......@@ -204,11 +205,11 @@ static int stripe_map(struct dm_target *ti, struct bio *bio)
}
static int stripe_status(struct dm_target *ti,
status_type_t type, char *result, int maxlen)
status_type_t type, char *result, unsigned int maxlen)
{
struct stripe_c *sc = (struct stripe_c *) ti->private;
int offset;
int i;
unsigned int i;
char b[BDEVNAME_SIZE];
switch (type) {
......
......@@ -23,12 +23,12 @@ struct dm_table {
atomic_t holders;
/* btree table */
int depth;
int counts[MAX_DEPTH]; /* in nodes */
unsigned int depth;
unsigned int counts[MAX_DEPTH]; /* in nodes */
sector_t *index[MAX_DEPTH];
int num_targets;
int num_allocated;
unsigned int num_targets;
unsigned int num_allocated;
sector_t *highs;
struct dm_target *targets;
......@@ -110,7 +110,7 @@ static void combine_restrictions_low(struct io_restrictions *lhs,
/*
* Calculate the index of the child node of the n'th node k'th key.
*/
static inline int get_child(int n, int k)
static inline unsigned int get_child(unsigned int n, unsigned int k)
{
return (n * CHILDREN_PER_NODE) + k;
}
......@@ -118,7 +118,8 @@ static inline int get_child(int n, int k)
/*
* Return the n'th node of level l from table t.
*/
static inline sector_t *get_node(struct dm_table *t, int l, int n)
static inline sector_t *get_node(struct dm_table *t,
unsigned int l, unsigned int n)
{
return t->index[l] + (n * KEYS_PER_NODE);
}
......@@ -127,7 +128,7 @@ static inline sector_t *get_node(struct dm_table *t, int l, int n)
* Return the highest key that you could lookup from the n'th
* node on level l of the btree.
*/
static sector_t high(struct dm_table *t, int l, int n)
static sector_t high(struct dm_table *t, unsigned int l, unsigned int n)
{
for (; l < t->depth - 1; l++)
n = get_child(n, CHILDREN_PER_NODE - 1);
......@@ -142,15 +143,15 @@ static sector_t high(struct dm_table *t, int l, int n)
* Fills in a level of the btree based on the highs of the level
* below it.
*/
static int setup_btree_index(int l, struct dm_table *t)
static int setup_btree_index(unsigned int l, struct dm_table *t)
{
int n, k;
unsigned int n, k;
sector_t *node;
for (n = 0; n < t->counts[l]; n++) {
for (n = 0U; n < t->counts[l]; n++) {
node = get_node(t, l, n);
for (k = 0; k < KEYS_PER_NODE; k++)
for (k = 0U; k < KEYS_PER_NODE; k++)
node[k] = high(t, l + 1, get_child(n, k));
}
......@@ -180,7 +181,7 @@ static void *dm_vcalloc(unsigned long nmemb, unsigned long elem_size)
* highs, and targets are managed as dynamic arrays during a
* table load.
*/
static int alloc_targets(struct dm_table *t, int num)
static int alloc_targets(struct dm_table *t, unsigned int num)
{
sector_t *n_highs;
struct dm_target *n_targets;
......@@ -248,7 +249,7 @@ static void free_devices(struct list_head *devices)
void table_destroy(struct dm_table *t)
{
int i;
unsigned int i;
DMWARN("destroying table");
......@@ -657,7 +658,8 @@ int dm_table_add_target(struct dm_table *t, const char *type,
static int setup_indexes(struct dm_table *t)
{
int i, total = 0;
int i;
unsigned int total = 0;
sector_t *indexes;
/* allocate the space for *all* the indexes */
......@@ -685,7 +687,8 @@ static int setup_indexes(struct dm_table *t)
*/
int dm_table_complete(struct dm_table *t)
{
int leaf_nodes, r = 0;
int r = 0;
unsigned int leaf_nodes;
/* how many indexes will the btree have ? */
leaf_nodes = div_up(t->num_targets, KEYS_PER_NODE);
......@@ -711,7 +714,7 @@ sector_t dm_table_get_size(struct dm_table *t)
return t->num_targets ? (t->highs[t->num_targets - 1] + 1) : 0;
}
struct dm_target *dm_table_get_target(struct dm_table *t, int index)
struct dm_target *dm_table_get_target(struct dm_table *t, unsigned int index)
{
if (index > t->num_targets)
return NULL;
......@@ -724,7 +727,7 @@ struct dm_target *dm_table_get_target(struct dm_table *t, int index)
*/
struct dm_target *dm_table_find_target(struct dm_table *t, sector_t sector)
{
int l, n = 0, k = 0;
unsigned int l, n = 0, k = 0;
sector_t *node;
for (l = 0; l < t->depth; l++) {
......
......@@ -146,7 +146,7 @@ int dm_unregister_target(struct target_type *t)
* io-err: always fails an io, useful for bringing
* up LVs that have holes in them.
*/
static int io_err_ctr(struct dm_target *ti, int argc, char **args)
static int io_err_ctr(struct dm_target *ti, unsigned int argc, char **args)
{
return 0;
}
......
......@@ -17,8 +17,8 @@
static const char *_name = DM_NAME;
#define MAX_DEVICES 1024
static int major = 0;
static int _major = 0;
static unsigned int major = 0;
static unsigned int _major = 0;
struct dm_io {
struct mapped_device *md;
......@@ -524,7 +524,7 @@ static int dm_request(request_queue_t *q, struct bio *bio)
static spinlock_t _minor_lock = SPIN_LOCK_UNLOCKED;
static unsigned long _minor_bits[MAX_DEVICES / BITS_PER_LONG];
static void free_minor(int minor)
static void free_minor(unsigned int minor)
{
spin_lock(&_minor_lock);
clear_bit(minor, _minor_bits);
......@@ -534,7 +534,7 @@ static void free_minor(int minor)
/*
* See if the device with a specific minor # is free.
*/
static int specific_minor(int minor)
static int specific_minor(unsigned int minor)
{
int r = -EBUSY;
......@@ -546,21 +546,23 @@ static int specific_minor(int minor)
spin_lock(&_minor_lock);
if (!test_and_set_bit(minor, _minor_bits))
r = minor;
r = 0;
spin_unlock(&_minor_lock);
return r;
}
static int next_free_minor(void)
static int next_free_minor(unsigned int *minor)
{
int minor, r = -EBUSY;
int r = -EBUSY;
unsigned int m;
spin_lock(&_minor_lock);
minor = find_first_zero_bit(_minor_bits, MAX_DEVICES);
if (minor != MAX_DEVICES) {
set_bit(minor, _minor_bits);
r = minor;
m = find_first_zero_bit(_minor_bits, MAX_DEVICES);
if (m != MAX_DEVICES) {
set_bit(m, _minor_bits);
*minor = m;
r = 0;
}
spin_unlock(&_minor_lock);
......@@ -570,8 +572,9 @@ static int next_free_minor(void)
/*
* Allocate and initialise a blank device with a given minor.
*/
static struct mapped_device *alloc_dev(int minor)
static struct mapped_device *alloc_dev(unsigned int minor)
{
int r;
struct mapped_device *md = kmalloc(sizeof(*md), GFP_KERNEL);
if (!md) {
......@@ -580,8 +583,8 @@ static struct mapped_device *alloc_dev(int minor)
}
/* get a minor number for the dev */
minor = (minor < 0) ? next_free_minor() : specific_minor(minor);
if (minor < 0) {
r = (minor < 0) ? next_free_minor(&minor) : specific_minor(minor);
if (r < 0) {
kfree(md);
return NULL;
}
......@@ -597,7 +600,7 @@ static struct mapped_device *alloc_dev(int minor)
md->io_pool = mempool_create(MIN_IOS, mempool_alloc_slab,
mempool_free_slab, _io_cache);
if (!md->io_pool) {
free_minor(md->disk->first_minor);
free_minor(minor);
kfree(md);
return NULL;
}
......@@ -605,7 +608,7 @@ static struct mapped_device *alloc_dev(int minor)
md->disk = alloc_disk(1);
if (!md->disk) {
mempool_destroy(md->io_pool);
free_minor(md->disk->first_minor);
free_minor(minor);
kfree(md);
return NULL;
}
......@@ -661,7 +664,8 @@ static void __unbind(struct mapped_device *md)
/*
* Constructor for a new device.
*/
int dm_create(int minor, struct dm_table *table, struct mapped_device **result)
int dm_create(unsigned int minor, struct dm_table *table,
struct mapped_device **result)
{
int r;
struct mapped_device *md;
......
......@@ -51,7 +51,8 @@ struct mapped_device;
* Functions for manipulating a struct mapped_device.
* Drop the reference with dm_put when you finish with the object.
*---------------------------------------------------------------*/
int dm_create(int minor, struct dm_table *table, struct mapped_device **md);
int dm_create(unsigned int minor, struct dm_table *table,
struct mapped_device **md);
/*
* Reference counting for md.
......@@ -96,7 +97,7 @@ int dm_table_add_target(struct dm_table *t, const char *type,
int dm_table_complete(struct dm_table *t);
void dm_table_event(struct dm_table *t);
sector_t dm_table_get_size(struct dm_table *t);
struct dm_target *dm_table_get_target(struct dm_table *t, int index);
struct dm_target *dm_table_get_target(struct dm_table *t, unsigned int index);
struct dm_target *dm_table_find_target(struct dm_table *t, sector_t sector);
void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q);
unsigned int dm_table_get_num_targets(struct dm_table *t);
......
......@@ -17,7 +17,8 @@ typedef enum { STATUSTYPE_INFO, STATUSTYPE_TABLE } status_type_t;
* In the constructor the target parameter will already have the
* table, type, begin and len fields filled in.
*/
typedef int (*dm_ctr_fn) (struct dm_target *target, int argc, char **argv);
typedef int (*dm_ctr_fn) (struct dm_target *target,
unsigned int argc, char **argv);
/*
* The destructor doesn't need to free the dm_target, just
......@@ -33,7 +34,7 @@ typedef void (*dm_dtr_fn) (struct dm_target *ti);
*/
typedef int (*dm_map_fn) (struct dm_target *ti, struct bio *bio);
typedef int (*dm_status_fn) (struct dm_target *ti, status_type_t status_type,
char *result, int maxlen);
char *result, unsigned int maxlen);
void dm_error(const char *message);
......
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