Commit ab29c480 authored by Julian Wiedmann's avatar Julian Wiedmann Committed by David S. Miller

s390/qeth: replace deprecated simple_stroul()

Convert the remaining occurences in sysfs code to kstrtouint().

While at it move some input parsing out of locked sections, replace an
open-coded clamp() and remove some unnecessary run-time checks for
ipatoe->mask_bits that are already enforced when creating the object.
Signed-off-by: default avatarJulian Wiedmann <jwi@linux.ibm.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent bcdfdf00
...@@ -195,8 +195,8 @@ struct qeth_vnicc_info { ...@@ -195,8 +195,8 @@ struct qeth_vnicc_info {
#define QETH_IN_BUF_SIZE_DEFAULT 65536 #define QETH_IN_BUF_SIZE_DEFAULT 65536
#define QETH_IN_BUF_COUNT_DEFAULT 64 #define QETH_IN_BUF_COUNT_DEFAULT 64
#define QETH_IN_BUF_COUNT_HSDEFAULT 128 #define QETH_IN_BUF_COUNT_HSDEFAULT 128
#define QETH_IN_BUF_COUNT_MIN 8 #define QETH_IN_BUF_COUNT_MIN 8U
#define QETH_IN_BUF_COUNT_MAX 128 #define QETH_IN_BUF_COUNT_MAX 128U
#define QETH_MAX_BUFFER_ELEMENTS(card) ((card)->qdio.in_buf_size >> 12) #define QETH_MAX_BUFFER_ELEMENTS(card) ((card)->qdio.in_buf_size >> 12)
#define QETH_IN_BUF_REQUEUE_THRESHOLD(card) \ #define QETH_IN_BUF_REQUEUE_THRESHOLD(card) \
((card)->qdio.in_buf_pool.buf_count / 2) ((card)->qdio.in_buf_pool.buf_count / 2)
......
...@@ -103,21 +103,21 @@ static ssize_t qeth_dev_portno_store(struct device *dev, ...@@ -103,21 +103,21 @@ static ssize_t qeth_dev_portno_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count) struct device_attribute *attr, const char *buf, size_t count)
{ {
struct qeth_card *card = dev_get_drvdata(dev); struct qeth_card *card = dev_get_drvdata(dev);
char *tmp;
unsigned int portno, limit; unsigned int portno, limit;
int rc = 0; int rc = 0;
rc = kstrtouint(buf, 16, &portno);
if (rc)
return rc;
if (portno > QETH_MAX_PORTNO)
return -EINVAL;
mutex_lock(&card->conf_mutex); mutex_lock(&card->conf_mutex);
if (card->state != CARD_STATE_DOWN) { if (card->state != CARD_STATE_DOWN) {
rc = -EPERM; rc = -EPERM;
goto out; goto out;
} }
portno = simple_strtoul(buf, &tmp, 16);
if (portno > QETH_MAX_PORTNO) {
rc = -EINVAL;
goto out;
}
limit = (card->ssqd.pcnt ? card->ssqd.pcnt - 1 : card->ssqd.pcnt); limit = (card->ssqd.pcnt ? card->ssqd.pcnt - 1 : card->ssqd.pcnt);
if (portno > limit) { if (portno > limit) {
rc = -EINVAL; rc = -EINVAL;
...@@ -248,19 +248,19 @@ static ssize_t qeth_dev_bufcnt_store(struct device *dev, ...@@ -248,19 +248,19 @@ static ssize_t qeth_dev_bufcnt_store(struct device *dev,
{ {
struct qeth_card *card = dev_get_drvdata(dev); struct qeth_card *card = dev_get_drvdata(dev);
unsigned int cnt; unsigned int cnt;
char *tmp;
int rc = 0; int rc = 0;
rc = kstrtouint(buf, 10, &cnt);
if (rc)
return rc;
mutex_lock(&card->conf_mutex); mutex_lock(&card->conf_mutex);
if (card->state != CARD_STATE_DOWN) { if (card->state != CARD_STATE_DOWN) {
rc = -EPERM; rc = -EPERM;
goto out; goto out;
} }
cnt = simple_strtoul(buf, &tmp, 10); cnt = clamp(cnt, QETH_IN_BUF_COUNT_MIN, QETH_IN_BUF_COUNT_MAX);
cnt = (cnt < QETH_IN_BUF_COUNT_MIN) ? QETH_IN_BUF_COUNT_MIN :
((cnt > QETH_IN_BUF_COUNT_MAX) ? QETH_IN_BUF_COUNT_MAX : cnt);
rc = qeth_resize_buffer_pool(card, cnt); rc = qeth_resize_buffer_pool(card, cnt);
out: out:
...@@ -341,18 +341,15 @@ static ssize_t qeth_dev_layer2_store(struct device *dev, ...@@ -341,18 +341,15 @@ static ssize_t qeth_dev_layer2_store(struct device *dev,
{ {
struct qeth_card *card = dev_get_drvdata(dev); struct qeth_card *card = dev_get_drvdata(dev);
struct net_device *ndev; struct net_device *ndev;
char *tmp;
int i, rc = 0;
enum qeth_discipline_id newdis; enum qeth_discipline_id newdis;
unsigned int input;
int rc;
mutex_lock(&card->discipline_mutex); rc = kstrtouint(buf, 16, &input);
if (card->state != CARD_STATE_DOWN) { if (rc)
rc = -EPERM; return rc;
goto out;
}
i = simple_strtoul(buf, &tmp, 16); switch (input) {
switch (i) {
case 0: case 0:
newdis = QETH_DISCIPLINE_LAYER3; newdis = QETH_DISCIPLINE_LAYER3;
break; break;
...@@ -360,7 +357,12 @@ static ssize_t qeth_dev_layer2_store(struct device *dev, ...@@ -360,7 +357,12 @@ static ssize_t qeth_dev_layer2_store(struct device *dev,
newdis = QETH_DISCIPLINE_LAYER2; newdis = QETH_DISCIPLINE_LAYER2;
break; break;
default: default:
rc = -EINVAL; return -EINVAL;
}
mutex_lock(&card->discipline_mutex);
if (card->state != CARD_STATE_DOWN) {
rc = -EPERM;
goto out; goto out;
} }
...@@ -551,20 +553,21 @@ static DEVICE_ATTR(hw_trap, 0644, qeth_hw_trap_show, ...@@ -551,20 +553,21 @@ static DEVICE_ATTR(hw_trap, 0644, qeth_hw_trap_show,
static ssize_t qeth_dev_blkt_store(struct qeth_card *card, static ssize_t qeth_dev_blkt_store(struct qeth_card *card,
const char *buf, size_t count, int *value, int max_value) const char *buf, size_t count, int *value, int max_value)
{ {
char *tmp; unsigned int input;
int i, rc = 0; int rc;
rc = kstrtouint(buf, 10, &input);
if (rc)
return rc;
if (input > max_value)
return -EINVAL;
mutex_lock(&card->conf_mutex); mutex_lock(&card->conf_mutex);
if (card->state != CARD_STATE_DOWN) { if (card->state != CARD_STATE_DOWN)
rc = -EPERM; rc = -EPERM;
goto out;
}
i = simple_strtoul(buf, &tmp, 10);
if (i <= max_value)
*value = i;
else else
rc = -EINVAL; *value = input;
out:
mutex_unlock(&card->conf_mutex); mutex_unlock(&card->conf_mutex);
return rc ? rc : count; return rc ? rc : count;
} }
......
...@@ -96,7 +96,7 @@ struct qeth_ipato_entry { ...@@ -96,7 +96,7 @@ struct qeth_ipato_entry {
struct list_head entry; struct list_head entry;
enum qeth_prot_versions proto; enum qeth_prot_versions proto;
char addr[16]; char addr[16];
int mask_bits; unsigned int mask_bits;
}; };
extern const struct attribute_group *qeth_l3_attr_groups[]; extern const struct attribute_group *qeth_l3_attr_groups[];
...@@ -110,7 +110,7 @@ int qeth_l3_setrouting_v6(struct qeth_card *); ...@@ -110,7 +110,7 @@ int qeth_l3_setrouting_v6(struct qeth_card *);
int qeth_l3_add_ipato_entry(struct qeth_card *, struct qeth_ipato_entry *); int qeth_l3_add_ipato_entry(struct qeth_card *, struct qeth_ipato_entry *);
int qeth_l3_del_ipato_entry(struct qeth_card *card, int qeth_l3_del_ipato_entry(struct qeth_card *card,
enum qeth_prot_versions proto, u8 *addr, enum qeth_prot_versions proto, u8 *addr,
int mask_bits); unsigned int mask_bits);
void qeth_l3_update_ipato(struct qeth_card *card); void qeth_l3_update_ipato(struct qeth_card *card);
int qeth_l3_modify_hsuid(struct qeth_card *card, bool add); int qeth_l3_modify_hsuid(struct qeth_card *card, bool add);
int qeth_l3_modify_rxip_vipa(struct qeth_card *card, bool add, const u8 *ip, int qeth_l3_modify_rxip_vipa(struct qeth_card *card, bool add, const u8 *ip,
......
...@@ -105,11 +105,9 @@ static bool qeth_l3_is_addr_covered_by_ipato(struct qeth_card *card, ...@@ -105,11 +105,9 @@ static bool qeth_l3_is_addr_covered_by_ipato(struct qeth_card *card,
(ipatoe->proto == QETH_PROT_IPV4) ? (ipatoe->proto == QETH_PROT_IPV4) ?
4 : 16); 4 : 16);
if (addr->proto == QETH_PROT_IPV4) if (addr->proto == QETH_PROT_IPV4)
rc = !memcmp(addr_bits, ipatoe_bits, rc = !memcmp(addr_bits, ipatoe_bits, ipatoe->mask_bits);
min(32, ipatoe->mask_bits));
else else
rc = !memcmp(addr_bits, ipatoe_bits, rc = !memcmp(addr_bits, ipatoe_bits, ipatoe->mask_bits);
min(128, ipatoe->mask_bits));
if (rc) if (rc)
break; break;
} }
...@@ -561,7 +559,7 @@ int qeth_l3_add_ipato_entry(struct qeth_card *card, ...@@ -561,7 +559,7 @@ int qeth_l3_add_ipato_entry(struct qeth_card *card,
int qeth_l3_del_ipato_entry(struct qeth_card *card, int qeth_l3_del_ipato_entry(struct qeth_card *card,
enum qeth_prot_versions proto, u8 *addr, enum qeth_prot_versions proto, u8 *addr,
int mask_bits) unsigned int mask_bits)
{ {
struct qeth_ipato_entry *ipatoe, *tmp; struct qeth_ipato_entry *ipatoe, *tmp;
int rc = -ENOENT; int rc = -ENOENT;
......
...@@ -407,10 +407,9 @@ static ssize_t qeth_l3_dev_ipato_add4_show(struct device *dev, ...@@ -407,10 +407,9 @@ static ssize_t qeth_l3_dev_ipato_add4_show(struct device *dev,
} }
static int qeth_l3_parse_ipatoe(const char *buf, enum qeth_prot_versions proto, static int qeth_l3_parse_ipatoe(const char *buf, enum qeth_prot_versions proto,
u8 *addr, int *mask_bits) u8 *addr, unsigned int *mask_bits)
{ {
const char *start; char *sep;
char *sep, *tmp;
int rc; int rc;
/* Expected input pattern: %addr/%mask */ /* Expected input pattern: %addr/%mask */
...@@ -424,13 +423,13 @@ static int qeth_l3_parse_ipatoe(const char *buf, enum qeth_prot_versions proto, ...@@ -424,13 +423,13 @@ static int qeth_l3_parse_ipatoe(const char *buf, enum qeth_prot_versions proto,
if (rc) if (rc)
return rc; return rc;
start = sep + 1; rc = kstrtouint(sep + 1, 10, mask_bits);
*mask_bits = simple_strtoul(start, &tmp, 10); if (rc)
if (!strlen(start) || return rc;
(tmp == start) ||
(*mask_bits > ((proto == QETH_PROT_IPV4) ? 32 : 128))) { if (*mask_bits > ((proto == QETH_PROT_IPV4) ? 32 : 128))
return -EINVAL; return -EINVAL;
}
return 0; return 0;
} }
...@@ -438,8 +437,8 @@ static ssize_t qeth_l3_dev_ipato_add_store(const char *buf, size_t count, ...@@ -438,8 +437,8 @@ static ssize_t qeth_l3_dev_ipato_add_store(const char *buf, size_t count,
struct qeth_card *card, enum qeth_prot_versions proto) struct qeth_card *card, enum qeth_prot_versions proto)
{ {
struct qeth_ipato_entry *ipatoe; struct qeth_ipato_entry *ipatoe;
unsigned int mask_bits;
u8 addr[16]; u8 addr[16];
int mask_bits;
int rc = 0; int rc = 0;
rc = qeth_l3_parse_ipatoe(buf, proto, addr, &mask_bits); rc = qeth_l3_parse_ipatoe(buf, proto, addr, &mask_bits);
...@@ -476,8 +475,8 @@ static QETH_DEVICE_ATTR(ipato_add4, add4, 0644, ...@@ -476,8 +475,8 @@ static QETH_DEVICE_ATTR(ipato_add4, add4, 0644,
static ssize_t qeth_l3_dev_ipato_del_store(const char *buf, size_t count, static ssize_t qeth_l3_dev_ipato_del_store(const char *buf, size_t count,
struct qeth_card *card, enum qeth_prot_versions proto) struct qeth_card *card, enum qeth_prot_versions proto)
{ {
unsigned int mask_bits;
u8 addr[16]; u8 addr[16];
int mask_bits;
int rc = 0; int rc = 0;
rc = qeth_l3_parse_ipatoe(buf, proto, addr, &mask_bits); rc = qeth_l3_parse_ipatoe(buf, proto, addr, &mask_bits);
......
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