Merge tag 'mediatek-drm-fixes-5.14' of https://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6-microblaze.git] / fs / fs_context.c
index 2834d1a..de1985e 100644 (file)
@@ -79,6 +79,35 @@ static int vfs_parse_sb_flag(struct fs_context *fc, const char *key)
        return -ENOPARAM;
 }
 
+/**
+ * vfs_parse_fs_param_source - Handle setting "source" via parameter
+ * @fc: The filesystem context to modify
+ * @param: The parameter
+ *
+ * This is a simple helper for filesystems to verify that the "source" they
+ * accept is sane.
+ *
+ * Returns 0 on success, -ENOPARAM if this is not  "source" parameter, and
+ * -EINVAL otherwise. In the event of failure, supplementary error information
+ *  is logged.
+ */
+int vfs_parse_fs_param_source(struct fs_context *fc, struct fs_parameter *param)
+{
+       if (strcmp(param->key, "source") != 0)
+               return -ENOPARAM;
+
+       if (param->type != fs_value_is_string)
+               return invalf(fc, "Non-string source");
+
+       if (fc->source)
+               return invalf(fc, "Multiple sources");
+
+       fc->source = param->string;
+       param->string = NULL;
+       return 0;
+}
+EXPORT_SYMBOL(vfs_parse_fs_param_source);
+
 /**
  * vfs_parse_fs_param - Add a single parameter to a superblock config
  * @fc: The filesystem context to modify
@@ -122,15 +151,9 @@ int vfs_parse_fs_param(struct fs_context *fc, struct fs_parameter *param)
        /* If the filesystem doesn't take any arguments, give it the
         * default handling of source.
         */
-       if (strcmp(param->key, "source") == 0) {
-               if (param->type != fs_value_is_string)
-                       return invalf(fc, "VFS: Non-string source");
-               if (fc->source)
-                       return invalf(fc, "VFS: Multiple sources");
-               fc->source = param->string;
-               param->string = NULL;
-               return 0;
-       }
+       ret = vfs_parse_fs_param_source(fc, param);
+       if (ret != -ENOPARAM)
+               return ret;
 
        return invalf(fc, "%s: Unknown parameter '%s'",
                      fc->fs_type->name, param->key);
@@ -504,16 +527,11 @@ static int legacy_parse_param(struct fs_context *fc, struct fs_parameter *param)
        struct legacy_fs_context *ctx = fc->fs_private;
        unsigned int size = ctx->data_size;
        size_t len = 0;
+       int ret;
 
-       if (strcmp(param->key, "source") == 0) {
-               if (param->type != fs_value_is_string)
-                       return invalf(fc, "VFS: Legacy: Non-string source");
-               if (fc->source)
-                       return invalf(fc, "VFS: Legacy: Multiple sources");
-               fc->source = param->string;
-               param->string = NULL;
-               return 0;
-       }
+       ret = vfs_parse_fs_param_source(fc, param);
+       if (ret != -ENOPARAM)
+               return ret;
 
        if (ctx->param_type == LEGACY_FS_MONOLITHIC_PARAMS)
                return invalf(fc, "VFS: Legacy: Can't mix monolithic and individual options");