diff --git a/lustre/mdd/mdd_dir.c b/lustre/mdd/mdd_dir.c
index 309025bbb44b8f28848ccca26e159e5e55bf8b67..9b54aba617dc431dca4fc03da0f0bec5ddfc6936 100644
--- a/lustre/mdd/mdd_dir.c
+++ b/lustre/mdd/mdd_dir.c
@@ -2271,6 +2271,9 @@ static int __mdd_links_add(const struct lu_env *env, struct lu_buf *buf,
         struct link_ea_entry *lee;
         int reclen;
 
+        if (lname == NULL || pfid == NULL)
+                return -EINVAL;
+
         /* Make sure our buf is big enough for the new one */
         leh = buf->lb_buf;
         reclen = lname->ln_namelen + sizeof(struct link_ea_entry);