Commit 4c9309c0 authored by Alexey Dobriyan's avatar Alexey Dobriyan Committed by NeilBrown

md: convert to kstrto*()

Convert away from deprecated simple_strto*() functions.

Add "fit into sector_t" checks.
Signed-off-by: default avatarAlexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: default avatarNeilBrown <neilb@suse.de>
parent c31df25f
...@@ -2630,13 +2630,14 @@ errors_show(struct md_rdev *rdev, char *page) ...@@ -2630,13 +2630,14 @@ errors_show(struct md_rdev *rdev, char *page)
static ssize_t static ssize_t
errors_store(struct md_rdev *rdev, const char *buf, size_t len) errors_store(struct md_rdev *rdev, const char *buf, size_t len)
{ {
char *e; unsigned int n;
unsigned long n = simple_strtoul(buf, &e, 10); int rv;
if (*buf && (*e == 0 || *e == '\n')) {
atomic_set(&rdev->corrected_errors, n); rv = kstrtouint(buf, 10, &n);
return len; if (rv < 0)
} return rv;
return -EINVAL; atomic_set(&rdev->corrected_errors, n);
return len;
} }
static struct rdev_sysfs_entry rdev_errors = static struct rdev_sysfs_entry rdev_errors =
__ATTR(errors, S_IRUGO|S_IWUSR, errors_show, errors_store); __ATTR(errors, S_IRUGO|S_IWUSR, errors_show, errors_store);
...@@ -2653,13 +2654,16 @@ slot_show(struct md_rdev *rdev, char *page) ...@@ -2653,13 +2654,16 @@ slot_show(struct md_rdev *rdev, char *page)
static ssize_t static ssize_t
slot_store(struct md_rdev *rdev, const char *buf, size_t len) slot_store(struct md_rdev *rdev, const char *buf, size_t len)
{ {
char *e; int slot;
int err; int err;
int slot = simple_strtoul(buf, &e, 10);
if (strncmp(buf, "none", 4)==0) if (strncmp(buf, "none", 4)==0)
slot = -1; slot = -1;
else if (e==buf || (*e && *e!= '\n')) else {
return -EINVAL; err = kstrtouint(buf, 10, (unsigned int *)&slot);
if (err < 0)
return err;
}
if (rdev->mddev->pers && slot == -1) { if (rdev->mddev->pers && slot == -1) {
/* Setting 'slot' on an active array requires also /* Setting 'slot' on an active array requires also
* updating the 'rd%d' link, and communicating * updating the 'rd%d' link, and communicating
...@@ -3544,12 +3548,12 @@ layout_show(struct mddev *mddev, char *page) ...@@ -3544,12 +3548,12 @@ layout_show(struct mddev *mddev, char *page)
static ssize_t static ssize_t
layout_store(struct mddev *mddev, const char *buf, size_t len) layout_store(struct mddev *mddev, const char *buf, size_t len)
{ {
char *e; unsigned int n;
unsigned long n = simple_strtoul(buf, &e, 10);
int err; int err;
if (!*buf || (*e && *e != '\n')) err = kstrtouint(buf, 10, &n);
return -EINVAL; if (err < 0)
return err;
err = mddev_lock(mddev); err = mddev_lock(mddev);
if (err) if (err)
return err; return err;
...@@ -3593,12 +3597,12 @@ static int update_raid_disks(struct mddev *mddev, int raid_disks); ...@@ -3593,12 +3597,12 @@ static int update_raid_disks(struct mddev *mddev, int raid_disks);
static ssize_t static ssize_t
raid_disks_store(struct mddev *mddev, const char *buf, size_t len) raid_disks_store(struct mddev *mddev, const char *buf, size_t len)
{ {
char *e; unsigned int n;
int err; int err;
unsigned long n = simple_strtoul(buf, &e, 10);
if (!*buf || (*e && *e != '\n')) err = kstrtouint(buf, 10, &n);
return -EINVAL; if (err < 0)
return err;
err = mddev_lock(mddev); err = mddev_lock(mddev);
if (err) if (err)
...@@ -3645,12 +3649,12 @@ chunk_size_show(struct mddev *mddev, char *page) ...@@ -3645,12 +3649,12 @@ chunk_size_show(struct mddev *mddev, char *page)
static ssize_t static ssize_t
chunk_size_store(struct mddev *mddev, const char *buf, size_t len) chunk_size_store(struct mddev *mddev, const char *buf, size_t len)
{ {
unsigned long n;
int err; int err;
char *e;
unsigned long n = simple_strtoul(buf, &e, 10);
if (!*buf || (*e && *e != '\n')) err = kstrtoul(buf, 10, &n);
return -EINVAL; if (err < 0)
return err;
err = mddev_lock(mddev); err = mddev_lock(mddev);
if (err) if (err)
...@@ -3688,19 +3692,24 @@ resync_start_show(struct mddev *mddev, char *page) ...@@ -3688,19 +3692,24 @@ resync_start_show(struct mddev *mddev, char *page)
static ssize_t static ssize_t
resync_start_store(struct mddev *mddev, const char *buf, size_t len) resync_start_store(struct mddev *mddev, const char *buf, size_t len)
{ {
unsigned long long n;
int err; int err;
char *e;
unsigned long long n = simple_strtoull(buf, &e, 10); if (cmd_match(buf, "none"))
n = MaxSector;
else {
err = kstrtoull(buf, 10, &n);
if (err < 0)
return err;
if (n != (sector_t)n)
return -EINVAL;
}
err = mddev_lock(mddev); err = mddev_lock(mddev);
if (err) if (err)
return err; return err;
if (mddev->pers && !test_bit(MD_RECOVERY_FROZEN, &mddev->recovery)) if (mddev->pers && !test_bit(MD_RECOVERY_FROZEN, &mddev->recovery))
err = -EBUSY; err = -EBUSY;
else if (cmd_match(buf, "none"))
n = MaxSector;
else if (!*buf || (*e && *e != '\n'))
err = -EINVAL;
if (!err) { if (!err) {
mddev->recovery_cp = n; mddev->recovery_cp = n;
...@@ -3936,14 +3945,14 @@ max_corrected_read_errors_show(struct mddev *mddev, char *page) { ...@@ -3936,14 +3945,14 @@ max_corrected_read_errors_show(struct mddev *mddev, char *page) {
static ssize_t static ssize_t
max_corrected_read_errors_store(struct mddev *mddev, const char *buf, size_t len) max_corrected_read_errors_store(struct mddev *mddev, const char *buf, size_t len)
{ {
char *e; unsigned int n;
unsigned long n = simple_strtoul(buf, &e, 10); int rv;
if (*buf && (*e == 0 || *e == '\n')) { rv = kstrtouint(buf, 10, &n);
atomic_set(&mddev->max_corr_read_errors, n); if (rv < 0)
return len; return rv;
} atomic_set(&mddev->max_corr_read_errors, n);
return -EINVAL; return len;
} }
static struct md_sysfs_entry max_corr_read_errors = static struct md_sysfs_entry max_corr_read_errors =
...@@ -4300,15 +4309,18 @@ sync_min_show(struct mddev *mddev, char *page) ...@@ -4300,15 +4309,18 @@ sync_min_show(struct mddev *mddev, char *page)
static ssize_t static ssize_t
sync_min_store(struct mddev *mddev, const char *buf, size_t len) sync_min_store(struct mddev *mddev, const char *buf, size_t len)
{ {
int min; unsigned int min;
char *e; int rv;
if (strncmp(buf, "system", 6)==0) { if (strncmp(buf, "system", 6)==0) {
mddev->sync_speed_min = 0; min = 0;
return len; } else {
rv = kstrtouint(buf, 10, &min);
if (rv < 0)
return rv;
if (min == 0)
return -EINVAL;
} }
min = simple_strtoul(buf, &e, 10);
if (buf == e || (*e && *e != '\n') || min <= 0)
return -EINVAL;
mddev->sync_speed_min = min; mddev->sync_speed_min = min;
return len; return len;
} }
...@@ -4326,15 +4338,18 @@ sync_max_show(struct mddev *mddev, char *page) ...@@ -4326,15 +4338,18 @@ sync_max_show(struct mddev *mddev, char *page)
static ssize_t static ssize_t
sync_max_store(struct mddev *mddev, const char *buf, size_t len) sync_max_store(struct mddev *mddev, const char *buf, size_t len)
{ {
int max; unsigned int max;
char *e; int rv;
if (strncmp(buf, "system", 6)==0) { if (strncmp(buf, "system", 6)==0) {
mddev->sync_speed_max = 0; max = 0;
return len; } else {
rv = kstrtouint(buf, 10, &max);
if (rv < 0)
return rv;
if (max == 0)
return -EINVAL;
} }
max = simple_strtoul(buf, &e, 10);
if (buf == e || (*e && *e != '\n') || max <= 0)
return -EINVAL;
mddev->sync_speed_max = max; mddev->sync_speed_max = max;
return len; return len;
} }
...@@ -4517,12 +4532,13 @@ suspend_lo_show(struct mddev *mddev, char *page) ...@@ -4517,12 +4532,13 @@ suspend_lo_show(struct mddev *mddev, char *page)
static ssize_t static ssize_t
suspend_lo_store(struct mddev *mddev, const char *buf, size_t len) suspend_lo_store(struct mddev *mddev, const char *buf, size_t len)
{ {
char *e; unsigned long long old, new;
unsigned long long new = simple_strtoull(buf, &e, 10);
unsigned long long old;
int err; int err;
if (buf == e || (*e && *e != '\n')) err = kstrtoull(buf, 10, &new);
if (err < 0)
return err;
if (new != (sector_t)new)
return -EINVAL; return -EINVAL;
err = mddev_lock(mddev); err = mddev_lock(mddev);
...@@ -4559,12 +4575,13 @@ suspend_hi_show(struct mddev *mddev, char *page) ...@@ -4559,12 +4575,13 @@ suspend_hi_show(struct mddev *mddev, char *page)
static ssize_t static ssize_t
suspend_hi_store(struct mddev *mddev, const char *buf, size_t len) suspend_hi_store(struct mddev *mddev, const char *buf, size_t len)
{ {
char *e; unsigned long long old, new;
unsigned long long new = simple_strtoull(buf, &e, 10);
unsigned long long old;
int err; int err;
if (buf == e || (*e && *e != '\n')) err = kstrtoull(buf, 10, &new);
if (err < 0)
return err;
if (new != (sector_t)new)
return -EINVAL; return -EINVAL;
err = mddev_lock(mddev); err = mddev_lock(mddev);
...@@ -4606,11 +4623,13 @@ static ssize_t ...@@ -4606,11 +4623,13 @@ static ssize_t
reshape_position_store(struct mddev *mddev, const char *buf, size_t len) reshape_position_store(struct mddev *mddev, const char *buf, size_t len)
{ {
struct md_rdev *rdev; struct md_rdev *rdev;
char *e; unsigned long long new;
int err; int err;
unsigned long long new = simple_strtoull(buf, &e, 10);
if (buf == e || (*e && *e != '\n')) err = kstrtoull(buf, 10, &new);
if (err < 0)
return err;
if (new != (sector_t)new)
return -EINVAL; return -EINVAL;
err = mddev_lock(mddev); err = mddev_lock(mddev);
if (err) if (err)
...@@ -9013,13 +9032,7 @@ static int get_ro(char *buffer, struct kernel_param *kp) ...@@ -9013,13 +9032,7 @@ static int get_ro(char *buffer, struct kernel_param *kp)
} }
static int set_ro(const char *val, struct kernel_param *kp) static int set_ro(const char *val, struct kernel_param *kp)
{ {
char *e; return kstrtouint(val, 10, (unsigned int *)&start_readonly);
int num = simple_strtoul(val, &e, 10);
if (*val && (*e == '\0' || *e == '\n')) {
start_readonly = num;
return 0;
}
return -EINVAL;
} }
module_param_call(start_ro, set_ro, get_ro, NULL, S_IRUSR|S_IWUSR); module_param_call(start_ro, set_ro, get_ro, NULL, S_IRUSR|S_IWUSR);
......
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