staging ft1000-usb code cleanup patches.
cover staging ft1000-usb code cleanup patches.
This set of patches clean ft1000-usb driver from various problems like typedef usage, memory leaks and unused comments.
PATCH 1/4 staging: ft1000-usb: Remove global flag DSP_loading.
This patch remove global flag DSP_loading which was checked only on one place. Instead check return value for dsp_reload() function.
Signed-off-by Marek Belisko <[email protected]>
--- drivers/staging/ft1000/ft1000-usb/ft1000_hw.c | 12 ++++-------- drivers/staging/ft1000/ft1000-usb/ft1000_usb.c | 16 ++++++++-------- drivers/staging/ft1000/ft1000-usb/ft1000_usb.h | 3 +-- 3 files changed, 13 insertions(+), 18 deletions(-)
drivers/staging/ft1000/ft1000-usb/ft1000_hw.c +4 -8
@@ -685,7 +685,7 @@ void CardSendCommand(struct ft1000_device *ft1000dev, void *ptempbuffer, int siz// // Returns: None //----------------------------------------------------------------------- -void dsp_reload (struct ft1000_device *ft1000dev) +int dsp_reload (struct ft1000_device *ft1000dev) {u16 status;USHORT tempword;
@@ -696,7 +696,6 @@ void dsp_reload (struct ft1000_device *ft1000dev) pft1000info =netdev_priv (ft1000dev->net); pft1000info->CardReady =0 ; - pft1000info->DSP_loading=1 ;// Program Interrupt Mask register status =ft1000_write_register (ft1000dev,0xffff ,FT1000_REG_SUP_IMASK );
@@ -723,14 +722,13 @@ void dsp_reload (struct ft1000_device *ft1000dev)// call codeloader status =scram_dnldr (ft1000dev, pFileStart, FileLength); -if ( status !=STATUS_SUCCESS ) -return ; +if (status !=STATUS_SUCCESS ) +return -EIO ;msleep (1000 ); - pft1000info->DSP_loading=0 ;DEBUG ("dsp_reload returned\n" ); - +return 0 ; }
@@ -1054,7 +1052,6 @@ u16 init_ft1000_netdev(struct ft1000_device *ft1000dev) pInfo->CurrentInterruptEnableMask =ISR_DEFAULT_MASK ; pInfo->InterruptsEnabled = FALSE; pInfo->CardReady =0 ; - pInfo->DSP_loading =0 ; pInfo->DSP_TIME[0 ] =0 ; pInfo->DSP_TIME[1 ] =0 ; pInfo->DSP_TIME[2 ] =0 ;
@@ -2252,7 +2249,6 @@ static int ft1000_dsp_prov(void *arg) info->fProvComplete =1 ; info->CardReady =1 ; - info->DSP_loading=0 ;return STATUS_SUCCESS ; }
drivers/staging/ft1000/ft1000-usb/ft1000_usb.c +8 -8
@@ -182,18 +182,16 @@ static int ft1000_probe(struct usb_interface *interface, const struct usb_device// DEBUG("In probe: pft1000info=%x\n", pft1000info); // aelias [-] reason: warning: format ???%x??? expects type ???unsigned int???, but argument 2 has type ???struct FT1000_INFO *??? DEBUG ("In probe: pft1000info=%p\n" , pft1000info);// aelias [+] reason: up -dsp_reload (ft1000dev); + ret =dsp_reload (ft1000dev); +if (ret) { +printk (KERN_ERR "Problem with DSP image loading\n" ); + goto err_load; + } + gPollingfailed = FALSE;//mbelian pft1000info->pPollThread =kthread_run (ft1000_poll_thread, ft1000dev,"ft1000_poll" );msleep (500 );//mbelian - -if ( pft1000info->DSP_loading ) - { -DEBUG ("ERROR!!!! RETURN FROM ft1000_probe **********************\n" ); -return 0 ; - } -while (!pft1000info->CardReady) {if ( gPollingfailed )
@@ -220,6 +218,8 @@ static int ft1000_probe(struct usb_interface *interface, const struct usb_devicereturn 0 ; +err_load: +kfree (pFileStart); err_fw:kfree (ft1000dev);return ret;
drivers/staging/ft1000/ft1000-usb/ft1000_usb.h +1 -2
@@ -554,7 +554,6 @@ typedef struct _FT1000_INFO {int IOCTLBufLvl;int DeviceCreated;int CardReady; -int DSP_loading;int NetDevRegDone;u8 CardNumber;u8 DeviceName[15 ];
@@ -632,7 +631,7 @@ void ft1000_free_buffer (PDPRAM_BLK pdpram_blk, struct list_head *plist);char *getfw (char *fn,size_t *pimgsz); -void dsp_reload (struct ft1000_device *ft1000dev); +int dsp_reload (struct ft1000_device *ft1000dev);u16 init_ft1000_netdev (struct ft1000_device *ft1000dev);struct usb_interface ;u16 reg_ft1000_netdev (struct ft1000_device *ft1000dev,struct usb_interface *intf);
Signature · 1 line
1.7.1
PATCH 2/4 staging: ft1000: Fix memory leak when polling fail.
In reply to Marek BeliskoSigned-off-by Marek Belisko <[email protected]>
--- drivers/staging/ft1000/ft1000-usb/ft1000_usb.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
drivers/staging/ft1000/ft1000-usb/ft1000_usb.c +2 -1
@@ -200,7 +200,8 @@ static int ft1000_probe(struct usb_interface *interface, const struct usb_device {kthread_stop (pft1000info->pPollThread ); } -return 0 ; + ret = -EIO ; + goto err_load; }msleep (100 );DEBUG ("ft1000_probe::Waiting for Card Ready\n" );
Signature · 1 line
1.7.1
PATCH 3/4 staging: ft1000: Remove unused/unnecessary comments.
In reply to Marek BeliskoSigned-off-by Marek Belisko <[email protected]>
--- drivers/staging/ft1000/ft1000-usb/ft1000_usb.c | 50 ++++-------------------- 1 files changed, 8 insertions(+), 42 deletions(-)
drivers/staging/ft1000/ft1000-usb/ft1000_usb.c +8 -42
@@ -6,7 +6,6 @@// // $Id: //==================================================== -// 20090926; aelias; removed all compiler warnings; ubuntu 9.04; 2.6.28-15-generic #include <linux/init.h> #include <linux/kernel.h> #include <linux/module.h>
@@ -16,16 +15,6 @@#include <linux/firmware.h> #include "ft1000_usb.h" -//#include <linux/sched.h> -//#include <linux/ptrace.h> -//#include <linux/slab.h> -//#include <linux/string.h> -//#include <linux/timer.h> -//#include <linux/netdevice.h> -//#include <linux/ioport.h> -//#include <linux/delay.h> -//#include <asm/io.h> -//#include <asm/system.h> #include <linux/kthread.h> MODULE_DESCRIPTION ("FT1000 EXPRESS CARD DRIVER" );
@@ -65,8 +54,7 @@ int ft1000_poll_thread(void *arg) } } } -//DEBUG("returned from polling thread\n"); -return STATUS_SUCCESS ; +return STATUS_SUCCESS ; }
@@ -104,7 +92,6 @@ static int ft1000_probe(struct usb_interface *interface, const struct usb_devicememset (ft1000dev,0 ,sizeof (*ft1000dev)); -//get usb device dev =interface_to_usbdev (interface);DEBUG ("ft1000_probe: usb device descriptor info:\n" );DEBUG ("ft1000_probe: number of configuration is %d\n" , dev->descriptor.bNumConfigurations);
@@ -112,7 +99,6 @@ static int ft1000_probe(struct usb_interface *interface, const struct usb_device ft1000dev->dev = dev; ft1000dev->status =0 ; ft1000dev->net =NULL ; -//ft1000dev->device_lock = SPIN_LOCK_UNLOCKED; spin_lock_init (&ft1000dev->device_lock); ft1000dev->tx_urb =usb_alloc_urb (0 ,GFP_ATOMIC ); ft1000dev->rx_urb =usb_alloc_urb (0 ,GFP_ATOMIC );
@@ -171,26 +157,20 @@ static int ft1000_probe(struct usb_interface *interface, const struct usb_device FileLength = dsp_fw->size;release_firmware (dsp_fw); -//for ( i=0; i< MAX_NUM_CARDS+2; i++) -// pdevobj[i] = NULL; - -//download dsp image DEBUG ("ft1000_probe: start downloading dsp image...\n" );init_ft1000_netdev (ft1000dev); pft1000info = (FT1000_INFO *)netdev_priv (ft1000dev->net); -// DEBUG("In probe: pft1000info=%x\n", pft1000info); // aelias [-] reason: warning: format ???%x??? expects type ???unsigned int???, but argument 2 has type ???struct FT1000_INFO *??? -DEBUG ("In probe: pft1000info=%p\n" , pft1000info);// aelias [+] reason: up - +DEBUG ("In probe: pft1000info=%p\n" , pft1000info); ret =dsp_reload (ft1000dev);if (ret) {printk (KERN_ERR "Problem with DSP image loading\n" ); goto err_load; } - gPollingfailed = FALSE;//mbelian + gPollingfailed = FALSE; pft1000info->pPollThread =kthread_run (ft1000_poll_thread, ft1000dev,"ft1000_poll" ); -msleep (500 );//mbelian +msleep (500 );while (!pft1000info->CardReady) {
@@ -208,14 +188,13 @@ static int ft1000_probe(struct usb_interface *interface, const struct usb_device } -//initialize network device DEBUG ("ft1000_probe::Card Ready!!!! Registering network device\n" );reg_ft1000_netdev (ft1000dev, interface); pft1000info->NetDevRegDone =1 ; -ft1000InitProc (ft1000dev->net);// +mbelian +ft1000InitProc (ft1000dev->net);return 0 ;
@@ -245,14 +224,13 @@ static void ft1000_disconnect(struct usb_interface *interface)DEBUG ("ft1000_disconnect is called\n" ); pft1000info = (PFT1000_INFO )usb_get_intfdata (interface); -// DEBUG("In disconnect pft1000info=%x\n", pft1000info); // aelias [-] reason: warning: format ???%x??? expects type ???unsigned int???, but argument 2 has type ???struct FT1000_INFO *??? -DEBUG ("In disconnect pft1000info=%p\n" , pft1000info);// aelias [+] reason: up +DEBUG ("In disconnect pft1000info=%p\n" , pft1000info);if (pft1000info) { -ft1000CleanupProc (pft1000info);//+mbelian +ft1000CleanupProc (pft1000info);if ( pft1000info->pPollThread ) {kthread_stop (pft1000info->pPollThread );
@@ -264,9 +242,6 @@ static void ft1000_disconnect(struct usb_interface *interface) {DEBUG ("ft1000_disconnect: destroy char driver\n" );ft1000_DestroyDevice (pft1000info->pFt1000Dev->net); -//DEBUG("ft1000_disconnect: calling ft1000_close\n"); -//ft1000_close(pft1000info->pFt1000Dev->net); -//DEBUG("ft1000_disconnect: ft1000_close is called\n"); unregister_netdev (pft1000info->pFt1000Dev->net);DEBUG ("ft1000_disconnect: network device unregisterd\n" );free_netdev (pft1000info->pFt1000Dev->net);
@@ -278,23 +253,14 @@ static void ft1000_disconnect(struct usb_interface *interface)DEBUG ("ft1000_disconnect: urb freed\n" ); -kfree (pft1000info->pFt1000Dev);//+mbelian +kfree (pft1000info->pFt1000Dev); }kfree (pFileStart); -//terminate other kernel threads -//in multiple instances case, first find the device -//in the link list -/**if (pPollThread) -{ -kthread_stop(pPollThread); -DEBUG("Polling thread is killed \n"); -}**/ return ; }static struct usb_driver ft1000_usb_driver = { -//.owner = THIS_MODULE, .name ="ft1000usb" , .probe = ft1000_probe, .disconnect = ft1000_disconnect,
Signature · 1 line
1.7.1
PATCH 4/4 staging:ft1000: get rid of typedef usage.
In reply to Marek BeliskoSigned-off-by Marek Belisko <[email protected]>
--- .../staging/ft1000/ft1000-usb/ft1000_download.c | 42 +++++--------------- 1 files changed, 10 insertions(+), 32 deletions(-)
drivers/staging/ft1000/ft1000-usb/ft1000_download.c +10 -32
@@ -85,20 +85,7 @@#define DWNLD_MAG1_SIZE_LOC 0x02#define DWNLD_MAG1_PS_HDR_LOC 0x03 -#pragma pack (push, pack_save, 1) -typedef struct _DSP_FILE_HDR { -long build_date; -long dsp_coff_date; -long loader_code_address; -long loader_code_size; -long loader_code_end; -long dsp_code_address; -long dsp_code_size; -long dsp_code_end; -long reserved[8 ]; -}DSP_FILE_HDR , *PDSP_FILE_HDR ; - -typedef struct _DSP_FILE_HDR_5 { +struct dsp_file_hdr {long version_id;// Version ID of this image format. long package_id;// Package ID of code release. long build_date;// Date/time stamp when file was built.
@@ -110,18 +97,10 @@ typedef struct _DSP_FILE_HDR_5 {long version_data_offset;// Offset were scrambled version data begins. long version_data_size;// Size, in words, of scrambled version data. long nDspImages;// Number of DSP images in file. -}DSP_FILE_HDR_5 , *PDSP_FILE_HDR_5 ; +}; -typedef struct _DSP_IMAGE_INFO { -long coff_date;// Date/time when DSP Coff image was built. -long begin_offset;// Offset in file where image begins. -long end_offset;// Offset in file where image begins. -long run_address;// On chip Start address of DSP code. -long image_size;// Size of image. -long version;// Embedded version # of DSP code. -}DSP_IMAGE_INFO , *PDSP_IMAGE_INFO ; - -typedef struct _DSP_IMAGE_INFO_V6 { +#pragma pack(1) +struct dsp_image_info {long coff_date;// Date/time when DSP Coff image was built. long begin_offset;// Offset in file where image begins. long end_offset;// Offset in file where image begins.
@@ -130,7 +109,8 @@ typedef struct _DSP_IMAGE_INFO_V6 {long version;// Embedded version # of DSP code. unsigned short checksum;// DSP File checksum unsigned short pad1; -}DSP_IMAGE_INFO_V6 , *PDSP_IMAGE_INFO_V6 ; +}; +//--------------------------------------------------------------------------- // Function: check_usb_db
@@ -867,14 +847,13 @@ u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart, ULONG FileLePPSEUDO_HDR pHdr;USHORT usHdrLength;//PPROV_RECORD pProvRecord; -PDSP_FILE_HDR pFileHdr;long word_length;USHORT request;USHORT temp;USHORT tempword; -PDSP_FILE_HDR_5 pFileHdr5; -PDSP_IMAGE_INFO_V6 pDspImageInfoV6 =NULL ; +struct dsp_file_hdr *pFileHdr5; +struct dsp_image_info *pDspImageInfoV6 =NULL ;long requested_version;BOOLEAN bGoodVersion;PDRVMSG pMailBoxData;
@@ -907,8 +886,7 @@ u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart, ULONG FileLe uiState =STATE_START_DWNLD ; - pFileHdr = (PDSP_FILE_HDR )pFileStart; - pFileHdr5 = (PDSP_FILE_HDR_5 )pFileStart; + pFileHdr5 = (struct dsp_file_hdr *)pFileStart;ft1000_write_register (ft1000dev,0x800 ,FT1000_REG_MAG_WATERMARK );
@@ -1203,7 +1181,7 @@ u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart, ULONG FileLe bGoodVersion = FALSE; requested_version =get_request_value (ft1000dev); - pDspImageInfoV6 = (PDSP_IMAGE_INFO_V6 )(pFileStart +sizeof (DSP_FILE_HDR_5 )); + pDspImageInfoV6 = (struct dsp_image_info *)(pFileStart +sizeof (struct dsp_file_hdr ));for (imageN =0 ; imageN < pFileHdr5->nDspImages; imageN++) {
Signature · 1 line
1.7.1