/* we are under risk of consuming all lh_cookie */
                CERROR("Can't have %d CPTs for LNet (max allowed is %d), please change setting of CPT-table and retry\n",
                       the_lnet.ln_cpt_number, LNET_CPT_MAX);
-               return -1;
+               return -E2BIG;
        }
 
        while ((1 << the_lnet.ln_cpt_bits) < the_lnet.ln_cpt_number)
        rc = lnet_create_locks();
        if (rc) {
                CERROR("Can't create LNet global locks: %d\n", rc);
-               return -1;
+               return rc;
        }
 
        the_lnet.ln_refcount = 0;
 
                        ltb = lnet_new_text_buf(nob);
                        if (!ltb) {
                                lnet_free_text_bufs(&pending);
-                               return -1;
+                               return -ENOMEM;
                        }
 
                        for (i = 0; i < nob; i++)
 
  failed:
        lnet_free_text_bufs(&pending);
-       return -1;
+       return -EINVAL;
 }
 
 static int
                 * priority as the token to report in the error message.
                 */
                *token += sep - str + 1;
-               return -1;
+               return -EINVAL;
        }
 
        CDEBUG(D_NET, "gateway %s, priority %d, nob %d\n", str, *priority, nob);
 
                return 1;
 
        if (r1->lr_priority > r2->lr_priority)
-               return -1;
+               return -ERANGE;
 
        if (r1_hops < r2_hops)
                return 1;
 
        if (r1_hops > r2_hops)
-               return -1;
+               return -ERANGE;
 
        if (p1->lp_txqnob < p2->lp_txqnob)
                return 1;
 
        if (p1->lp_txqnob > p2->lp_txqnob)
-               return -1;
+               return -ERANGE;
 
        if (p1->lp_txcredits > p2->lp_txcredits)
                return 1;
 
        if (p1->lp_txcredits < p2->lp_txcredits)
-               return -1;
+               return -ERANGE;
 
        if (r1->lr_seq - r2->lr_seq <= 0)
                return 1;
 
-       return -1;
+       return -ERANGE;
 }
 
 static lnet_peer_t *
                        libcfs_id2str(info.mi_id), info.mi_portal,
                        info.mi_mbits, info.mi_roffset, info.mi_rlength, rc);
 
-               return ENOENT;  /* +ve: OK but no match */
+               return -ENOENT; /* -ve: OK but no match */
        }
 }
 
                CNETERR("Dropping GET from %s portal %d match %llu offset %d length %d\n",
                        libcfs_id2str(info.mi_id), info.mi_portal,
                        info.mi_mbits, info.mi_roffset, info.mi_rlength);
-               return ENOENT;  /* +ve: OK but no match */
+               return -ENOENT; /* -ve: OK but no match */
        }
 
        LASSERT(rc == LNET_MATCHMD_OK);
                               md->md_me->me_portal);
 
                lnet_res_unlock(cpt);
-               return ENOENT;            /* +ve: OK but no match */
+               return -ENOENT; /* -ve: OK but no match */
        }
 
        LASSERT(!md->md_offset);
                        rlength, hdr->msg.reply.dst_wmd.wh_object_cookie,
                        mlength);
                lnet_res_unlock(cpt);
-               return ENOENT;    /* +ve: OK but no match */
+               return -ENOENT; /* -ve: OK but no match */
        }
 
        CDEBUG(D_NET, "%s: Reply from %s of length %d/%d into md %#llx\n",
                               md->md_me->me_portal);
 
                lnet_res_unlock(cpt);
-               return ENOENT;            /* +ve! */
+               return -ENOENT; /* -ve! */
        }
 
        CDEBUG(D_NET, "%s: ACK from %s into md %#llx\n",
        if (!rc)
                return 0;
 
-       LASSERT(rc == ENOENT);
+       LASSERT(rc == -ENOENT);
 
  free_drop:
        LASSERT(!msg->msg_md);
 
                LCONSOLE_ERROR_MSG(0x10c,
                                   "tiny_router_buffers=%d invalid when routing enabled\n",
                                   tiny_router_buffers);
-               return -1;
+               return -EINVAL;
        }
 
        if (tiny_router_buffers > 0)
                LCONSOLE_ERROR_MSG(0x10c,
                                   "small_router_buffers=%d invalid when routing enabled\n",
                                   small_router_buffers);
-               return -1;
+               return -EINVAL;
        }
 
        if (small_router_buffers > 0)
                LCONSOLE_ERROR_MSG(0x10c,
                                   "large_router_buffers=%d invalid when routing enabled\n",
                                   large_router_buffers);
-               return -1;
+               return -EINVAL;
        }
 
        if (large_router_buffers > 0)