Commit 32aecdd3 authored by Al Viro's avatar Al Viro

slightly reduce idiocy in drivers/staging/bcm/Misc.c

a) vfs_llseek() does *not* access userland pointers of any kind
b) neither does filp_close(), for that matter
c) ... nor filp_open()
d) vfs_read() does, but we do have a wrapper for that (kernel_read()),
so there's no need to reinvent it.
e) passing current->files to filp_close() on something that never
had been in descriptor table is pointless.

ISAGN: voodoo dolls to be used on voodoo programmers...
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent e4fad8e5
...@@ -157,12 +157,7 @@ static int create_worker_threads(PMINI_ADAPTER psAdapter) ...@@ -157,12 +157,7 @@ static int create_worker_threads(PMINI_ADAPTER psAdapter)
static struct file *open_firmware_file(PMINI_ADAPTER Adapter, const char *path) static struct file *open_firmware_file(PMINI_ADAPTER Adapter, const char *path)
{ {
struct file *flp = NULL; struct file *flp = filp_open(path, O_RDONLY, S_IRWXU);
mm_segment_t oldfs;
oldfs = get_fs();
set_fs(get_ds());
flp = filp_open(path, O_RDONLY, S_IRWXU);
set_fs(oldfs);
if (IS_ERR(flp)) { if (IS_ERR(flp)) {
pr_err(DRV_NAME "Unable To Open File %s, err %ld", path, PTR_ERR(flp)); pr_err(DRV_NAME "Unable To Open File %s, err %ld", path, PTR_ERR(flp));
flp = NULL; flp = NULL;
...@@ -183,14 +178,12 @@ static int BcmFileDownload(PMINI_ADAPTER Adapter, const char *path, unsigned int ...@@ -183,14 +178,12 @@ static int BcmFileDownload(PMINI_ADAPTER Adapter, const char *path, unsigned int
{ {
int errorno = 0; int errorno = 0;
struct file *flp = NULL; struct file *flp = NULL;
mm_segment_t oldfs;
struct timeval tv = {0}; struct timeval tv = {0};
flp = open_firmware_file(Adapter, path); flp = open_firmware_file(Adapter, path);
if (!flp) { if (!flp) {
errorno = -ENOENT;
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Unable to Open %s\n", path); BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Unable to Open %s\n", path);
goto exit_download; return -ENOENT;
} }
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Opened file is = %s and length =0x%lx to be downloaded at =0x%x", path, (unsigned long)flp->f_dentry->d_inode->i_size, loc); BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Opened file is = %s and length =0x%lx to be downloaded at =0x%x", path, (unsigned long)flp->f_dentry->d_inode->i_size, loc);
do_gettimeofday(&tv); do_gettimeofday(&tv);
...@@ -201,10 +194,7 @@ static int BcmFileDownload(PMINI_ADAPTER Adapter, const char *path, unsigned int ...@@ -201,10 +194,7 @@ static int BcmFileDownload(PMINI_ADAPTER Adapter, const char *path, unsigned int
errorno = -EIO; errorno = -EIO;
goto exit_download; goto exit_download;
} }
oldfs = get_fs();
set_fs(get_ds());
vfs_llseek(flp, 0, 0); vfs_llseek(flp, 0, 0);
set_fs(oldfs);
if (Adapter->bcm_file_readback_from_chip(Adapter->pvInterfaceAdapter, flp, loc)) { if (Adapter->bcm_file_readback_from_chip(Adapter->pvInterfaceAdapter, flp, loc)) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Failed to read back firmware!"); BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Failed to read back firmware!");
errorno = -EIO; errorno = -EIO;
...@@ -212,12 +202,7 @@ static int BcmFileDownload(PMINI_ADAPTER Adapter, const char *path, unsigned int ...@@ -212,12 +202,7 @@ static int BcmFileDownload(PMINI_ADAPTER Adapter, const char *path, unsigned int
} }
exit_download: exit_download:
oldfs = get_fs(); filp_close(flp, NULL);
set_fs(get_ds());
if (flp && !(IS_ERR(flp)))
filp_close(flp, current->files);
set_fs(oldfs);
return errorno; return errorno;
} }
...@@ -1080,10 +1065,8 @@ int InitCardAndDownloadFirmware(PMINI_ADAPTER ps_adapter) ...@@ -1080,10 +1065,8 @@ int InitCardAndDownloadFirmware(PMINI_ADAPTER ps_adapter)
static int bcm_parse_target_params(PMINI_ADAPTER Adapter) static int bcm_parse_target_params(PMINI_ADAPTER Adapter)
{ {
struct file *flp = NULL; struct file *flp = NULL;
mm_segment_t oldfs = {0};
char *buff; char *buff;
int len = 0; int len = 0;
loff_t pos = 0;
buff = kmalloc(BUFFER_1K, GFP_KERNEL); buff = kmalloc(BUFFER_1K, GFP_KERNEL);
if (!buff) if (!buff)
...@@ -1103,20 +1086,16 @@ static int bcm_parse_target_params(PMINI_ADAPTER Adapter) ...@@ -1103,20 +1086,16 @@ static int bcm_parse_target_params(PMINI_ADAPTER Adapter)
Adapter->pstargetparams = NULL; Adapter->pstargetparams = NULL;
return -ENOENT; return -ENOENT;
} }
oldfs = get_fs(); len = kernel_read(flp, 0, buff, BUFFER_1K);
set_fs(get_ds()); filp_close(flp, NULL);
len = vfs_read(flp, (void __user __force *)buff, BUFFER_1K, &pos);
set_fs(oldfs);
if (len != sizeof(STARGETPARAMS)) { if (len != sizeof(STARGETPARAMS)) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Mismatch in Target Param Structure!\n"); BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Mismatch in Target Param Structure!\n");
kfree(buff); kfree(buff);
kfree(Adapter->pstargetparams); kfree(Adapter->pstargetparams);
Adapter->pstargetparams = NULL; Adapter->pstargetparams = NULL;
filp_close(flp, current->files);
return -ENOENT; return -ENOENT;
} }
filp_close(flp, current->files);
/* Check for autolink in config params */ /* Check for autolink in config params */
/* /*
......
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