aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2012-04-01 17:38:43 -0400
committerTejun Heo <tj@kernel.org>2012-04-01 17:38:43 -0400
commit726fa6945e6e5f0389bf47a790e1df734a67de54 (patch)
tree7119107ef544ccde91bdd6a116b4bdabc15e4bbd
parent3a8b31d396b296df4b8594429d86d415d3409432 (diff)
blkcg: simplify blkg_conf_prep()
blkg_conf_prep() implements "MAJ:MIN VAL" parsing manually, which is unnecessary. Just use sscanf("%u:%u %llu"). This might not reject some malformed input (extra input at the end) but we don't care. Signed-off-by: Tejun Heo <tj@kernel.org>
-rw-r--r--block/blk-cgroup.c64
1 files changed, 10 insertions, 54 deletions
diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index 1e1ee2af7b5f..b07a501839e7 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -987,57 +987,16 @@ static int blkg_conf_prep(struct blkio_cgroup *blkcg, const char *input,
987{ 987{
988 struct gendisk *disk; 988 struct gendisk *disk;
989 struct blkio_group *blkg; 989 struct blkio_group *blkg;
990 char *buf, *s[4], *p, *major_s, *minor_s; 990 unsigned int major, minor;
991 unsigned long major, minor; 991 unsigned long long v;
992 int i = 0, ret = -EINVAL; 992 int part, ret;
993 int part;
994 dev_t dev;
995 u64 temp;
996 993
997 buf = kstrdup(input, GFP_KERNEL); 994 if (sscanf(input, "%u:%u %llu", &major, &minor, &v) != 3)
998 if (!buf) 995 return -EINVAL;
999 return -ENOMEM;
1000
1001 memset(s, 0, sizeof(s));
1002
1003 while ((p = strsep(&buf, " ")) != NULL) {
1004 if (!*p)
1005 continue;
1006
1007 s[i++] = p;
1008
1009 /* Prevent from inputing too many things */
1010 if (i == 3)
1011 break;
1012 }
1013
1014 if (i != 2)
1015 goto out;
1016
1017 p = strsep(&s[0], ":");
1018 if (p != NULL)
1019 major_s = p;
1020 else
1021 goto out;
1022
1023 minor_s = s[0];
1024 if (!minor_s)
1025 goto out;
1026
1027 if (strict_strtoul(major_s, 10, &major))
1028 goto out;
1029
1030 if (strict_strtoul(minor_s, 10, &minor))
1031 goto out;
1032
1033 dev = MKDEV(major, minor);
1034
1035 if (strict_strtoull(s[1], 10, &temp))
1036 goto out;
1037 996
1038 disk = get_gendisk(dev, &part); 997 disk = get_gendisk(MKDEV(major, minor), &part);
1039 if (!disk || part) 998 if (!disk || part)
1040 goto out; 999 return -EINVAL;
1041 1000
1042 rcu_read_lock(); 1001 rcu_read_lock();
1043 1002
@@ -1059,16 +1018,13 @@ static int blkg_conf_prep(struct blkio_cgroup *blkcg, const char *input,
1059 msleep(10); 1018 msleep(10);
1060 ret = restart_syscall(); 1019 ret = restart_syscall();
1061 } 1020 }
1062 goto out; 1021 return ret;
1063 } 1022 }
1064 1023
1065 ctx->disk = disk; 1024 ctx->disk = disk;
1066 ctx->blkg = blkg; 1025 ctx->blkg = blkg;
1067 ctx->v = temp; 1026 ctx->v = v;
1068 ret = 0; 1027 return 0;
1069out:
1070 kfree(buf);
1071 return ret;
1072} 1028}
1073 1029
1074/** 1030/**