{
        int ret;
 
-       if (type >= MAXQUOTAS)
-               return -EINVAL;
        ret = security_quotactl(Q_SYNC, type, 0, NULL);
        if (!ret)
                iterate_supers(quota_sync_one, &type);
 {
        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
        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