Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 61edc3f3 authored by Richard Weinberger's avatar Richard Weinberger
Browse files

ubi: Don't bypass ->getattr()



Directly accessing inode fields bypasses ->getattr()
and can cause problems when the underlying filesystem
does not have the default ->getattr() implementation.

So instead of obtaining the backing inode via d_backing_inode()
use vfs_getattr() and obtain what we need from the kstat struct.

Cc: Al Viro <viro@zeniv.linux.org.uk>
Reported-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
parent 1a498ec4
Loading
Loading
Loading
Loading
+10 −6
Original line number Diff line number Diff line
@@ -1147,22 +1147,26 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)
 */
static struct mtd_info * __init open_mtd_by_chdev(const char *mtd_dev)
{
	int err, major, minor, mode;
	int err, minor;
	struct path path;
	struct kstat stat;

	/* Probably this is an MTD character device node path */
	err = kern_path(mtd_dev, LOOKUP_FOLLOW, &path);
	if (err)
		return ERR_PTR(err);

	/* MTD device number is defined by the major / minor numbers */
	major = imajor(d_backing_inode(path.dentry));
	minor = iminor(d_backing_inode(path.dentry));
	mode = d_backing_inode(path.dentry)->i_mode;
	err = vfs_getattr(&path, &stat);
	path_put(&path);
	if (major != MTD_CHAR_MAJOR || !S_ISCHR(mode))
	if (err)
		return ERR_PTR(err);

	/* MTD device number is defined by the major / minor numbers */
	if (MAJOR(stat.rdev) != MTD_CHAR_MAJOR || !S_ISCHR(stat.mode))
		return ERR_PTR(-EINVAL);

	minor = MINOR(stat.rdev);

	if (minor & 1)
		/*
		 * Just do not think the "/dev/mtdrX" devices support is need,
+10 −7
Original line number Diff line number Diff line
@@ -301,9 +301,9 @@ EXPORT_SYMBOL_GPL(ubi_open_volume_nm);
 */
struct ubi_volume_desc *ubi_open_volume_path(const char *pathname, int mode)
{
	int error, ubi_num, vol_id, mod;
	struct inode *inode;
	int error, ubi_num, vol_id;
	struct path path;
	struct kstat stat;

	dbg_gen("open volume %s, mode %d", pathname, mode);

@@ -314,14 +314,17 @@ struct ubi_volume_desc *ubi_open_volume_path(const char *pathname, int mode)
	if (error)
		return ERR_PTR(error);

	inode = d_backing_inode(path.dentry);
	mod = inode->i_mode;
	ubi_num = ubi_major2num(imajor(inode));
	vol_id = iminor(inode) - 1;
	error = vfs_getattr(&path, &stat);
	path_put(&path);
	if (error)
		return ERR_PTR(error);

	if (!S_ISCHR(mod))
	if (!S_ISCHR(stat.mode))
		return ERR_PTR(-EINVAL);

	ubi_num = ubi_major2num(MAJOR(stat.rdev));
	vol_id = MINOR(stat.rdev) - 1;

	if (vol_id >= 0 && ubi_num >= 0)
		return ubi_open_volume(ubi_num, vol_id, mode);
	return ERR_PTR(-ENODEV);