1
0
Fork 0

Reduce path_lookup() abuses

... use kern_path() where possible

[folded a fix from rdd]

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
hifive-unleashed-5.1
Al Viro 2009-04-02 21:17:03 -04:00
parent 6b3304b531
commit e24977d45f
4 changed files with 25 additions and 25 deletions

View File

@ -173,26 +173,26 @@ static const struct file_operations osd_fops = {
.unlocked_ioctl = osd_uld_ioctl, .unlocked_ioctl = osd_uld_ioctl,
}; };
struct osd_dev *osduld_path_lookup(const char *path) struct osd_dev *osduld_path_lookup(const char *name)
{ {
struct nameidata nd; struct path path;
struct inode *inode; struct inode *inode;
struct cdev *cdev; struct cdev *cdev;
struct osd_uld_device *uninitialized_var(oud); struct osd_uld_device *uninitialized_var(oud);
int error; int error;
if (!path || !*path) { if (!name || !*name) {
OSD_ERR("Mount with !path || !*path\n"); OSD_ERR("Mount with !path || !*path\n");
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
} }
error = path_lookup(path, LOOKUP_FOLLOW, &nd); error = kern_path(name, LOOKUP_FOLLOW, &path);
if (error) { if (error) {
OSD_ERR("path_lookup of %s faild=>%d\n", path, error); OSD_ERR("path_lookup of %s failed=>%d\n", name, error);
return ERR_PTR(error); return ERR_PTR(error);
} }
inode = nd.path.dentry->d_inode; inode = path.dentry->d_inode;
error = -EINVAL; /* Not the right device e.g osd_uld_device */ error = -EINVAL; /* Not the right device e.g osd_uld_device */
if (!S_ISCHR(inode->i_mode)) { if (!S_ISCHR(inode->i_mode)) {
OSD_DEBUG("!S_ISCHR()\n"); OSD_DEBUG("!S_ISCHR()\n");
@ -202,15 +202,15 @@ struct osd_dev *osduld_path_lookup(const char *path)
cdev = inode->i_cdev; cdev = inode->i_cdev;
if (!cdev) { if (!cdev) {
OSD_ERR("Before mounting an OSD Based filesystem\n"); OSD_ERR("Before mounting an OSD Based filesystem\n");
OSD_ERR(" user-mode must open+close the %s device\n", path); OSD_ERR(" user-mode must open+close the %s device\n", name);
OSD_ERR(" Example: bash: echo < %s\n", path); OSD_ERR(" Example: bash: echo < %s\n", name);
goto out; goto out;
} }
/* The Magic wand. Is it our char-dev */ /* The Magic wand. Is it our char-dev */
/* TODO: Support sg devices */ /* TODO: Support sg devices */
if (cdev->owner != THIS_MODULE) { if (cdev->owner != THIS_MODULE) {
OSD_ERR("Error mounting %s - is not an OSD device\n", path); OSD_ERR("Error mounting %s - is not an OSD device\n", name);
goto out; goto out;
} }
@ -220,7 +220,7 @@ struct osd_dev *osduld_path_lookup(const char *path)
error = 0; error = 0;
out: out:
path_put(&nd.path); path_put(&path);
return error ? ERR_PTR(error) : &oud->od; return error ? ERR_PTR(error) : &oud->od;
} }
EXPORT_SYMBOL(osduld_path_lookup); EXPORT_SYMBOL(osduld_path_lookup);

View File

@ -1282,21 +1282,21 @@ static int gfs2_get_sb(struct file_system_type *fs_type, int flags,
static struct super_block *get_gfs2_sb(const char *dev_name) static struct super_block *get_gfs2_sb(const char *dev_name)
{ {
struct super_block *sb; struct super_block *sb;
struct nameidata nd; struct path path;
int error; int error;
error = path_lookup(dev_name, LOOKUP_FOLLOW, &nd); error = kern_path(dev_name, LOOKUP_FOLLOW, &path);
if (error) { if (error) {
printk(KERN_WARNING "GFS2: path_lookup on %s returned error %d\n", printk(KERN_WARNING "GFS2: path_lookup on %s returned error %d\n",
dev_name, error); dev_name, error);
return NULL; return NULL;
} }
sb = nd.path.dentry->d_inode->i_sb; sb = path.dentry->d_inode->i_sb;
if (sb && (sb->s_type == &gfs2_fs_type)) if (sb && (sb->s_type == &gfs2_fs_type))
atomic_inc(&sb->s_active); atomic_inc(&sb->s_active);
else else
sb = NULL; sb = NULL;
path_put(&nd.path); path_put(&path);
return sb; return sb;
} }

View File

@ -1720,14 +1720,14 @@ static bool tomoyo_policy_loader_exists(void)
* policies are not loaded yet. * policies are not loaded yet.
* Thus, let do_execve() call this function everytime. * Thus, let do_execve() call this function everytime.
*/ */
struct nameidata nd; struct path path;
if (path_lookup(tomoyo_loader, LOOKUP_FOLLOW, &nd)) { if (kern_path(tomoyo_loader, LOOKUP_FOLLOW, &path)) {
printk(KERN_INFO "Not activating Mandatory Access Control now " printk(KERN_INFO "Not activating Mandatory Access Control now "
"since %s doesn't exist.\n", tomoyo_loader); "since %s doesn't exist.\n", tomoyo_loader);
return false; return false;
} }
path_put(&nd.path); path_put(&path);
return true; return true;
} }

View File

@ -165,11 +165,11 @@ char *tomoyo_realpath_from_path(struct path *path)
*/ */
char *tomoyo_realpath(const char *pathname) char *tomoyo_realpath(const char *pathname)
{ {
struct nameidata nd; struct path path;
if (pathname && path_lookup(pathname, LOOKUP_FOLLOW, &nd) == 0) { if (pathname && kern_path(pathname, LOOKUP_FOLLOW, &path) == 0) {
char *buf = tomoyo_realpath_from_path(&nd.path); char *buf = tomoyo_realpath_from_path(&path);
path_put(&nd.path); path_put(&path);
return buf; return buf;
} }
return NULL; return NULL;
@ -184,11 +184,11 @@ char *tomoyo_realpath(const char *pathname)
*/ */
char *tomoyo_realpath_nofollow(const char *pathname) char *tomoyo_realpath_nofollow(const char *pathname)
{ {
struct nameidata nd; struct path path;
if (pathname && path_lookup(pathname, 0, &nd) == 0) { if (pathname && kern_path(pathname, 0, &path) == 0) {
char *buf = tomoyo_realpath_from_path(&nd.path); char *buf = tomoyo_realpath_from_path(&path);
path_put(&nd.path); path_put(&path);
return buf; return buf;
} }
return NULL; return NULL;