Commit dbc6e022 authored by Al Viro's avatar Al Viro

delousing target_core_file a bit

* set_fs(KERNEL_DS) + getname() is probably the weirdest implementation
of strdup() I've seen.  Especially since they don't to copy it at all...
* filp_open() never returns NULL; it's ERR_PTR(-E...) on failure.
* file->f_dentry is never going to be NULL, TYVM.
* match_strdup() + snprintf() + kfree() is a bloody weird way to spell
match_strlcpy().

Pox on cargo-cult programmers...
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 06fd516c
...@@ -109,46 +109,29 @@ static struct se_device *fd_create_virtdevice( ...@@ -109,46 +109,29 @@ static struct se_device *fd_create_virtdevice(
struct se_subsystem_dev *se_dev, struct se_subsystem_dev *se_dev,
void *p) void *p)
{ {
char *dev_p = NULL;
struct se_device *dev; struct se_device *dev;
struct se_dev_limits dev_limits; struct se_dev_limits dev_limits;
struct queue_limits *limits; struct queue_limits *limits;
struct fd_dev *fd_dev = p; struct fd_dev *fd_dev = p;
struct fd_host *fd_host = hba->hba_ptr; struct fd_host *fd_host = hba->hba_ptr;
mm_segment_t old_fs;
struct file *file; struct file *file;
struct inode *inode = NULL; struct inode *inode = NULL;
int dev_flags = 0, flags, ret = -EINVAL; int dev_flags = 0, flags, ret = -EINVAL;
memset(&dev_limits, 0, sizeof(struct se_dev_limits)); memset(&dev_limits, 0, sizeof(struct se_dev_limits));
old_fs = get_fs();
set_fs(get_ds());
dev_p = getname(fd_dev->fd_dev_name);
set_fs(old_fs);
if (IS_ERR(dev_p)) {
pr_err("getname(%s) failed: %lu\n",
fd_dev->fd_dev_name, IS_ERR(dev_p));
ret = PTR_ERR(dev_p);
goto fail;
}
/* /*
* Use O_DSYNC by default instead of O_SYNC to forgo syncing * Use O_DSYNC by default instead of O_SYNC to forgo syncing
* of pure timestamp updates. * of pure timestamp updates.
*/ */
flags = O_RDWR | O_CREAT | O_LARGEFILE | O_DSYNC; flags = O_RDWR | O_CREAT | O_LARGEFILE | O_DSYNC;
file = filp_open(dev_p, flags, 0600); file = filp_open(fd_dev->fd_dev_name, flags, 0600);
if (IS_ERR(file)) { if (IS_ERR(file)) {
pr_err("filp_open(%s) failed\n", dev_p); pr_err("filp_open(%s) failed\n", fd_dev->fd_dev_name);
ret = PTR_ERR(file); ret = PTR_ERR(file);
goto fail; goto fail;
} }
if (!file || !file->f_dentry) {
pr_err("filp_open(%s) failed\n", dev_p);
goto fail;
}
fd_dev->fd_file = file; fd_dev->fd_file = file;
/* /*
* If using a block backend with this struct file, we extract * If using a block backend with this struct file, we extract
...@@ -212,14 +195,12 @@ static struct se_device *fd_create_virtdevice( ...@@ -212,14 +195,12 @@ static struct se_device *fd_create_virtdevice(
" %llu total bytes\n", fd_host->fd_host_id, fd_dev->fd_dev_id, " %llu total bytes\n", fd_host->fd_host_id, fd_dev->fd_dev_id,
fd_dev->fd_dev_name, fd_dev->fd_dev_size); fd_dev->fd_dev_name, fd_dev->fd_dev_size);
putname(dev_p);
return dev; return dev;
fail: fail:
if (fd_dev->fd_file) { if (fd_dev->fd_file) {
filp_close(fd_dev->fd_file, NULL); filp_close(fd_dev->fd_file, NULL);
fd_dev->fd_file = NULL; fd_dev->fd_file = NULL;
} }
putname(dev_p);
return ERR_PTR(ret); return ERR_PTR(ret);
} }
...@@ -448,14 +429,11 @@ static ssize_t fd_set_configfs_dev_params( ...@@ -448,14 +429,11 @@ static ssize_t fd_set_configfs_dev_params(
token = match_token(ptr, tokens, args); token = match_token(ptr, tokens, args);
switch (token) { switch (token) {
case Opt_fd_dev_name: case Opt_fd_dev_name:
arg_p = match_strdup(&args[0]); if (match_strlcpy(fd_dev->fd_dev_name, &args[0],
if (!arg_p) { FD_MAX_DEV_NAME) == 0) {
ret = -ENOMEM; ret = -EINVAL;
break; break;
} }
snprintf(fd_dev->fd_dev_name, FD_MAX_DEV_NAME,
"%s", arg_p);
kfree(arg_p);
pr_debug("FILEIO: Referencing Path: %s\n", pr_debug("FILEIO: Referencing Path: %s\n",
fd_dev->fd_dev_name); fd_dev->fd_dev_name);
fd_dev->fbd_flags |= FBDF_HAS_PATH; fd_dev->fbd_flags |= FBDF_HAS_PATH;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment