summaryrefslogtreecommitdiffstats
path: root/kernel/params.c
diff options
context:
space:
mode:
authorSagi Grimberg <sagi@grimberg.me>2021-06-16 14:19:33 -0700
committerChristoph Hellwig <hch@lst.de>2021-08-16 14:42:22 +0200
commit2a14c9ae15a38148484a128b84bff7e9ffd90d68 (patch)
tree6ff98acb5e26d5bf21c4e644ef8348b7a2dd7acc /kernel/params.c
parent9ea9b9c48387edc101d56349492ad9c0492ff78d (diff)
downloadlinux-2a14c9ae15a38148484a128b84bff7e9ffd90d68.tar.gz
linux-2a14c9ae15a38148484a128b84bff7e9ffd90d68.tar.bz2
linux-2a14c9ae15a38148484a128b84bff7e9ffd90d68.zip
params: lift param_set_uint_minmax to common code
It is a useful helper hence move it to common code so others can enjoy it. Suggested-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com> Reviewed-by: Hannes Reinecke <hare@suse.com> Signed-off-by: Sagi Grimberg <sagi@grimberg.me> Signed-off-by: Christoph Hellwig <hch@lst.de>
Diffstat (limited to 'kernel/params.c')
-rw-r--r--kernel/params.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/kernel/params.c b/kernel/params.c
index 2daa2780a92c..8299bd764e42 100644
--- a/kernel/params.c
+++ b/kernel/params.c
@@ -243,6 +243,24 @@ STANDARD_PARAM_DEF(ulong, unsigned long, "%lu", kstrtoul);
STANDARD_PARAM_DEF(ullong, unsigned long long, "%llu", kstrtoull);
STANDARD_PARAM_DEF(hexint, unsigned int, "%#08x", kstrtouint);
+int param_set_uint_minmax(const char *val, const struct kernel_param *kp,
+ unsigned int min, unsigned int max)
+{
+ unsigned int num;
+ int ret;
+
+ if (!val)
+ return -EINVAL;
+ ret = kstrtouint(val, 0, &num);
+ if (ret)
+ return ret;
+ if (num < min || num > max)
+ return -EINVAL;
+ *((unsigned int *)kp->arg) = num;
+ return 0;
+}
+EXPORT_SYMBOL_GPL(param_set_uint_minmax);
+
int param_set_charp(const char *val, const struct kernel_param *kp)
{
if (strlen(val) > 1024) {