[Devel] [PATCH vz7 v2 5/7] ub stat: commnad check helper introduced
Stanislav Kinsburskiy
skinsbursky at odin.com
Thu Oct 1 06:38:38 PDT 2015
From: Stanislav Kinsburskiy <skinsbursky at parallels.com>
Signed-off-by: Stanislav Kinsburskiy <skinsbursky at parallels.com>
---
kernel/bc/statd.c | 22 +++++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)
diff --git a/kernel/bc/statd.c b/kernel/bc/statd.c
index b421ac1..db9f294 100644
--- a/kernel/bc/statd.c
+++ b/kernel/bc/statd.c
@@ -224,12 +224,29 @@ int ubstat_alloc_store(struct user_beancounter *ub)
}
EXPORT_SYMBOL(ubstat_alloc_store);
+static int ubstat_check_cmd(long cmd)
+{
+ switch (UBSTAT_CMD(cmd)) {
+ case UBSTAT_READ_ONE:
+ if (UBSTAT_PARMID(cmd) >= UB_RESOURCES)
+ break;
+ case UBSTAT_READ_ALL:
+ case UBSTAT_READ_FULL:
+ return 0;
+ }
+ return -EINVAL;
+}
+
static int ubstat_get_stat(struct user_beancounter *ub, long cmd,
void __user *buf, long size)
{
void *kbuf;
int retval;
+ retval = ubstat_check_cmd(cmd);
+ if (retval)
+ return retval;
+
kbuf = (void *)__get_free_page(GFP_KERNEL);
if (kbuf == NULL)
return -ENOMEM;
@@ -241,9 +258,6 @@ static int ubstat_get_stat(struct user_beancounter *ub, long cmd,
spin_lock(&ubs_notify_lock);
switch (UBSTAT_CMD(cmd)) {
case UBSTAT_READ_ONE:
- retval = -EINVAL;
- if (UBSTAT_PARMID(cmd) >= UB_RESOURCES)
- break;
retval = ubstat_do_read_one(ub,
UBSTAT_PARMID(cmd), kbuf);
break;
@@ -255,6 +269,8 @@ static int ubstat_get_stat(struct user_beancounter *ub, long cmd,
break;
default:
retval = -EINVAL;
+ __WARN_printf("%s: we shouldn't get there\ncmd: %ld\n",
+ __func__, UBSTAT_CMD(cmd));
}
spin_unlock(&ubs_notify_lock);
More information about the Devel
mailing list