tree data UPDATE invalid duplicate instances

Check and handle duplicate instances even for
nodes that do not allow them. That enables
diff and merge to work with invalid data.

Fixes sysrepo/sysrepo#2833
diff --git a/src/tree_data.c b/src/tree_data.c
index 60a17b5..cb7a581 100644
--- a/src/tree_data.c
+++ b/src/tree_data.c
@@ -2480,7 +2480,7 @@
     struct lyd_node **match_p, *first, *iter;
     struct lyd_node_inner *parent;
 
-    LY_CHECK_ARG_RET(NULL, target, lysc_is_dup_inst_list(target->schema), set, LY_EINVAL);
+    LY_CHECK_ARG_RET(NULL, target, set, LY_EINVAL);
     LY_CHECK_CTX_EQUAL_RET(siblings ? LYD_CTX(siblings) : NULL, LYD_CTX(target), LY_EINVAL);
 
     LY_CHECK_RET(ly_set_new(set));
diff --git a/src/tree_data.h b/src/tree_data.h
index 0f8db3f..53e18a5 100644
--- a/src/tree_data.h
+++ b/src/tree_data.h
@@ -2391,8 +2391,8 @@
         const char *key_or_value, size_t val_len, struct lyd_node **match);
 
 /**
- * @brief Search the given siblings for all the exact same instances of a specific node instance. Accepts only nodes
- * that are allowed to have several exact same instances. Uses hashes to whatever extent possible.
+ * @brief Search the given siblings for all the exact same instances of a specific node instance.
+ * Uses hashes to whatever extent possible.
  *
  * @param[in] siblings Siblings to search in including preceding and succeeding nodes.
  * @param[in] target Target node instance to find.
diff --git a/src/tree_data_common.c b/src/tree_data_common.c
index 8f087b2..f6a53c9 100644
--- a/src/tree_data_common.c
+++ b/src/tree_data_common.c
@@ -73,12 +73,13 @@
 {
     struct lyd_dup_inst *dup_inst;
 
-    if (!*inst || !lysc_is_dup_inst_list((*inst)->schema)) {
-        /* no match or not dup-inst list, inst is unchanged */
+    if (!*inst) {
+        /* no match, inst is unchanged */
         return LY_SUCCESS;
     }
 
-    /* there can be more exact same instances and we must make sure we do not match a single node more times */
+    /* there can be more exact same instances (even if not allowed in invalid data) and we must make sure we do not
+     * match a single node more times */
     dup_inst = lyd_dup_inst_get(*inst, dup_inst_cache);
     LY_CHECK_ERR_RET(!dup_inst, LOGMEM(LYD_CTX(siblings)), LY_EMEM);