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

Commit 7c51d177 authored by Al Viro's avatar Al Viro
Browse files

vt6656: slightly sanitized reading config



Just reading - parsing the results is left alone (and unspeakably
lousy).

Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 434b5a2e
Loading
Loading
Loading
Loading
+20 −43
Original line number Original line Diff line number Diff line
@@ -46,6 +46,7 @@
 */
 */
#undef __NO_VERSION__
#undef __NO_VERSION__


#include <linux/file.h>
#include "device.h"
#include "device.h"
#include "card.h"
#include "card.h"
#include "baseband.h"
#include "baseband.h"
@@ -1316,52 +1317,28 @@ static int Config_FileGetParameter(unsigned char *string,
/* if read fails, return NULL, or return data pointer */
/* if read fails, return NULL, or return data pointer */
static unsigned char *Config_FileOperation(struct vnt_private *pDevice)
static unsigned char *Config_FileOperation(struct vnt_private *pDevice)
{
{
    unsigned char *config_path = CONFIG_PATH;
	unsigned char *buffer = kmalloc(1024, GFP_KERNEL);
    unsigned char *buffer = NULL;
	struct file   *file;
    struct file   *filp=NULL;
    mm_segment_t old_fs = get_fs();

    int result = 0;

    set_fs (KERNEL_DS);

    /* open file */
      filp = filp_open(config_path, O_RDWR, 0);
        if (IS_ERR(filp)) {
	     printk("Config_FileOperation file Not exist\n");
	     result=-1;
             goto error2;
	  }

     if(!(filp->f_op) || !(filp->f_op->read) ||!(filp->f_op->write)) {
           printk("file %s is not read or writeable?\n",config_path);
	  result = -1;
	  goto error1;
     	}


    buffer = kmalloc(1024, GFP_KERNEL);
	if (!buffer) {
    if(buffer==NULL) {
		printk("allocate mem for file fail?\n");
		printk("allocate mem for file fail?\n");
      result = -1;
		return NULL;
      goto error1;
	}
	}


    if(filp->f_op->read(filp, buffer, 1024, &filp->f_pos)<0) {
	file = filp_open(CONFIG_PATH, O_RDONLY, 0);
     printk("read file error?\n");
	if (IS_ERR(file)) {
     result = -1;
		kfree(buffer);
		printk("Config_FileOperation file Not exist\n");
		return NULL;
	}
	}


error1:
	if (kernel_read(file, 0, buffer, 1024) < 0) {
  if(filp_close(filp,NULL))
		printk("read file error?\n");
       printk("Config_FileOperation:close file fail\n");

error2:
  set_fs (old_fs);

if(result!=0) {
		kfree(buffer);
		kfree(buffer);
		buffer = NULL;
		buffer = NULL;
	}
	}

	fput(file);
	return buffer;
	return buffer;
}
}