tree schema FEATURE schema node module owner func
diff --git a/src/tree_data_helpers.c b/src/tree_data_helpers.c
index 3863ade..b9cfc41 100644
--- a/src/tree_data_helpers.c
+++ b/src/tree_data_helpers.c
@@ -267,8 +267,7 @@
         }
     }
 
-    for (schema = node->schema; schema->parent; schema = schema->parent) {}
-    return schema->module;
+    return lysc_owner_module(node->schema);
 }
 
 void
diff --git a/src/tree_schema.h b/src/tree_schema.h
index 67e5183..e202d84 100644
--- a/src/tree_schema.h
+++ b/src/tree_schema.h
@@ -105,6 +105,7 @@
  * - ::lys_set_implemented()
  *
  * - ::lysc_has_when()
+ * - ::lysc_owner_module()
  *
  * - ::lysc_node_child()
  * - ::lysc_node_actions()
@@ -2018,6 +2019,15 @@
 const struct lysc_when *lysc_has_when(const struct lysc_node *node);
 
 /**
+ * @brief Get the owner module of the schema node. It is the module of the top-level node. Generally,
+ * in case of augments it is the target module, recursively, otherwise it is the module where the node is defined.
+ *
+ * @param[in] node Schema node to examine.
+ * @return Module owner of the node.
+ */
+const struct lys_module *lysc_owner_module(const struct lysc_node *node);
+
+/**
  * @brief Get the groupings linked list of the given (parsed) schema node.
  * Decides the node's type and in case it has a groupings array, returns it.
  * @param[in] node Node to examine.
diff --git a/src/tree_schema_helpers.c b/src/tree_schema_helpers.c
index 0dbfefa..67076b6 100644
--- a/src/tree_schema_helpers.c
+++ b/src/tree_schema_helpers.c
@@ -1222,6 +1222,17 @@
     return NULL;
 }
 
+API const struct lys_module *
+lysc_owner_module(const struct lysc_node *node)
+{
+    if (!node) {
+        return NULL;
+    }
+
+    for ( ; node->parent; node = node->parent) {}
+    return node->module;
+}
+
 API const char *
 lys_nodetype2str(uint16_t nodetype)
 {