Merge tag 'mtd/fixes-for-4.18-rc3' of git://git.infradead.org/linux-mtd
[sfrench/cifs-2.6.git] / fs / namei.c
index 6df1f61855d600a7072b2b770e993118cc5ac036..734cef54fdf8b0cc3c4136dc3b11f6e07c5952e2 100644 (file)
@@ -537,12 +537,12 @@ static int __nd_alloc_stack(struct nameidata *nd)
        struct saved *p;
 
        if (nd->flags & LOOKUP_RCU) {
-               p= kmalloc(MAXSYMLINKS * sizeof(struct saved),
+               p= kmalloc_array(MAXSYMLINKS, sizeof(struct saved),
                                  GFP_ATOMIC);
                if (unlikely(!p))
                        return -ECHILD;
        } else {
-               p= kmalloc(MAXSYMLINKS * sizeof(struct saved),
+               p= kmalloc_array(MAXSYMLINKS, sizeof(struct saved),
                                  GFP_KERNEL);
                if (unlikely(!p))
                        return -ENOMEM;
@@ -2463,6 +2463,35 @@ static int lookup_one_len_common(const char *name, struct dentry *base,
        return inode_permission(base->d_inode, MAY_EXEC);
 }
 
+/**
+ * try_lookup_one_len - filesystem helper to lookup single pathname component
+ * @name:      pathname component to lookup
+ * @base:      base directory to lookup from
+ * @len:       maximum length @len should be interpreted to
+ *
+ * Look up a dentry by name in the dcache, returning NULL if it does not
+ * currently exist.  The function does not try to create a dentry.
+ *
+ * Note that this routine is purely a helper for filesystem usage and should
+ * not be called by generic code.
+ *
+ * The caller must hold base->i_mutex.
+ */
+struct dentry *try_lookup_one_len(const char *name, struct dentry *base, int len)
+{
+       struct qstr this;
+       int err;
+
+       WARN_ON_ONCE(!inode_is_locked(base->d_inode));
+
+       err = lookup_one_len_common(name, base, len, &this);
+       if (err)
+               return ERR_PTR(err);
+
+       return lookup_dcache(&this, base, 0);
+}
+EXPORT_SYMBOL(try_lookup_one_len);
+
 /**
  * lookup_one_len - filesystem helper to lookup single pathname component
  * @name:      pathname component to lookup