context FEATURE add alternate to ly_ctx_get_submodule()

new ly_ctx_get_submodule2() can be used when the caller already has a
pointer to the main module where he wants to search for the submodule.
diff --git a/src/context.c b/src/context.c
index 9047c04..83c6560 100644
--- a/src/context.c
+++ b/src/context.c
@@ -168,11 +168,31 @@
 }
 
 API const struct lys_submodule *
+ly_ctx_get_submodule2(const struct lys_module *main_module, const char *submodule)
+{
+    struct lys_submodule *result;
+    int i;
+
+    if (!main_module || !submodule) {
+        ly_errno = LY_EINVAL;
+        return NULL;
+    }
+
+    /* search in submodules list */
+    for (i = 0; i < main_module->inc_size; i++) {
+        result = main_module->inc[i].submodule;
+        if (result && ly_strequal(submodule, result->name, 0)) {
+            return result;
+        }
+    }
+
+    return NULL;
+}
+
+API const struct lys_submodule *
 ly_ctx_get_submodule(const struct ly_ctx *ctx, const char *module, const char *revision, const char *submodule)
 {
     const struct lys_module *mainmod;
-    struct lys_submodule *result;
-    int i;
 
     if (!module || !submodule) {
         ly_errno = LY_EINVAL;
@@ -185,16 +205,7 @@
         return NULL;
     }
 
-    /* search in submodules list */
-    for (i = 0; i < mainmod->inc_size; i++) {
-        result = mainmod->inc[i].submodule;
-        if (ly_strequal(submodule, result->name, 0)) {
-            return result;
-        }
-    }
-
-    ly_errno = LY_EINVAL;
-    return NULL;
+    return ly_ctx_get_submodule2(mainmod, submodule);
 }
 
 static const struct lys_module *
diff --git a/src/libyang.h b/src/libyang.h
index bc64779..d04ebf7 100644
--- a/src/libyang.h
+++ b/src/libyang.h
@@ -658,7 +658,9 @@
 const struct lys_module *ly_ctx_get_module_by_ns(const struct ly_ctx *ctx, const char *ns, const char *revision);
 
 /**
- * @brief Get submodule from the context's search dir.
+ * @brief Get submodule of a main module.
+ *
+ * If you already have the pointer to the submodule's main module, use ly_ctx_get_submodule2() instead.
  *
  * @param[in] ctx Context to work in.
  * @param[in] module Name of the main (belongs-to) module.
@@ -670,6 +672,18 @@
                                                  const char *submodule);
 
 /**
+ * @brief Get submodule of a main module.
+ *
+ * If you have only the name (and optionally revision) of the submodule's main module, use ly_ctx_get_submodule()
+ * instead.
+ *
+ * @param[in] main_module Main module (belongs to) of the searched submodule.
+ * @param[in] submodule Name of the submodule to get.
+ * @return Pointer to the data model structure.
+ */
+const struct lys_submodule *ly_ctx_get_submodule2(const struct lys_module *main_module, const char *submodule);
+
+/**
  * @brief Get schema node according to the given absolute schema node identifier
  * in JSON format.
  *