All of lore.kernel.org
 help / color / mirror / Atom feed
* [linux-next:master 1206/2332] fs/namei.c:4637 lookup_open() warn: inconsistent indenting
@ 2026-09-02  1:03 kernel test robot
  0 siblings, 0 replies; only message in thread
From: kernel test robot @ 2026-09-02  1:03 UTC (permalink / raw)
  To: Jori Koolstra; +Cc: oe-kbuild-all, Christian Brauner

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
head:   8b72f6626dc39b9e7e82b2721d4f7c3b86286012
commit: 449c7265d60d44eece1f83eee2badf2ea61e767d [1206/2332] vfs: add O_CREAT|O_DIRECTORY to open*(2)
config: csky-randconfig-r071-20260901 (https://download.01.org/0day-ci/archive/20260902/202609020834.LGMSIGsS-lkp@intel.com/config)
compiler: csky-linux-gcc (GCC) 16.1.0
smatch: v0.5.0-9187-g5189e3fb

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202609020834.LGMSIGsS-lkp@intel.com/

New smatch warnings:
fs/namei.c:4637 lookup_open() warn: inconsistent indenting

Old smatch warnings:
fs/namei.c:1789 lookup_dcache() warn: passing zero to 'ERR_PTR'
fs/namei.c:1901 lookup_fast() warn: passing zero to 'ERR_PTR'

vim +4637 fs/namei.c

  4478	
  4479	static inline
  4480	struct dentry *vfs_mkdir_no_perm(struct mnt_idmap *, struct inode *,
  4481					 struct dentry *, umode_t,
  4482					 struct delegated_inode *);
  4483	/*
  4484	 * Look up and maybe create and open the last component.
  4485	 *
  4486	 * Takes the parent inode lock itself, exclusive if O_CREAT was requested and
  4487	 * shared otherwise, and drops it again before returning.  The caller must not
  4488	 * hold it.
  4489	 *
  4490	 * On success returns the dentry of the last component.  If FMODE_OPENED is set
  4491	 * on file->f_mode the file was also opened and attached to @file; otherwise
  4492	 * only lookup and creation were performed and the caller has to open it.  In
  4493	 * the latter case the dentry may be negative if O_CREAT hadn't been specified.
  4494	 *
  4495	 * Returns ERR_PTR() on failure.
  4496	 */
  4497	static struct dentry *lookup_open(struct nameidata *nd, struct file *file,
  4498					  const struct open_flags *op)
  4499	{
  4500		struct delegated_inode delegated_inode = { };
  4501		struct mnt_idmap *idmap;
  4502		struct dentry *dir = nd->path.dentry;
  4503		struct inode *dir_inode = dir->d_inode;
  4504		bool create_dir = O_IS_MKDIR(op->mode);
  4505		int open_flag;
  4506		struct dentry *dentry;
  4507		int error, create_error;
  4508		umode_t mode;
  4509		bool got_write;
  4510	
  4511	retry:
  4512		open_flag = op->open_flag;
  4513		got_write = false;
  4514		mode = op->mode;
  4515		create_error = 0;
  4516	
  4517		if (open_flag & (O_CREAT | O_TRUNC | O_WRONLY | O_RDWR)) {
  4518			got_write = !mnt_want_write(nd->path.mnt);
  4519			/*
  4520			 * do _not_ fail yet - we might not need that or fail with
  4521			 * a different error; we'll be dropping this one anyway.
  4522			 */
  4523		}
  4524		if (open_flag & O_CREAT)
  4525			inode_lock_nested(dir_inode, I_MUTEX_PARENT);
  4526		else
  4527			inode_lock_shared(dir_inode);
  4528	
  4529		if (unlikely(IS_DEADDIR(dir_inode))) {
  4530			dentry = ERR_PTR(-ENOENT);
  4531			goto out;
  4532		}
  4533	
  4534		if (create_dir && dir_inode->i_op->atomic_open)
  4535			open_flag &= ~O_CREAT;
  4536	
  4537		file->f_mode &= ~FMODE_CREATED;
  4538		dentry = d_lookup(dir, &nd->last);
  4539		for (;;) {
  4540			if (!dentry) {
  4541				dentry = d_alloc_parallel(dir, &nd->last);
  4542				if (IS_ERR(dentry))
  4543					goto out;
  4544			}
  4545			if (d_in_lookup(dentry))
  4546				break;
  4547	
  4548			error = d_revalidate(dir_inode, &nd->last, dentry, nd->flags);
  4549			if (likely(error > 0))
  4550				break;
  4551			if (error)
  4552				goto out_dput;
  4553			d_invalidate(dentry);
  4554			dput(dentry);
  4555			dentry = NULL;
  4556		}
  4557		if (dentry->d_inode) {
  4558			/* Cached positive dentry: will open in do_open(). */
  4559			goto out;
  4560		}
  4561	
  4562		if (open_flag & O_CREAT)
  4563			audit_inode(nd->name, dir, AUDIT_INODE_PARENT);
  4564	
  4565		/*
  4566		 * Checking write permission is tricky, bacuse we don't know if we are
  4567		 * going to actually need it: O_CREAT opens should work as long as the
  4568		 * file exists.  But checking existence breaks atomicity.  The trick is
  4569		 * to check access and if not granted clear O_CREAT from the flags.
  4570		 *
  4571		 * Another problem is returing the "right" error value (e.g. for an
  4572		 * O_EXCL open we want to return EEXIST not EROFS).
  4573		 */
  4574		if (unlikely(!got_write))
  4575			open_flag &= ~O_TRUNC;
  4576		idmap = mnt_idmap(nd->path.mnt);
  4577		if (open_flag & O_CREAT) {
  4578			if (open_flag & O_EXCL)
  4579				open_flag &= ~O_TRUNC;
  4580			mode = o_create_mode(idmap, dir_inode, open_flag, mode);
  4581			if (likely(got_write))
  4582				create_error = may_o_create(idmap, &nd->path,
  4583							    dentry, open_flag, mode);
  4584			else
  4585				create_error = -EROFS;
  4586		}
  4587		if (create_error)
  4588			open_flag &= ~O_CREAT;
  4589		if (dir_inode->i_op->atomic_open) {
  4590			if (nd->flags & LOOKUP_DIRECTORY)
  4591				open_flag |= O_DIRECTORY;
  4592			dentry = atomic_open(&nd->path, dentry, file, open_flag, mode,
  4593					     create_error);
  4594			goto out;
  4595		}
  4596	
  4597		if (d_in_lookup(dentry)) {
  4598			struct dentry *res = dir_inode->i_op->lookup(dir_inode, dentry,
  4599								     nd->flags);
  4600			d_lookup_done(dentry);
  4601			if (unlikely(res)) {
  4602				if (IS_ERR(res)) {
  4603					error = PTR_ERR(res);
  4604					goto out_dput;
  4605				}
  4606				dput(dentry);
  4607				dentry = res;
  4608			}
  4609		}
  4610	
  4611		if (dentry->d_inode || !(op->open_flag & O_CREAT)) {
  4612			/*
  4613			 * No need to create a file.  If lookup returned a positive
  4614			 * dentry, the file will be opened in do_open().
  4615			 */
  4616			goto out;
  4617		}
  4618	
  4619		/* Negative dentry with O_CREAT flag set */
  4620		audit_inode_child(dir_inode, dentry, AUDIT_TYPE_CHILD_CREATE);
  4621	
  4622		if (unlikely(create_error)) {
  4623			/* should have done a create, but we already errored */
  4624			error = create_error;
  4625			goto out_dput;
  4626		}
  4627	
  4628		if ((create_dir && !dir_inode->i_op->mkdir)
  4629			|| (!create_dir && !dir_inode->i_op->create)) {
  4630			error = -EACCES;
  4631			goto out_dput;
  4632		}
  4633	
  4634		if (create_dir) {
  4635			struct dentry *res = vfs_mkdir_no_perm(idmap, dir_inode, dentry,
  4636							       mode, &delegated_inode);
> 4637				error = PTR_ERR_OR_ZERO(res);
  4638				if (!error)
  4639					dentry = res;
  4640		} else {
  4641			error = vfs_create_no_perm(idmap, dentry, mode, &delegated_inode);
  4642		}
  4643		if (error)
  4644			goto out_dput;
  4645	
  4646		file->f_mode |= FMODE_CREATED;
  4647	out:
  4648		if ((open_flag & O_CREAT) || create_error)
  4649			inode_unlock(dir_inode);
  4650		else
  4651			inode_unlock_shared(dir_inode);
  4652	
  4653		if (got_write)
  4654			mnt_drop_write(nd->path.mnt);
  4655	
  4656		if (is_delegated(&delegated_inode)) {
  4657			/* Must have come through out_dput: dentry is an ERR_PTR() */
  4658			error = break_deleg_wait(&delegated_inode);
  4659	
  4660			if (!error)
  4661				goto retry;
  4662			dentry = ERR_PTR(error);
  4663		}
  4664	
  4665		return dentry;
  4666	
  4667	out_dput:
  4668		dput(dentry);
  4669		dentry = ERR_PTR(error);
  4670		goto out;
  4671	}
  4672	

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-09-02  1:04 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-02  1:03 [linux-next:master 1206/2332] fs/namei.c:4637 lookup_open() warn: inconsistent indenting kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.