aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorMarek Belisko <marek.belisko@gmail.com>2010-10-07 08:36:37 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2010-10-07 13:10:59 -0400
commitada541f0cb03eb3c39016597470bd0aaaa1c6486 (patch)
tree01157a5929f9938b5343bb1197a8104de178672f /drivers
parent95624b2d75617bd16ffe4d698b645f468fbd0f20 (diff)
staging: ft1000-usb: Add correct procedure for fw image downloading.
call request_firmware instead of trying to open the file directly from the kernel driver. Signed-off-by: Marek Belisko <marek.belisko@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/staging/ft1000/ft1000-usb/ft1000_download.c63
-rw-r--r--drivers/staging/ft1000/ft1000-usb/ft1000_usb.c35
2 files changed, 26 insertions, 72 deletions
diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_download.c b/drivers/staging/ft1000/ft1000-usb/ft1000_download.c
index ba07d5d8504..1f7c7a67e1d 100644
--- a/drivers/staging/ft1000/ft1000-usb/ft1000_download.c
+++ b/drivers/staging/ft1000/ft1000-usb/ft1000_download.c
@@ -132,69 +132,6 @@ typedef struct _DSP_IMAGE_INFO_V6 {
132 unsigned short pad1; 132 unsigned short pad1;
133} DSP_IMAGE_INFO_V6, *PDSP_IMAGE_INFO_V6; 133} DSP_IMAGE_INFO_V6, *PDSP_IMAGE_INFO_V6;
134 134
135
136//---------------------------------------------------------------------------
137// Function: getfw
138//
139// Parameters: char *fn - input DSP image file name
140// int *pimgsz - output DSP image file size
141// Returns: DSP image buffer
142//
143// Description: Read the DSP image file into a char buffer
144//
145// Notes:
146//
147//---------------------------------------------------------------------------
148char *getfw (char *fn, size_t *pimgsz)
149{
150 struct file *fd;
151 mm_segment_t fs = get_fs();
152 loff_t pos;
153 char *pfwimg;
154 int fwimgsz;
155
156 set_fs(get_ds());
157
158 fd = filp_open(fn, 0, 0);
159 if ( IS_ERR(fd) )
160 {
161 DEBUG("FT1000:%s:can not open dsp image\n", __FUNCTION__);
162 set_fs(fs);
163 return NULL;
164 }
165
166 fwimgsz = i_size_read(fd->f_dentry->d_inode);
167 *pimgsz = fwimgsz;
168
169 if (fwimgsz <= 0)
170 {
171 DEBUG("FT1000:%s:invalid file size\n", __FUNCTION__);
172 filp_close(fd, current->files);
173 set_fs(fs);
174 return NULL;
175 }
176 pfwimg = (char*)vmalloc ( fwimgsz );
177 if (pfwimg == NULL) {
178 DEBUG("FT1000:%s:can not allocate memory for dsp image\n", __FUNCTION__);
179 filp_close(fd, current->files);
180 set_fs(fs);
181 return NULL;
182 }
183 pos = 0;
184 if (vfs_read(fd, (void __user __force*)pfwimg, fwimgsz, &pos) != fwimgsz) {
185 vfree(pfwimg);
186 DEBUG("FT1000:%s:failed to read firmware image\n",__FUNCTION__);
187 filp_close(fd, current->files);
188 set_fs(fs);
189 return NULL;
190 }
191
192 filp_close(fd, current->files);
193 set_fs(fs);
194
195 return pfwimg;
196}
197
198//--------------------------------------------------------------------------- 135//---------------------------------------------------------------------------
199// Function: check_usb_db 136// Function: check_usb_db
200// 137//
diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c b/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c
index 4aef1c43e61..3c9bb6d226f 100644
--- a/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c
+++ b/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c
@@ -13,6 +13,7 @@
13#include <linux/usb.h> 13#include <linux/usb.h>
14#include <linux/netdevice.h> 14#include <linux/netdevice.h>
15#include <linux/etherdevice.h> 15#include <linux/etherdevice.h>
16#include <linux/firmware.h>
16#include "ft1000_usb.h" 17#include "ft1000_usb.h"
17 18
18//#include <linux/sched.h> 19//#include <linux/sched.h>
@@ -88,10 +89,12 @@ static int ft1000_probe(struct usb_interface *interface, const struct usb_device
88 struct usb_endpoint_descriptor *endpoint; 89 struct usb_endpoint_descriptor *endpoint;
89 struct usb_device *dev; 90 struct usb_device *dev;
90 unsigned numaltsetting; 91 unsigned numaltsetting;
91 int i; 92 int i, ret = 0, size;
92 93
93 struct ft1000_device *ft1000dev; 94 struct ft1000_device *ft1000dev;
94 FT1000_INFO *pft1000info; 95 FT1000_INFO *pft1000info;
96 const struct firmware *dsp_fw;
97
95 98
96 if(!(ft1000dev = kmalloc(sizeof(struct ft1000_device), GFP_KERNEL))) 99 if(!(ft1000dev = kmalloc(sizeof(struct ft1000_device), GFP_KERNEL)))
97 { 100 {
@@ -149,14 +152,24 @@ static int ft1000_probe(struct usb_interface *interface, const struct usb_device
149 152
150 DEBUG("bulk_in=%d, bulk_out=%d\n", ft1000dev->bulk_in_endpointAddr, ft1000dev->bulk_out_endpointAddr); 153 DEBUG("bulk_in=%d, bulk_out=%d\n", ft1000dev->bulk_in_endpointAddr, ft1000dev->bulk_out_endpointAddr);
151 154
152 //read DSP image 155 ret = request_firmware(&dsp_fw, "ft3000.img", &dev->dev);
153 pFileStart = (void*)getfw("/etc/flarion/ft3000.img", &FileLength); 156 if (ret < 0) {
157 printk(KERN_ERR "Error request_firmware().\n");
158 goto err_fw;
159 }
154 160
155 if (pFileStart == NULL ) 161 size = max_t(uint, dsp_fw->size, 4096);
156 { 162 pFileStart = kmalloc(size, GFP_KERNEL);
157 DEBUG ("ft1000_probe: Read DSP image failed\n"); 163
158 return 0; 164 if (!pFileStart) {
159 } 165 release_firmware(dsp_fw);
166 ret = -ENOMEM;
167 goto err_fw;
168 }
169
170 memcpy(pFileStart, dsp_fw->data, dsp_fw->size);
171 FileLength = dsp_fw->size;
172 release_firmware(dsp_fw);
160 173
161 //for ( i=0; i< MAX_NUM_CARDS+2; i++) 174 //for ( i=0; i< MAX_NUM_CARDS+2; i++)
162 // pdevobj[i] = NULL; 175 // pdevobj[i] = NULL;
@@ -206,6 +219,10 @@ static int ft1000_probe(struct usb_interface *interface, const struct usb_device
206 ft1000InitProc(ft1000dev->net);// +mbelian 219 ft1000InitProc(ft1000dev->net);// +mbelian
207 220
208 return 0; 221 return 0;
222
223err_fw:
224 kfree(ft1000dev);
225 return ret;
209} 226}
210 227
211//--------------------------------------------------------------------------- 228//---------------------------------------------------------------------------
@@ -262,7 +279,7 @@ static void ft1000_disconnect(struct usb_interface *interface)
262 279
263 kfree(pft1000info->pFt1000Dev); //+mbelian 280 kfree(pft1000info->pFt1000Dev); //+mbelian
264 } 281 }
265 282 kfree(pFileStart);
266 //terminate other kernel threads 283 //terminate other kernel threads
267 //in multiple instances case, first find the device 284 //in multiple instances case, first find the device
268 //in the link list 285 //in the link list