BUG_ON(me->expect_class_max >= NF_CT_MAX_EXPECT_CLASSES);
        BUG_ON(strlen(me->name) > NF_CT_HELPER_NAME_LEN - 1);
  
 +      if (me->expect_policy->max_expected > NF_CT_EXPECT_MAX_CNT)
 +              return -EINVAL;
 +
        mutex_lock(&nf_ct_helper_mutex);
-       hlist_for_each_entry(cur, &nf_ct_helper_hash[h], hnode) {
-               if (nf_ct_tuple_src_mask_cmp(&cur->tuple, &me->tuple, &mask)) {
-                       ret = -EEXIST;
-                       goto out;
+       for (i = 0; i < nf_ct_helper_hsize; i++) {
+               hlist_for_each_entry(cur, &nf_ct_helper_hash[i], hnode) {
+                       if (!strcmp(cur->name, me->name) &&
+                           (cur->tuple.src.l3num == NFPROTO_UNSPEC ||
+                            cur->tuple.src.l3num == me->tuple.src.l3num) &&
+                           cur->tuple.dst.protonum == me->tuple.dst.protonum) {
+                               ret = -EEXIST;
+                               goto out;
+                       }
+               }
+       }
+ 
+       /* avoid unpredictable behaviour for auto_assign_helper */
+       if (!(me->flags & NF_CT_HELPER_F_USERSPACE)) {
+               hlist_for_each_entry(cur, &nf_ct_helper_hash[h], hnode) {
+                       if (nf_ct_tuple_src_mask_cmp(&cur->tuple, &me->tuple,
+                                                    &mask)) {
+                               ret = -EEXIST;
+                               goto out;
+                       }
                }
        }
        hlist_add_head_rcu(&me->hnode, &nf_ct_helper_hash[h]);