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

Commit 88b38782 authored by Li Zefan's avatar Li Zefan Committed by Al Viro
Browse files

[PATCH] vfs: use kstrdup() and check failing allocation



- use kstrdup() instead of kmalloc() + memcpy()
- return NULL if allocating ->mnt_devname failed
- mnt_devname should be const

Signed-off-by: default avatarLi Zefan <lizf@cn.fujitsu.com>
Acked-by: default avatarCyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 672b16b2
Loading
Loading
Loading
Loading
+13 −11
Original line number Original line Diff line number Diff line
@@ -112,9 +112,13 @@ struct vfsmount *alloc_vfsmnt(const char *name)
		int err;
		int err;


		err = mnt_alloc_id(mnt);
		err = mnt_alloc_id(mnt);
		if (err) {
		if (err)
			kmem_cache_free(mnt_cache, mnt);
			goto out_free_cache;
			return NULL;

		if (name) {
			mnt->mnt_devname = kstrdup(name, GFP_KERNEL);
			if (!mnt->mnt_devname)
				goto out_free_id;
		}
		}


		atomic_set(&mnt->mnt_count, 1);
		atomic_set(&mnt->mnt_count, 1);
@@ -127,16 +131,14 @@ struct vfsmount *alloc_vfsmnt(const char *name)
		INIT_LIST_HEAD(&mnt->mnt_slave_list);
		INIT_LIST_HEAD(&mnt->mnt_slave_list);
		INIT_LIST_HEAD(&mnt->mnt_slave);
		INIT_LIST_HEAD(&mnt->mnt_slave);
		atomic_set(&mnt->__mnt_writers, 0);
		atomic_set(&mnt->__mnt_writers, 0);
		if (name) {
			int size = strlen(name) + 1;
			char *newname = kmalloc(size, GFP_KERNEL);
			if (newname) {
				memcpy(newname, name, size);
				mnt->mnt_devname = newname;
			}
		}
	}
	}
	return mnt;
	return mnt;

out_free_id:
	mnt_free_id(mnt);
out_free_cache:
	kmem_cache_free(mnt_cache, mnt);
	return NULL;
}
}


/*
/*
+1 −1
Original line number Original line Diff line number Diff line
@@ -47,7 +47,7 @@ struct vfsmount {
	struct list_head mnt_child;	/* and going through their mnt_child */
	struct list_head mnt_child;	/* and going through their mnt_child */
	int mnt_flags;
	int mnt_flags;
	/* 4 bytes hole on 64bits arches */
	/* 4 bytes hole on 64bits arches */
	char *mnt_devname;		/* Name of device e.g. /dev/dsk/hda1 */
	const char *mnt_devname;	/* Name of device e.g. /dev/dsk/hda1 */
	struct list_head mnt_list;
	struct list_head mnt_list;
	struct list_head mnt_expire;	/* link in fs-specific expiry list */
	struct list_head mnt_expire;	/* link in fs-specific expiry list */
	struct list_head mnt_share;	/* circular list of shared mounts */
	struct list_head mnt_share;	/* circular list of shared mounts */