diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2013-04-06 18:11:22 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2013-04-09 15:16:50 -0400 |
commit | f805442e130c6eeb6c25bc5c3b3cefc27ab6dcec (patch) | |
tree | 1d5b6f736bdc3dc83cb10d31ff87d91959e6f521 | |
parent | 7c51d177f0eac50a85abc19e60e79c1dc58955d9 (diff) |
vt6655: slightly clean reading config file
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
-rw-r--r-- | drivers/staging/vt6655/device_main.c | 115 |
1 files changed, 40 insertions, 75 deletions
diff --git a/drivers/staging/vt6655/device_main.c b/drivers/staging/vt6655/device_main.c index 453c83d7fe8c..a89ab9bf38e4 100644 --- a/drivers/staging/vt6655/device_main.c +++ b/drivers/staging/vt6655/device_main.c | |||
@@ -60,6 +60,7 @@ | |||
60 | */ | 60 | */ |
61 | #undef __NO_VERSION__ | 61 | #undef __NO_VERSION__ |
62 | 62 | ||
63 | #include <linux/file.h> | ||
63 | #include "device.h" | 64 | #include "device.h" |
64 | #include "card.h" | 65 | #include "card.h" |
65 | #include "channel.h" | 66 | #include "channel.h" |
@@ -2946,87 +2947,51 @@ static int Config_FileGetParameter(unsigned char *string, | |||
2946 | return true; | 2947 | return true; |
2947 | } | 2948 | } |
2948 | 2949 | ||
2949 | int Config_FileOperation(PSDevice pDevice,bool fwrite,unsigned char *Parameter) { | 2950 | int Config_FileOperation(PSDevice pDevice,bool fwrite,unsigned char *Parameter) |
2950 | unsigned char *config_path = CONFIG_PATH; | 2951 | { |
2951 | unsigned char *buffer = NULL; | 2952 | unsigned char *buffer = kmalloc(1024, GFP_KERNEL); |
2952 | unsigned char tmpbuffer[20]; | 2953 | unsigned char tmpbuffer[20]; |
2953 | struct file *filp=NULL; | 2954 | struct file *file; |
2954 | mm_segment_t old_fs = get_fs(); | 2955 | int result=0; |
2955 | //int oldfsuid=0,oldfsgid=0; | ||
2956 | int result=0; | ||
2957 | |||
2958 | set_fs (KERNEL_DS); | ||
2959 | |||
2960 | /* Can't do this anymore, so we rely on correct filesystem permissions: | ||
2961 | //Make sure a caller can read or write power as root | ||
2962 | oldfsuid=current->cred->fsuid; | ||
2963 | oldfsgid=current->cred->fsgid; | ||
2964 | current->cred->fsuid = 0; | ||
2965 | current->cred->fsgid = 0; | ||
2966 | */ | ||
2967 | |||
2968 | //open file | ||
2969 | filp = filp_open(config_path, O_RDWR, 0); | ||
2970 | if (IS_ERR(filp)) { | ||
2971 | printk("Config_FileOperation:open file fail?\n"); | ||
2972 | result=-1; | ||
2973 | goto error2; | ||
2974 | } | ||
2975 | 2956 | ||
2976 | if(!(filp->f_op) || !(filp->f_op->read) ||!(filp->f_op->write)) { | 2957 | if (!buffer) { |
2977 | printk("file %s cann't readable or writable?\n",config_path); | 2958 | printk("allocate mem for file fail?\n"); |
2978 | result = -1; | 2959 | return -1; |
2979 | goto error1; | 2960 | } |
2980 | } | 2961 | file = filp_open(CONFIG_PATH, O_RDONLY, 0); |
2981 | 2962 | if (IS_ERR(file)) { | |
2982 | buffer = kmalloc(1024, GFP_KERNEL); | 2963 | kfree(buffer); |
2983 | if(buffer==NULL) { | 2964 | printk("Config_FileOperation:open file fail?\n"); |
2984 | printk("allocate mem for file fail?\n"); | 2965 | return -1; |
2985 | result = -1; | 2966 | } |
2986 | goto error1; | ||
2987 | } | ||
2988 | 2967 | ||
2989 | if(filp->f_op->read(filp, buffer, 1024, &filp->f_pos)<0) { | 2968 | if (kernel_read(file, 0, buffer, 1024) < 0) { |
2990 | printk("read file error?\n"); | 2969 | printk("read file error?\n"); |
2991 | result = -1; | 2970 | result = -1; |
2992 | goto error1; | 2971 | goto error1; |
2993 | } | 2972 | } |
2994 | 2973 | ||
2995 | if(Config_FileGetParameter("ZONETYPE",tmpbuffer,buffer)!=true) { | 2974 | if (Config_FileGetParameter("ZONETYPE",tmpbuffer,buffer)!=true) { |
2996 | printk("get parameter error?\n"); | 2975 | printk("get parameter error?\n"); |
2997 | result = -1; | 2976 | result = -1; |
2998 | goto error1; | 2977 | goto error1; |
2999 | } | 2978 | } |
3000 | 2979 | ||
3001 | if(memcmp(tmpbuffer,"USA",3)==0) { | 2980 | if (memcmp(tmpbuffer,"USA",3)==0) { |
3002 | result=ZoneType_USA; | 2981 | result = ZoneType_USA; |
3003 | } | 2982 | } else if(memcmp(tmpbuffer,"JAPAN",5)==0) { |
3004 | else if(memcmp(tmpbuffer,"JAPAN",5)==0) { | 2983 | result = ZoneType_Japan; |
3005 | result=ZoneType_Japan; | 2984 | } else if(memcmp(tmpbuffer,"EUROPE",5)==0) { |
3006 | } | 2985 | result = ZoneType_Europe; |
3007 | else if(memcmp(tmpbuffer,"EUROPE",5)==0) { | 2986 | } else { |
3008 | result=ZoneType_Europe; | 2987 | result = -1; |
3009 | } | 2988 | printk("Unknown Zonetype[%s]?\n",tmpbuffer); |
3010 | else { | 2989 | } |
3011 | result = -1; | ||
3012 | printk("Unknown Zonetype[%s]?\n",tmpbuffer); | ||
3013 | } | ||
3014 | 2990 | ||
3015 | error1: | 2991 | error1: |
3016 | kfree(buffer); | 2992 | kfree(buffer); |
3017 | 2993 | fput(file); | |
3018 | if(filp_close(filp,NULL)) | 2994 | return result; |
3019 | printk("Config_FileOperation:close file fail\n"); | ||
3020 | |||
3021 | error2: | ||
3022 | set_fs (old_fs); | ||
3023 | |||
3024 | /* | ||
3025 | current->cred->fsuid=oldfsuid; | ||
3026 | current->cred->fsgid=oldfsgid; | ||
3027 | */ | ||
3028 | |||
3029 | return result; | ||
3030 | } | 2995 | } |
3031 | 2996 | ||
3032 | 2997 | ||