Skip to contentSkip to conversation

quota: check quota type in early stage

PATCH In review Chengguang Xu 2 participants 2 messages Oct 8, 2019 Diskquota

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 quota: check quota type in early stage

Check quota type in early stage so we can avoid many unncessary operations when the type is wrong.

---
 fs/quota/quota.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
fs/quota/quota.c +3 -4
index cb13fb76dbee..5444d3c4d93f 100644
@@ -60,8 +60,6 @@ static int quota_sync_all(int type)
 {
 	int ret;
 
-	if (type >= MAXQUOTAS)
-		return -EINVAL;
 	ret = security_quotactl(Q_SYNC, type, 0, NULL);
 	if (!ret)
 		iterate_supers(quota_sync_one, &type);
@@ -686,8 +684,6 @@ static int do_quotactl(struct super_block *sb, int type, int cmd, qid_t id,
 {
 	int ret;
 
-	if (type >= MAXQUOTAS)
-		return -EINVAL;
 	type = array_index_nospec(type, MAXQUOTAS);
 	/*
 	 * Quota not supported on this fs? Check this before s_quota_types
@@ -831,6 +827,9 @@ int kernel_quotactl(unsigned int cmd, const char __user *special,
 	cmds = cmd >> SUBCMDSHIFT;
 	type = cmd & SUBCMDMASK;
 
+	if (type >= MAXQUOTAS)
+		return -EINVAL;
+
 	/*
 	 * As a special case Q_SYNC can be called without a specific device.
 	 * It will iterate all superblocks that have quota enabled and call
Signature · 1 line
2.21.0
#1 lore raw
Quoted 4 lines · Chengguang Xu

Check quota type in early stage so we can avoid many unncessary operations when the type is wrong.

Yeah, checking earlier makes sense, especially since it consolidates two checks into one. I've added your patch to my tree. Thanks!

Honza

Quoted 42 lines
---
 fs/quota/quota.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
fs/quota/quota.c +3 -4
index cb13fb76dbee..5444d3c4d93f 100644
@@ -60,8 +60,6 @@ static int quota_sync_all(int type)
 {
 	int ret;
 
-	if (type >= MAXQUOTAS)
-		return -EINVAL;
 	ret = security_quotactl(Q_SYNC, type, 0, NULL);
 	if (!ret)
 		iterate_supers(quota_sync_one, &type);
@@ -686,8 +684,6 @@ static int do_quotactl(struct super_block *sb, int type, int cmd, qid_t id,
 {
 	int ret;
 
-	if (type >= MAXQUOTAS)
-		return -EINVAL;
 	type = array_index_nospec(type, MAXQUOTAS);
 	/*
 	 * Quota not supported on this fs? Check this before s_quota_types
@@ -831,6 +827,9 @@ int kernel_quotactl(unsigned int cmd, const char __user *special,
 	cmds = cmd >> SUBCMDSHIFT;
 	type = cmd & SUBCMDMASK;
 
+	if (type >= MAXQUOTAS)
+		return -EINVAL;
+
 	/*
 	 * As a special case Q_SYNC can be called without a specific device.
 	 * It will iterate all superblocks that have quota enabled and call
Signature · 1 line
2.21.0
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR