[S390] cio: Use strict_strtoul() for attributes.

Make parsing of attribute writes handle incorrect input better.

Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
This commit is contained in:
Cornelia Huck
2008-04-30 13:38:33 +02:00
committed by Martin Schwidefsky
parent 0ff5ce7f30
commit 2f97220231
5 changed files with 35 additions and 18 deletions

View File

@@ -318,7 +318,7 @@ ccwgroup_online_store (struct device *dev, struct device_attribute *attr, const
{ {
struct ccwgroup_device *gdev; struct ccwgroup_device *gdev;
struct ccwgroup_driver *gdrv; struct ccwgroup_driver *gdrv;
unsigned int value; unsigned long value;
int ret; int ret;
gdev = to_ccwgroupdev(dev); gdev = to_ccwgroupdev(dev);
@@ -329,7 +329,9 @@ ccwgroup_online_store (struct device *dev, struct device_attribute *attr, const
if (!try_module_get(gdrv->owner)) if (!try_module_get(gdrv->owner))
return -EINVAL; return -EINVAL;
value = simple_strtoul(buf, NULL, 0); ret = strict_strtoul(buf, 0, &value);
if (ret)
goto out;
ret = count; ret = count;
if (value == 1) if (value == 1)
ccwgroup_set_online(gdev); ccwgroup_set_online(gdev);
@@ -337,6 +339,7 @@ ccwgroup_online_store (struct device *dev, struct device_attribute *attr, const
ccwgroup_set_offline(gdev); ccwgroup_set_offline(gdev);
else else
ret = -EINVAL; ret = -EINVAL;
out:
module_put(gdrv->owner); module_put(gdrv->owner);
return ret; return ret;
} }

View File

@@ -1219,16 +1219,21 @@ static ssize_t cmb_enable_store(struct device *dev,
{ {
struct ccw_device *cdev; struct ccw_device *cdev;
int ret; int ret;
unsigned long val;
ret = strict_strtoul(buf, 16, &val);
if (ret)
return ret;
cdev = to_ccwdev(dev); cdev = to_ccwdev(dev);
switch (buf[0]) { switch (val) {
case '0': case 0:
ret = disable_cmf(cdev); ret = disable_cmf(cdev);
if (ret) if (ret)
dev_info(&cdev->dev, "disable_cmf failed (%d)\n", ret); dev_info(&cdev->dev, "disable_cmf failed (%d)\n", ret);
break; break;
case '1': case 1:
ret = enable_cmf(cdev); ret = enable_cmf(cdev);
if (ret && ret != -EBUSY) if (ret && ret != -EBUSY)
dev_info(&cdev->dev, "enable_cmf failed (%d)\n", ret); dev_info(&cdev->dev, "enable_cmf failed (%d)\n", ret);

View File

@@ -705,13 +705,17 @@ css_cm_enable_store(struct device *dev, struct device_attribute *attr,
{ {
struct channel_subsystem *css = to_css(dev); struct channel_subsystem *css = to_css(dev);
int ret; int ret;
unsigned long val;
ret = strict_strtoul(buf, 16, &val);
if (ret)
return ret;
mutex_lock(&css->mutex); mutex_lock(&css->mutex);
switch (buf[0]) { switch (val) {
case '0': case 0:
ret = css->cm_enabled ? chsc_secm(css, 0) : 0; ret = css->cm_enabled ? chsc_secm(css, 0) : 0;
break; break;
case '1': case 1:
ret = css->cm_enabled ? 0 : chsc_secm(css, 1); ret = css->cm_enabled ? 0 : chsc_secm(css, 1);
break; break;
default: default:

View File

@@ -512,8 +512,8 @@ static ssize_t online_store (struct device *dev, struct device_attribute *attr,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct ccw_device *cdev = to_ccwdev(dev); struct ccw_device *cdev = to_ccwdev(dev);
int i, force; int force, ret;
char *tmp; unsigned long i;
if (atomic_cmpxchg(&cdev->private->onoff, 0, 1) != 0) if (atomic_cmpxchg(&cdev->private->onoff, 0, 1) != 0)
return -EAGAIN; return -EAGAIN;
@@ -525,25 +525,30 @@ static ssize_t online_store (struct device *dev, struct device_attribute *attr,
if (!strncmp(buf, "force\n", count)) { if (!strncmp(buf, "force\n", count)) {
force = 1; force = 1;
i = 1; i = 1;
ret = 0;
} else { } else {
force = 0; force = 0;
i = simple_strtoul(buf, &tmp, 16); ret = strict_strtoul(buf, 16, &i);
} }
if (ret)
goto out;
switch (i) { switch (i) {
case 0: case 0:
online_store_handle_offline(cdev); online_store_handle_offline(cdev);
ret = count;
break; break;
case 1: case 1:
online_store_handle_online(cdev, force); online_store_handle_online(cdev, force);
ret = count;
break; break;
default: default:
count = -EINVAL; ret = -EINVAL;
} }
out:
if (cdev->drv) if (cdev->drv)
module_put(cdev->drv->owner); module_put(cdev->drv->owner);
atomic_set(&cdev->private->onoff, 0); atomic_set(&cdev->private->onoff, 0);
return count; return ret;
} }
static ssize_t static ssize_t

View File

@@ -3663,11 +3663,11 @@ qdio_performance_stats_show(struct bus_type *bus, char *buf)
static ssize_t static ssize_t
qdio_performance_stats_store(struct bus_type *bus, const char *buf, size_t count) qdio_performance_stats_store(struct bus_type *bus, const char *buf, size_t count)
{ {
char *tmp; unsigned long i;
int i; int ret;
i = simple_strtoul(buf, &tmp, 16); ret = strict_strtoul(buf, 16, &i);
if ((i == 0) || (i == 1)) { if (!ret && ((i == 0) || (i == 1))) {
if (i == qdio_performance_stats) if (i == qdio_performance_stats)
return count; return count;
qdio_performance_stats = i; qdio_performance_stats = i;