mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-12-29 09:16:33 +00:00
lib: parser: optimize match_NUMBER apis to use local array
Memory will be allocated to store substring_t in match_strdup(), which
means the caller of match_strdup() may need to be scheduled out to wait
for reclaiming memory. smatch complains that this can cuase sleeping in
an atoic context.
Using local array to store substring_t to remove the restriction.
Link: https://lkml.kernel.org/r/20230120032352.242767-1-lilingfeng3@huawei.com
Link: https://lore.kernel.org/all/20221104023938.2346986-5-yukuai1@huaweicloud.com/
Link: https://lkml.kernel.org/r/20230120032352.242767-1-lilingfeng3@huawei.com
Fixes: 2c06479884
("blk-iocost: don't release 'ioc->lock' while updating params")
Signed-off-by: Li Lingfeng <lilingfeng3@huawei.com>
Reported-by: Yu Kuai <yukuai1@huaweicloud.com>
Acked-by: Tejun Heo <tj@kernel.org>
Cc: BingJing Chang <bingjingc@synology.com>
Cc: Eric Biggers <ebiggers@google.com>
Cc: Hou Tao <houtao1@huawei.com>
Cc: James Smart <james.smart@broadcom.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: yangerkun <yangerkun@huawei.com>
Cc: Zhang Yi <yi.zhang@huawei.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
parent
badc28d492
commit
67222c4ba8
39
lib/parser.c
39
lib/parser.c
@ -11,6 +11,15 @@
|
|||||||
#include <linux/slab.h>
|
#include <linux/slab.h>
|
||||||
#include <linux/string.h>
|
#include <linux/string.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* max size needed by different bases to express U64
|
||||||
|
* HEX: "0xFFFFFFFFFFFFFFFF" --> 18
|
||||||
|
* DEC: "18446744073709551615" --> 20
|
||||||
|
* OCT: "01777777777777777777777" --> 23
|
||||||
|
* pick the max one to define NUMBER_BUF_LEN
|
||||||
|
*/
|
||||||
|
#define NUMBER_BUF_LEN 24
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* match_one - Determines if a string matches a simple pattern
|
* match_one - Determines if a string matches a simple pattern
|
||||||
* @s: the string to examine for presence of the pattern
|
* @s: the string to examine for presence of the pattern
|
||||||
@ -129,14 +138,12 @@ EXPORT_SYMBOL(match_token);
|
|||||||
static int match_number(substring_t *s, int *result, int base)
|
static int match_number(substring_t *s, int *result, int base)
|
||||||
{
|
{
|
||||||
char *endp;
|
char *endp;
|
||||||
char *buf;
|
char buf[NUMBER_BUF_LEN];
|
||||||
int ret;
|
int ret;
|
||||||
long val;
|
long val;
|
||||||
|
|
||||||
buf = match_strdup(s);
|
if (match_strlcpy(buf, s, NUMBER_BUF_LEN) >= NUMBER_BUF_LEN)
|
||||||
if (!buf)
|
return -ERANGE;
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
val = simple_strtol(buf, &endp, base);
|
val = simple_strtol(buf, &endp, base);
|
||||||
if (endp == buf)
|
if (endp == buf)
|
||||||
@ -145,7 +152,6 @@ static int match_number(substring_t *s, int *result, int base)
|
|||||||
ret = -ERANGE;
|
ret = -ERANGE;
|
||||||
else
|
else
|
||||||
*result = (int) val;
|
*result = (int) val;
|
||||||
kfree(buf);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,18 +169,15 @@ static int match_number(substring_t *s, int *result, int base)
|
|||||||
*/
|
*/
|
||||||
static int match_u64int(substring_t *s, u64 *result, int base)
|
static int match_u64int(substring_t *s, u64 *result, int base)
|
||||||
{
|
{
|
||||||
char *buf;
|
char buf[NUMBER_BUF_LEN];
|
||||||
int ret;
|
int ret;
|
||||||
u64 val;
|
u64 val;
|
||||||
|
|
||||||
buf = match_strdup(s);
|
if (match_strlcpy(buf, s, NUMBER_BUF_LEN) >= NUMBER_BUF_LEN)
|
||||||
if (!buf)
|
return -ERANGE;
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
ret = kstrtoull(buf, base, &val);
|
ret = kstrtoull(buf, base, &val);
|
||||||
if (!ret)
|
if (!ret)
|
||||||
*result = val;
|
*result = val;
|
||||||
kfree(buf);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,14 +209,12 @@ EXPORT_SYMBOL(match_int);
|
|||||||
*/
|
*/
|
||||||
int match_uint(substring_t *s, unsigned int *result)
|
int match_uint(substring_t *s, unsigned int *result)
|
||||||
{
|
{
|
||||||
int err = -ENOMEM;
|
char buf[NUMBER_BUF_LEN];
|
||||||
char *buf = match_strdup(s);
|
|
||||||
|
|
||||||
if (buf) {
|
if (match_strlcpy(buf, s, NUMBER_BUF_LEN) >= NUMBER_BUF_LEN)
|
||||||
err = kstrtouint(buf, 10, result);
|
return -ERANGE;
|
||||||
kfree(buf);
|
|
||||||
}
|
return kstrtouint(buf, 10, result);
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(match_uint);
|
EXPORT_SYMBOL(match_uint);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user