Skip to contentSkip to conversation

staging fixes

PATCH In review Arnd Bergmann 2 participants 12 messages Sep 30, 2010 – Oct 4, 2010 Staging

lore
Share & tools
lore
#0 lore raw

cover staging fixes

My previous version of the first patch (staging: make new character devices nonseekable) was untested and broke compilation in multiple ways.

To make up for this, please take the fixed version and some patches to fix basic problems in those two drivers, as found by building with sparse.

Arnd

Arnd Bergmann (6):
staging: make new character devices nonseekable stagin/ft1000-usb: fix unlocked_ioctl prototype staging/ft1000-usb: fix build warnings staging/ft1000-usb: fix problems found by sparse staging/bcm: fix most build warnings staging/bcm: add sparse annotations

 drivers/staging/bcm/Adapter.h                      |    2 +-
 drivers/staging/bcm/Bcmchar.c                      |  168 ++++++++++----------
 drivers/staging/bcm/Bcmnet.c                       |    6 +-
 drivers/staging/bcm/CmHost.c                       |   18 +-
 drivers/staging/bcm/Debug.c                        |    2 +-
 drivers/staging/bcm/HandleControlPacket.c          |    2 +-
 drivers/staging/bcm/IPv6Protocol.c                 |    4 +-
 drivers/staging/bcm/InterfaceDld.c                 |    6 +-
 drivers/staging/bcm/InterfaceIdleMode.c            |    2 +-
 drivers/staging/bcm/InterfaceIdleMode.h            |    2 +-
 drivers/staging/bcm/InterfaceInit.c                |   31 ++--
 drivers/staging/bcm/Ioctl.h                        |    8 +-
 drivers/staging/bcm/LeakyBucket.c                  |   22 ++--
 drivers/staging/bcm/Macros.h                       |    2 +-
 drivers/staging/bcm/Misc.c                         |   20 ++-
 drivers/staging/bcm/PHSDefines.h                   |    2 +-
 drivers/staging/bcm/PHSModule.c                    |    2 +-
 drivers/staging/bcm/Prototypes.h                   |    3 +-
 drivers/staging/bcm/Qos.c                          |    8 +-
 drivers/staging/bcm/Transmit.c                     |    4 +-
 drivers/staging/bcm/led_control.c                  |   22 ++--
 drivers/staging/bcm/nvm.c                          |   54 +++---
 drivers/staging/ft1000/ft1000-usb/ft1000_chdev.c   |   92 ++++++------
 .../staging/ft1000/ft1000-usb/ft1000_download.c    |   45 +++---
 drivers/staging/ft1000/ft1000-usb/ft1000_hw.c      |   95 +++++-------
 drivers/staging/ft1000/ft1000-usb/ft1000_proc.c    |    2 +-
 drivers/staging/ft1000/ft1000-usb/ft1000_usb.c     |   25 +---
 drivers/staging/ft1000/ft1000-usb/ft1000_usb.h     |   43 +++++-
 28 files changed, 348 insertions(+), 344 deletions(-)
#1 lore raw

PATCH 1/6 staging: make new character devices nonseekable

As a preparation for changing the default behaviour of llseek to no_llseek, every file_operations structure should have a .llseek operation.

There are three new instances in staging now, which can all be changed into no_llseek explicitly since the devices do not need to seek.

Add nonseekable_open where appropriate, to prevent pread/pwrite as well.

---
 drivers/staging/bcm/Bcmchar.c                    |    5 +++++
 drivers/staging/bcm/InterfaceInit.c              |    1 +
 drivers/staging/ft1000/ft1000-usb/ft1000_chdev.c |   10 ++++++----
 3 files changed, 12 insertions(+), 4 deletions(-)
drivers/staging/bcm/Bcmchar.c +5 -0
index b239862..afde77a 100644
@@ -1,3 +1,5 @@
+#include <linux/fs.h>
+
 #include "headers.h"
 /***************************************************************
 * Function	  - bcm_char_open()
@@ -35,6 +37,8 @@ static int bcm_char_open(struct inode *inode, struct file * filp)
 
 	/*Start Queuing the control response Packets*/
 	atomic_inc(&Adapter->ApplicationRunning);
+
+	nonseekable_open(inode, filp);
 	return 0;
 }
 static int bcm_char_release(struct inode *inode, struct file *filp)
@@ -2360,6 +2364,7 @@ static struct file_operations bcm_fops = {
     .release  = bcm_char_release,
     .read     = bcm_char_read,
     .unlocked_ioctl    = bcm_char_ioctl,
+	.llseek = no_llseek,
 };
 
 
drivers/staging/bcm/InterfaceInit.c +1 -0
index d22a0e5..67d8572 100644
@@ -163,6 +163,7 @@ static struct file_operations usbbcm_fops = {
     .read    =  usbbcm_read,
     .write   =  usbbcm_write,
     .owner   =  THIS_MODULE,
+	.llseek = no_llseek,
 };
 
 static struct usb_class_driver usbbcm_class = {
drivers/staging/ft1000/ft1000-usb/ft1000_chdev.c +6 -4
index 65087ce..89d9a58 100644
@@ -81,10 +81,11 @@ int numofmsgbuf = 0;
 //
 static struct file_operations ft1000fops =
 {
-    unlocked_ioctl:    ft1000_ChIoctl,
-    poll:     ft1000_ChPoll,
-    open:     ft1000_ChOpen,
-    release:  ft1000_ChRelease
+	.unlocked_ioctl	= ft1000_ChIoctl,
+	.poll		= ft1000_ChPoll,
+	.open		= ft1000_ChOpen,
+	.release	= ft1000_ChRelease,
+	.llseek		= no_llseek,
 };
 
 
@@ -470,6 +471,7 @@ static int ft1000_ChOpen (struct inode *Inode, struct file *File)
 
     File->private_data = pdevobj[num]->net;
 
+	nonseekable_open(Inode, File);
     return 0;
 }
 
Signature · 1 line
1.7.1
#2 lore raw

PATCH 2/6 staging/ft1000-usb: fix unlocked_ioctl prototype

In reply to Arnd Bergmann

unlocked_ioctl has a "long" return type.

---
 drivers/staging/ft1000/ft1000-usb/ft1000_chdev.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/staging/ft1000/ft1000-usb/ft1000_chdev.c +2 -2
index 89d9a58..44b037c 100644
@@ -51,7 +51,7 @@ extern void CardSendCommand(struct ft1000_device *ft1000dev, unsigned short *pte
 
 static int ft1000_ChOpen (struct inode *Inode, struct file *File);
 static unsigned int ft1000_ChPoll(struct file *file, poll_table *wait);
-static int ft1000_ChIoctl(struct file *File, unsigned int Command,
+static long ft1000_ChIoctl(struct file *File, unsigned int Command,
                            unsigned long Argument);
 static int ft1000_ChRelease (struct inode *Inode, struct file *File);
 
@@ -536,7 +536,7 @@ static unsigned int ft1000_ChPoll(struct file *file, poll_table *wait)
 // Notes:
 //
 //---------------------------------------------------------------------------
-static int ft1000_ChIoctl (struct file *File, unsigned int Command,
+static long ft1000_ChIoctl (struct file *File, unsigned int Command,
                            unsigned long Argument)
 {
     struct net_device *dev;
Signature · 1 line
1.7.1
#3 lore raw

PATCH 3/6 staging/ft1000-usb: fix build warnings

In reply to Arnd Bergmann

This lets us see clearer when stuff breaks.

Most of the changes are fixes for casts between int and pointer that don't work on 64 bit.

The ioctl function uses a large amount of stack, which gets fixed by allocating the buffer dynamically.

---
 drivers/staging/ft1000/ft1000-usb/ft1000_chdev.c   |   44 +++++++++++--------
 .../staging/ft1000/ft1000-usb/ft1000_download.c    |    4 +-
 drivers/staging/ft1000/ft1000-usb/ft1000_hw.c      |    6 +-
 drivers/staging/ft1000/ft1000-usb/ft1000_usb.c     |    4 +-
 drivers/staging/ft1000/ft1000-usb/ft1000_usb.h     |    2 +-
 5 files changed, 33 insertions(+), 27 deletions(-)
drivers/staging/ft1000/ft1000-usb/ft1000_chdev.c +25 -19
index 44b037c..282deeb 100644
@@ -263,7 +263,7 @@ int ft1000_CreateDevice(struct ft1000_device *dev)
     //save the device info to global array
     pdevobj[info->CardNumber] = dev;
 
-    DEBUG("ft1000_CreateDevice: ******SAVED pdevobj[%d]=%x\n", info->CardNumber, (unsigned int)pdevobj[info->CardNumber]);	//aelias [+] reason:up
+    DEBUG("ft1000_CreateDevice: ******SAVED pdevobj[%d]=%p\n", info->CardNumber, pdevobj[info->CardNumber]);	//aelias [+] reason:up
 
     if (info->DeviceCreated)
     {
@@ -430,7 +430,7 @@ static int ft1000_ChOpen (struct inode *Inode, struct file *File)
     DEBUG("ft1000_ChOpen: minor number=%d\n", num);
 
     for (i=0; i<5; i++)
-        DEBUG("pdevobj[%d]=%x\n", i, (unsigned int)pdevobj[i]); //aelias [+] reason: down
+        DEBUG("pdevobj[%d]=%p\n", i, pdevobj[i]); //aelias [+] reason: down
 
     if ( pdevobj[num] != NULL )
         //info = (PFT1000_INFO)(pdevobj[num]->net->priv);
@@ -441,7 +441,7 @@ static int ft1000_ChOpen (struct inode *Inode, struct file *File)
         return -1;
     }
 
-    DEBUG("f_owner = 0x%8x number of application = %d\n", (u32)(&File->f_owner), info->appcnt );
+    DEBUG("f_owner = %p number of application = %d\n", (&File->f_owner), info->appcnt );
 
     // Check if maximum number of application exceeded
     if (info->appcnt > MAX_NUM_APP) {
@@ -451,7 +451,7 @@ static int ft1000_ChOpen (struct inode *Inode, struct file *File)
 
     // Search for available application info block
     for (i=0; i<MAX_NUM_APP; i++) {
-        if ( (info->app_info[i].fileobject == 0) ) {
+        if ( (info->app_info[i].fileobject == NULL) ) {
             break;
         }
     }
@@ -463,7 +463,7 @@ static int ft1000_ChOpen (struct inode *Inode, struct file *File)
     }
 
     info->appcnt++;
-    info->app_info[i].fileobject = (u32)(&File->f_owner);
+    info->app_info[i].fileobject = &File->f_owner;
     info->app_info[i].nTxMsg = 0;
     info->app_info[i].nRxMsg = 0;
     info->app_info[i].nTxMsgReject = 0;
@@ -503,7 +503,7 @@ static unsigned int ft1000_ChPoll(struct file *file, poll_table *wait)
 
     // Search for matching file object
     for (i=0; i<MAX_NUM_APP; i++) {
-        if ( info->app_info[i].fileobject == (u32)(&file->f_owner) ) {
+        if ( info->app_info[i].fileobject == &file->f_owner) {
             //DEBUG("FT1000:ft1000_ChIoctl: Message is for AppId = %d\n", info->app_info[i].app_id);
             break;
         }
@@ -587,7 +587,7 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
             if (tempword == DSPBCMSGID) {
                 // Search for matching file object
                 for (i=0; i<MAX_NUM_APP; i++) {
-                    if ( info->app_info[i].fileobject == (u32)(&File->f_owner) ) {
+                    if ( info->app_info[i].fileobject == &File->f_owner) {
                         info->app_info[i].DspBCMsgFlag = 1;
                         DEBUG("FT1000:ft1000_ChIoctl:Registered for broadcast messages\n");
                         break;
@@ -660,7 +660,7 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
         break;
     case IOCTL_SET_DPRAM_CMD:
         {
-            IOCTL_DPRAM_BLK dpram_data;
+            IOCTL_DPRAM_BLK *dpram_data;
             //IOCTL_DPRAM_COMMAND dpram_command;
             USHORT qtype;
             USHORT msgsz;
@@ -702,6 +702,11 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
                     break;
                 }
 
+		result = -ENOMEM;
+		dpram_data = kmalloc(msgsz + 2, GFP_KERNEL);
+		if (!dpram_data)
+			break;
+
                 //if ( copy_from_user(&(dpram_command.dpram_blk), (PIOCTL_DPRAM_BLK)Argument, msgsz+2) ) {
                 if ( copy_from_user(&dpram_data, (PIOCTL_DPRAM_BLK)Argument, msgsz+2) ) {
                     DEBUG("FT1000:ft1000_ChIoctl: copy fault occurred\n");
@@ -717,20 +722,21 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
 #endif
                     // Check if this message came from a registered application
                     for (i=0; i<MAX_NUM_APP; i++) {
-                        if ( info->app_info[i].fileobject == (u32)(&File->f_owner) ) {
+                        if ( info->app_info[i].fileobject == &File->f_owner) {
                             break;
                         }
                     }
                     if (i==MAX_NUM_APP) {
                         DEBUG("FT1000:No matching application fileobject\n");
                         result = -EINVAL;
+			kfree(dpram_data);
                         break;
                     }
                     app_index = i;
 
                     // Check message qtype type which is the lower byte within qos_class
                     //qtype = ntohs(dpram_command.dpram_blk.pseudohdr.qos_class) & 0xff;
-                    qtype = ntohs(dpram_data.pseudohdr.qos_class) & 0xff;
+                    qtype = ntohs(dpram_data->pseudohdr.qos_class) & 0xff;
                     //DEBUG("FT1000_ft1000_ChIoctl: qtype = %d\n", qtype);
                     if (qtype) {
                     }
@@ -756,6 +762,7 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
                                         if (tempword & FT1000_DB_DPRAM_TX) {
                                             DEBUG("FT1000:ft1000_ChIoctl:Doorbell not available\n");
                                             result = -ENOTTY;
+						kfree(dpram_data);
                                             break;
                                         }
                                     }
@@ -769,7 +776,7 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
                         if ( (msgsz < MAX_CMD_SQSIZE) && (msgsz > PSEUDOSZ) ) {
                             // Need to put sequence number plus new checksum for message
                             //pmsg = (PUSHORT)&dpram_command.dpram_blk.pseudohdr;
-                            pmsg = (PUSHORT)&dpram_data.pseudohdr;
+                            pmsg = (PUSHORT)&dpram_data->pseudohdr;
                             ppseudo_hdr = (PPSEUDO_HDR)pmsg;
                             total_len = msgsz+2;
                             if (total_len & 0x1) {
@@ -789,7 +796,7 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
                             pmsg++;
                             ppseudo_hdr = (PPSEUDO_HDR)pmsg;
 #if 0
-                            ptr = (char *)&dpram_data;
+                            ptr = dpram_data;
                             DEBUG("FT1000:ft1000_ChIoctl: Command Send\n");
                             for (i=0; i<total_len; i++) {
                                 DEBUG("FT1000:ft1000_ChIoctl: data %d = 0x%x\n", i, *ptr++);
@@ -798,15 +805,13 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
                             //dpram_command.extra = 0;
 
                             //CardSendCommand(ft1000dev,(unsigned char*)&dpram_command,total_len+2);
-                            CardSendCommand(ft1000dev,(unsigned short*)&dpram_data,total_len+2);
+                            CardSendCommand(ft1000dev,(unsigned short*)dpram_data,total_len+2);
 
 
                             info->app_info[app_index].nTxMsg++;
-                            break;
                         }
                         else {
                             result = -EINVAL;
-                            break;
                         }
                     }
                 }
@@ -815,13 +820,14 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
                 DEBUG("FT1000:ft1000_ChIoctl: Card not ready take messages\n");
                 result = -EACCES;
             }
+	    kfree(dpram_data);
 
         }
         break;
     case IOCTL_GET_DPRAM_CMD:
         {
             PDPRAM_BLK pdpram_blk;
-            PIOCTL_DPRAM_BLK pioctl_dpram;
+            IOCTL_DPRAM_BLK __user *pioctl_dpram;
             int msglen;
 
             //DEBUG("FT1000:ft1000_ChIoctl: IOCTL_FT1000_GET_DPRAM called\n");
@@ -832,7 +838,7 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
 
             // Search for matching file object
             for (i=0; i<MAX_NUM_APP; i++) {
-                if ( info->app_info[i].fileobject == (u32)(&File->f_owner) ) {
+                if ( info->app_info[i].fileobject == &File->f_owner) {
                     //DEBUG("FT1000:ft1000_ChIoctl: Message is for AppId = %d\n", info->app_info[i].app_id);
                     break;
                 }
@@ -856,7 +862,7 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
                 //DEBUG("FT1000:ft1000_ChIoctl:NumOfMsg for app %d = %d\n", i, info->app_info[i].NumOfMsg);
                 spin_unlock_irqrestore(&free_buff_lock, flags);
                 msglen = ntohs(*(u16 *)pdpram_blk->pbuffer) + PSEUDOSZ;
-                pioctl_dpram->total_len = htons(msglen);
+                pioctl_dpram->total_len = htons(msglen); /* XXX exploit here */
                 //DEBUG("FT1000:ft1000_ChIoctl:msg length = %x\n", msglen);
                 if(copy_to_user (&pioctl_dpram->pseudohdr, pdpram_blk->pbuffer, msglen))
 				{
@@ -910,7 +916,7 @@ static int ft1000_ChRelease (struct inode *Inode, struct file *File)
 
     // Search for matching file object
     for (i=0; i<MAX_NUM_APP; i++) {
-        if ( info->app_info[i].fileobject == (u32)(&File->f_owner) ) {
+        if ( info->app_info[i].fileobject == &File->f_owner) {
             //DEBUG("FT1000:ft1000_ChIoctl: Message is for AppId = %d\n", info->app_info[i].app_id);
             break;
         }
drivers/staging/ft1000/ft1000-usb/ft1000_download.c +2 -2
index 93f75b1..c71a1f4 100644
@@ -1356,8 +1356,8 @@ u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart, ULONG  FileLe
                     pprov_record->pprov_data = pbuffer;
                     list_add_tail (&pprov_record->list, &pft1000info->prov_list);
                     // Move to next entry if available
-                    pUcFile = (UCHAR *)((UINT)pUcFile + (UINT)((usHdrLength + 1) & 0xFFFFFFFE) + sizeof(PSEUDO_HDR));
-                    if ( (UINT)(pUcFile) - (UINT)(pFileStart) >= (UINT)FileLength) {
+                    pUcFile = (UCHAR *)((unsigned long)pUcFile + (UINT)((usHdrLength + 1) & 0xFFFFFFFE) + sizeof(PSEUDO_HDR));
+                    if ( (unsigned long)(pUcFile) - (unsigned long)(pFileStart) >= (unsigned long)FileLength) {
                        uiState = STATE_DONE_FILE;
                     }
                 }
drivers/staging/ft1000/ft1000-usb/ft1000_hw.c +3 -3
index 51ed0dd..4c3b1db 100644
@@ -1350,7 +1350,7 @@ static int ft1000_read_fifo_reg(struct ft1000_device *ft1000dev,unsigned int pip
 
         if(urb->status)
         {
-            printk("ft1000 control message failed (urb addr: %x) with error number: %i\n", (int)urb, (int)status);
+            printk("ft1000 control message failed (urb addr: %p) with error number: %i\n", urb, (int)status);
 
             usb_clear_halt(ft1000dev->dev, usb_rcvctrlpipe(ft1000dev->dev, 0));
             usb_clear_halt(ft1000dev->dev, usb_sndctrlpipe(ft1000dev->dev, 0));
@@ -1390,7 +1390,7 @@ static inline u16 ft1000_read_fifo_len (struct net_device *dev)
 	FT1000_INFO *info = (FT1000_INFO *) netdev_priv (dev);
     struct ft1000_device *ft1000dev = info->pFt1000Dev;
 //    DEBUG("ft1000_read_fifo_len: enter ft1000dev %x\n", ft1000dev);			//aelias [-] reason: warning: format ???%x??? expects type ???unsigned int???, but argument 2 has type ???struct ft1000_device *???
-    DEBUG("ft1000_read_fifo_len: enter ft1000dev %x\n", (unsigned int)ft1000dev);	//aelias [+] reason: up
+    DEBUG("ft1000_read_fifo_len: enter ft1000dev %p\n", ft1000dev);	//aelias [+] reason: up
     //ft1000_read_register(ft1000dev, &temp, FT1000_REG_MAG_UFSR);
 
     ret = STATUS_SUCCESS;
@@ -1882,7 +1882,7 @@ int ft1000_close(struct net_device *net)
     //usb_kill_urb(ft1000dev->tx_urb);
 
 
-    DEBUG("ft1000_close: pInfo=%x, ft1000dev=%x\n", (int)pInfo, (int)ft1000dev);
+    DEBUG("ft1000_close: pInfo=%p, ft1000dev=%p\n", pInfo, ft1000dev);
     netif_carrier_off(net);//mbelian
     netif_stop_queue(net);
     //DEBUG("ft1000_close: netif_stop_queue called\n");
drivers/staging/ft1000/ft1000-usb/ft1000_usb.c +2 -2
index 4dbc98b..f708c09 100644
@@ -184,7 +184,7 @@ static int ft1000_probe(struct usb_interface *interface, const struct usb_device
     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=%x\n", (unsigned int)pft1000info);		// aelias [+] reason: up
+    DEBUG("In probe: pft1000info=%p\n", pft1000info);		// aelias [+] reason: up
 
     dsp_reload(ft1000dev);
     gPollingfailed = FALSE;  //mbelian
@@ -245,7 +245,7 @@ static void ft1000_disconnect(struct usb_interface *interface)
 
     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=%x\n", (unsigned int) pft1000info);	// aelias [+] reason: up
+    DEBUG("In disconnect pft1000info=%p\n", pft1000info);	// aelias [+] reason: up
 
 
 
drivers/staging/ft1000/ft1000-usb/ft1000_usb.h +1 -1
index b0c611b..a64d468 100644
@@ -83,7 +83,7 @@ typedef struct _APP_INFO_BLOCK
     u32 nRxMsg;                    // DPRAM msg rcv from dsp with app_id
     u32 nTxMsgReject;              // DPRAM msg rejected due to DSP doorbell set
     u32 nRxMsgMiss;                // DPRAM msg dropped due to overflow
-    u32 fileobject;                // Application's file object
+    struct fown_struct *fileobject;// Application's file object
     u16 app_id;                    // Application id
     int DspBCMsgFlag;
     int NumOfMsg;                   // number of messages queued up
Signature · 1 line
1.7.1
#4 lore raw

Re: [PATCH 3/6] staging/ft1000-usb: fix build warnings

Quoted 130 lines · Arnd Bergmann

This lets us see clearer when stuff breaks.

Most of the changes are fixes for casts between int and pointer that don't work on 64 bit.

The ioctl function uses a large amount of stack, which gets fixed by allocating the buffer dynamically.

---
 drivers/staging/ft1000/ft1000-usb/ft1000_chdev.c   |   44 +++++++++++-------- .../staging/ft1000/ft1000-usb/ft1000_download.c    |    4 +- drivers/staging/ft1000/ft1000-usb/ft1000_hw.c      |    6 +- drivers/staging/ft1000/ft1000-usb/ft1000_usb.c     |    4 +- drivers/staging/ft1000/ft1000-usb/ft1000_usb.h     |    2 +-

 5 files changed, 33 insertions(+), 27 deletions(-)
drivers/staging/ft1000/ft1000-usb/ft1000_chdev.c +7 -7
index 44b037c..282deeb 100644
@@ -263,7 +263,7 @@ int ft1000_CreateDevice(struct ft1000_device *dev)
     //save the device info to global array
     pdevobj[info->CardNumber] = dev;
 
-    DEBUG("ft1000_CreateDevice: ******SAVED pdevobj[%d]=%x\n", info->CardNumber, (unsigned int)pdevobj[info->CardNumber]);     //aelias [+] reason:up
+    DEBUG("ft1000_CreateDevice: ******SAVED pdevobj[%d]=%p\n", info->CardNumber, pdevobj[info->CardNumber]);   //aelias [+] reason:up
 
     if (info->DeviceCreated)
     {
@@ -430,7 +430,7 @@ static int ft1000_ChOpen (struct inode *Inode, struct file *File)
     DEBUG("ft1000_ChOpen: minor number=%d\n", num);
 
     for (i=0; i<5; i++)
-        DEBUG("pdevobj[%d]=%x\n", i, (unsigned int)pdevobj[i]); //aelias [+] reason: down
+        DEBUG("pdevobj[%d]=%p\n", i, pdevobj[i]); //aelias [+] reason: down
 
     if ( pdevobj[num] != NULL )
         //info = (PFT1000_INFO)(pdevobj[num]->net->priv);
@@ -441,7 +441,7 @@ static int ft1000_ChOpen (struct inode *Inode, struct file *File)
         return -1;
     }
 
-    DEBUG("f_owner = 0x%8x number of application = %d\n", (u32)(&File->f_owner), info->appcnt );
+    DEBUG("f_owner = %p number of application = %d\n", (&File->f_owner), info->appcnt );
 
     // Check if maximum number of application exceeded
     if (info->appcnt > MAX_NUM_APP) {
@@ -451,7 +451,7 @@ static int ft1000_ChOpen (struct inode *Inode, struct file *File)
 
     // Search for available application info block
     for (i=0; i<MAX_NUM_APP; i++) {
-        if ( (info->app_info[i].fileobject == 0) ) {
+        if ( (info->app_info[i].fileobject == NULL) ) {
             break;
         }
     }
@@ -463,7 +463,7 @@ static int ft1000_ChOpen (struct inode *Inode, struct file *File)
     }
 
     info->appcnt++;
-    info->app_info[i].fileobject = (u32)(&File->f_owner);
+    info->app_info[i].fileobject = &File->f_owner;
     info->app_info[i].nTxMsg = 0;
     info->app_info[i].nRxMsg = 0;
     info->app_info[i].nTxMsgReject = 0;
@@ -503,7 +503,7 @@ static unsigned int ft1000_ChPoll(struct file *file, poll_table *wait)
 
     // Search for matching file object
     for (i=0; i<MAX_NUM_APP; i++) {
-        if ( info->app_info[i].fileobject == (u32)(&file->f_owner) ) {
+        if ( info->app_info[i].fileobject == &file->f_owner) {
             //DEBUG("FT1000:ft1000_ChIoctl: Message is for AppId = %d\n", info->app_info[i].app_id);
             break;
         }
@@ -587,7 +587,7 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
             if (tempword == DSPBCMSGID) {
                 // Search for matching file object
                 for (i=0; i<MAX_NUM_APP; i++) {
-                    if ( info->app_info[i].fileobject == (u32)(&File->f_owner) ) {
+                    if ( info->app_info[i].fileobject == &File->f_owner) {
                         info->app_info[i].DspBCMsgFlag = 1;
                         DEBUG("FT1000:ft1000_ChIoctl:Registered for broadcast messages\n");
                         break;
@@ -660,7 +660,7 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
         break;

    case IOCTL_SET_DPRAM_CMD:
        {
-            IOCTL_DPRAM_BLK dpram_data;
+            IOCTL_DPRAM_BLK *dpram_data;
            //IOCTL_DPRAM_COMMAND dpram_command;
            USHORT qtype;
            USHORT msgsz;

drivers/staging/ft1000/ft1000-usb/ft1000_chdev.c +8 -2
@@ -702,6 +702,11 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
                     break;
                 }
 
+               result = -ENOMEM;
+               dpram_data = kmalloc(msgsz + 2, GFP_KERNEL);
+               if (!dpram_data)
+                       break;
+
                 //if ( copy_from_user(&(dpram_command.dpram_blk), (PIOCTL_DPRAM_BLK)Argument, msgsz+2) ) {
                 if ( copy_from_user(&dpram_data, (PIOCTL_DPRAM_BLK)Argument, msgsz+2) ) {
                     DEBUG("FT1000:ft1000_ChIoctl: copy fault occurred\n");
@@ -717,20 +722,21 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
  #endif
                     // Check if this message came from a registered application
                     for (i=0; i<MAX_NUM_APP; i++) {
-                        if ( info->app_info[i].fileobject == (u32)(&File->f_owner) ) {
+                        if ( info->app_info[i].fileobject == &File->f_owner) {
                             break;
                         }
                     }
                     if (i==MAX_NUM_APP) {
                         DEBUG("FT1000:No matching application fileobject\n");
                         result = -EINVAL;
+                       kfree(dpram_data);
                         break;
                     }
                     app_index = i;
 
                     // Check message qtype type which is the lower byte within qos_class
                     //qtype = ntohs(dpram_command.dpram_blk.pseudohdr.qos_class) & 0xff;
-                    qtype = ntohs(dpram_data.pseudohdr.qos_class) & 0xff;
+                    qtype = ntohs(dpram_data->pseudohdr.qos_class) & 0xff;
                     //DEBUG("FT1000_ft1000_ChIoctl: qtype = %d\n", qtype);
                     if (qtype) {
                     }

drivers/staging/ft1000/ft1000-usb/ft1000_chdev.c static long ft1000_ChIoctl (struct file *File, unsigned int Command, · line 765

Quoted 4 lines
drivers/staging/ft1000/ft1000-usb/ft1000_chdev.c +1 -0
@@ -756,6 +762,7 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
                                         if (tempword & FT1000_DB_DPRAM_TX) {
                                             DEBUG("FT1000:ft1000_ChIoctl:Doorbell not available\n");
                                             result = -ENOTTY;
+                                               kfree(dpram_data);

is shift of kfree() needed or just a typo?

Quoted 156 lines
drivers/staging/ft1000/ft1000-usb/ft1000_chdev.c +4 -5
                                             break;
                                         }
                                     }
@@ -769,7 +776,7 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
                         if ( (msgsz < MAX_CMD_SQSIZE) && (msgsz > PSEUDOSZ) ) {
                             // Need to put sequence number plus new checksum for message
                             //pmsg = (PUSHORT)&dpram_command.dpram_blk.pseudohdr;
-                            pmsg = (PUSHORT)&dpram_data.pseudohdr;
+                            pmsg = (PUSHORT)&dpram_data->pseudohdr;
                             ppseudo_hdr = (PPSEUDO_HDR)pmsg;
                             total_len = msgsz+2;
                             if (total_len & 0x1) {
@@ -789,7 +796,7 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
                             pmsg++;
                             ppseudo_hdr = (PPSEUDO_HDR)pmsg;
  #if 0
-                            ptr = (char *)&dpram_data;
+                            ptr = dpram_data;
                             DEBUG("FT1000:ft1000_ChIoctl: Command Send\n");
                             for (i=0; i<total_len; i++) {
                                 DEBUG("FT1000:ft1000_ChIoctl: data %d = 0x%x\n", i, *ptr++);
@@ -798,15 +805,13 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
                             //dpram_command.extra = 0;
 
                             //CardSendCommand(ft1000dev,(unsigned char*)&dpram_command,total_len+2);
-                            CardSendCommand(ft1000dev,(unsigned short*)&dpram_data,total_len+2);
+                            CardSendCommand(ft1000dev,(unsigned short*)dpram_data,total_len+2);
 
 
                             info->app_info[app_index].nTxMsg++;
-                            break;
                         }
                         else {
                             result = -EINVAL;
-                            break;
                         }
                     }
                 }
@@ -815,13 +820,14 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
                 DEBUG("FT1000:ft1000_ChIoctl: Card not ready take messages\n");
                 result = -EACCES;
             }
+           kfree(dpram_data);
 
         }
         break;

    case IOCTL_GET_DPRAM_CMD:
        {
            PDPRAM_BLK pdpram_blk;
-            PIOCTL_DPRAM_BLK pioctl_dpram;
+            IOCTL_DPRAM_BLK __user *pioctl_dpram; int msglen;

            //DEBUG("FT1000:ft1000_ChIoctl: IOCTL_FT1000_GET_DPRAM called\n");

drivers/staging/ft1000/ft1000-usb/ft1000_chdev.c +3 -3
@@ -832,7 +838,7 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
 
             // Search for matching file object
             for (i=0; i<MAX_NUM_APP; i++) {
-                if ( info->app_info[i].fileobject == (u32)(&File->f_owner) ) {
+                if ( info->app_info[i].fileobject == &File->f_owner) {
                     //DEBUG("FT1000:ft1000_ChIoctl: Message is for AppId = %d\n", info->app_info[i].app_id);
                     break;
                 }
@@ -856,7 +862,7 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
                 //DEBUG("FT1000:ft1000_ChIoctl:NumOfMsg for app %d = %d\n", i, info->app_info[i].NumOfMsg);
                 spin_unlock_irqrestore(&free_buff_lock, flags);
                 msglen = ntohs(*(u16 *)pdpram_blk->pbuffer) + PSEUDOSZ;
-                pioctl_dpram->total_len = htons(msglen);
+                pioctl_dpram->total_len = htons(msglen); /* XXX exploit here */
                 //DEBUG("FT1000:ft1000_ChIoctl:msg length = %x\n", msglen);
                 if(copy_to_user (&pioctl_dpram->pseudohdr, pdpram_blk->pbuffer, msglen))
                                {
@@ -910,7 +916,7 @@ static int ft1000_ChRelease (struct inode *Inode, struct file *File)
 
     // Search for matching file object
     for (i=0; i<MAX_NUM_APP; i++) {
-        if ( info->app_info[i].fileobject == (u32)(&File->f_owner) ) {
+        if ( info->app_info[i].fileobject == &File->f_owner) {
             //DEBUG("FT1000:ft1000_ChIoctl: Message is for AppId = %d\n", info->app_info[i].app_id);
             break;
         }
drivers/staging/ft1000/ft1000-usb/ft1000_download.c +2 -2
index 93f75b1..c71a1f4 100644
@@ -1356,8 +1356,8 @@ u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart, ULONG  FileLe
                     pprov_record->pprov_data = pbuffer;
                     list_add_tail (&pprov_record->list, &pft1000info->prov_list);
                     // Move to next entry if available
-                    pUcFile = (UCHAR *)((UINT)pUcFile + (UINT)((usHdrLength + 1) & 0xFFFFFFFE) + sizeof(PSEUDO_HDR));
-                    if ( (UINT)(pUcFile) - (UINT)(pFileStart) >= (UINT)FileLength) {
+                    pUcFile = (UCHAR *)((unsigned long)pUcFile + (UINT)((usHdrLength + 1) & 0xFFFFFFFE) + sizeof(PSEUDO_HDR));
+                    if ( (unsigned long)(pUcFile) - (unsigned long)(pFileStart) >= (unsigned long)FileLength) {
                        uiState = STATE_DONE_FILE;
                     }
                 }
drivers/staging/ft1000/ft1000-usb/ft1000_hw.c +3 -3
index 51ed0dd..4c3b1db 100644
@@ -1350,7 +1350,7 @@ static int ft1000_read_fifo_reg(struct ft1000_device *ft1000dev,unsigned int pip
 
         if(urb->status)
         {
-            printk("ft1000 control message failed (urb addr: %x) with error number: %i\n", (int)urb, (int)status);
+            printk("ft1000 control message failed (urb addr: %p) with error number: %i\n", urb, (int)status);
 
             usb_clear_halt(ft1000dev->dev, usb_rcvctrlpipe(ft1000dev->dev, 0));
             usb_clear_halt(ft1000dev->dev, usb_sndctrlpipe(ft1000dev->dev, 0));
@@ -1390,7 +1390,7 @@ static inline u16 ft1000_read_fifo_len (struct net_device *dev)
        FT1000_INFO *info = (FT1000_INFO *) netdev_priv (dev);
     struct ft1000_device *ft1000dev = info->pFt1000Dev;
  //    DEBUG("ft1000_read_fifo_len: enter ft1000dev %x\n", ft1000dev);                  //aelias [-] reason: warning: format ???%x??? expects type ???unsigned int???, but argument 2 has type ???struct ft1000_device *???
-    DEBUG("ft1000_read_fifo_len: enter ft1000dev %x\n", (unsigned int)ft1000dev);      //aelias [+] reason: up
+    DEBUG("ft1000_read_fifo_len: enter ft1000dev %p\n", ft1000dev);    //aelias [+] reason: up
     //ft1000_read_register(ft1000dev, &temp, FT1000_REG_MAG_UFSR);
 
     ret = STATUS_SUCCESS;
@@ -1882,7 +1882,7 @@ int ft1000_close(struct net_device *net)
     //usb_kill_urb(ft1000dev->tx_urb);
 
 
-    DEBUG("ft1000_close: pInfo=%x, ft1000dev=%x\n", (int)pInfo, (int)ft1000dev);
+    DEBUG("ft1000_close: pInfo=%p, ft1000dev=%p\n", pInfo, ft1000dev);

    netif_carrier_off(net);//mbelian netif_stop_queue(net); //DEBUG("ft1000_close: netif_stop_queue called\n");

drivers/staging/ft1000/ft1000-usb/ft1000_usb.c +1 -1
index 4dbc98b..f708c09 100644
@@ -184,7 +184,7 @@ static int ft1000_probe(struct usb_interface *interface, const struct usb_device
     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=%x\n", (unsigned int)pft1000info);            // aelias [+] reason: up
+    DEBUG("In probe: pft1000info=%p\n", pft1000info);          // aelias [+] reason: up
 
     dsp_reload(ft1000dev);

    gPollingfailed = FALSE;  //mbelian

drivers/staging/ft1000/ft1000-usb/ft1000_usb.c +1 -1
@@ -245,7 +245,7 @@ static void ft1000_disconnect(struct usb_interface *interface)
 
     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=%x\n", (unsigned int) pft1000info);       // aelias [+] reason: up
+    DEBUG("In disconnect pft1000info=%p\n", pft1000info);      // aelias [+] reason: up
 
 
 
drivers/staging/ft1000/ft1000-usb/ft1000_usb.h +0 -0
index b0c611b..a64d468 100644
@@ -83,7 +83,7 @@ typedef struct _APP_INFO_BLOCK

    u32 nRxMsg;                    // DPRAM msg rcv from dsp with app_id u32 nTxMsgReject;              // DPRAM msg rejected due to DSP doorbell set

Quoted 10 lines

    u32 nRxMsgMiss;                // DPRAM msg dropped due to overflow
-    u32 fileobject;                // Application's file object
+    struct fown_struct *fileobject;// Application's file object u16 app_id;                    // Application id
    int DspBCMsgFlag;
    int NumOfMsg;                   // number of messages queued up --
1.7.1

Anyway there is also compilation warning:
In function ‘copy_from_user’,
inlined from ‘ft1000_ChIoctl’ at
drivers/staging/ft1000/ft1000-usb/ft1000_chdev.c:709:36:
/home/open-nandra/kernels/linux-next/arch/x86/include/asm/uaccess_32.h:212:26:
warning: call to ‘copy_from_user_overflow’ declared with attribute
warning: copy_from_user() buffer size is not provably correct

best regards,

marek

Signature · 10 lines
as simple and primitive as possible
-------------------------------------------------
Marek Belisko - OPEN-NANDRA
Freelance Developer

Ruska Nova Ves 219 | Presov, 08005 Slovak Republic
Tel: +421 915 052 184
skype: marekwhite
icq: 290551086
web: http://open-nandra.com
#5 lore raw

Re: [PATCH 3/6] staging/ft1000-usb: fix build warnings

Quoted 11 lines · Belisko Marek

drivers/staging/ft1000/ft1000-usb/ft1000_chdev.c static long ft1000_ChIoctl (struct file *File, unsigned int Command, · line 765

Quoted 7 lines
                    if (qtype) {
                    }
drivers/staging/ft1000/ft1000-usb/ft1000_chdev.c +1 -0
@@ -756,6 +762,7 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
                                        if (tempword & FT1000_DB_DPRAM_TX) {
                                            DEBUG("FT1000:ft1000_ChIoctl:Doorbell not available\n");
                                            result = -ENOTTY;
+                                               kfree(dpram_data);

is shift of kfree() needed or just a typo?

Quoted 3 lines
(quoted diff) +0 -0
                                            break;
                                        }
                                    }

Indentation in this driver is largely broken (should be using tabs only, but uses tabs and spaces). I didn't want to add to this, but I guess it doesn't matter much either way.

You should probably split larger functions into multiple smaller ones where sensible so you can do a proper reindentation of the whole driver.

Quoted 8 lines

Anyway there is also compilation warning:
In function ‘copy_from_user’,
inlined from ‘ft1000_ChIoctl’ at
drivers/staging/ft1000/ft1000-usb/ft1000_chdev.c:709:36:
/home/open-nandra/kernels/linux-next/arch/x86/include/asm/uaccess_32.h:212:26:
warning: call to ‘copy_from_user_overflow’ declared with attribute
warning: copy_from_user() buffer size is not provably correct

This warning is compiler dependent, so it didn't show up on my system. Just make an extra patch for it.

Arnd

#6 lore raw

PATCH 4/6 staging/ft1000-usb: fix problems found by sparse

In reply to Arnd Bergmann

In the original code, address space annotations are missing, which hides a possible unchecked user pointer access.

Two functions use a lot of stack space.

Extern declarations are all in the wrong place, which leads to type differences between caller and callee in some cases.

---
 drivers/staging/ft1000/ft1000-usb/ft1000_chdev.c   |   36 ++++-----
 .../staging/ft1000/ft1000-usb/ft1000_download.c    |   41 ++++-----
 drivers/staging/ft1000/ft1000-usb/ft1000_hw.c      |   89 ++++++++------------
 drivers/staging/ft1000/ft1000-usb/ft1000_proc.c    |    2 +-
 drivers/staging/ft1000/ft1000-usb/ft1000_usb.c     |   21 +----
 drivers/staging/ft1000/ft1000-usb/ft1000_usb.h     |   41 +++++++++-
 6 files changed, 110 insertions(+), 120 deletions(-)
drivers/staging/ft1000/ft1000-usb/ft1000_chdev.c +15 -21
index 282deeb..46e72e4 100644
@@ -41,13 +41,9 @@
 #include "ft1000_usb.h"
 //#include "ft1000_ioctl.h"
 
-void ft1000_DestroyDevice(struct net_device *dev);
-u16 ft1000_read_dpram16(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer, u8 highlow);
-u16 ft1000_read_register(struct ft1000_device *ft1000dev, short* Data, u16 nRegIndx);
+static int ft1000_flarion_cnt = 0;
 
-extern inline u16 ft1000_asic_read (struct net_device *dev, u16 offset);
-extern inline void ft1000_asic_write (struct net_device *dev, u16 offset, u16 value);
-extern void CardSendCommand(struct ft1000_device *ft1000dev, unsigned short *ptempbuffer, int size);
+//need to looking usage of ft1000Handle
 
 static int ft1000_ChOpen (struct inode *Inode, struct file *File);
 static unsigned int ft1000_ChPoll(struct file *file, poll_table *wait);
@@ -55,12 +51,6 @@ static long ft1000_ChIoctl(struct file *File, unsigned int Command,
                            unsigned long Argument);
 static int ft1000_ChRelease (struct inode *Inode, struct file *File);
 
-static int ft1000_flarion_cnt = 0;
-
-//need to looking usage of ft1000Handle
-
-
-
 // Global pointer to device object
 static struct ft1000_device *pdevobj[MAX_NUM_CARDS + 2];
 //static devfs_handle_t ft1000Handle[MAX_NUM_CARDS];
@@ -326,7 +316,7 @@ int ft1000_CreateDevice(struct ft1000_device *dev)
         info->app_info[i].nRxMsg = 0;
         info->app_info[i].nTxMsgReject = 0;
         info->app_info[i].nRxMsgMiss = 0;
-        info->app_info[i].fileobject = 0;
+        info->app_info[i].fileobject = NULL;
         info->app_info[i].app_id = i+1;
         info->app_info[i].DspBCMsgFlag = 0;
         info->app_info[i].NumOfMsg = 0;
@@ -539,6 +529,7 @@ static unsigned int ft1000_ChPoll(struct file *file, poll_table *wait)
 static long ft1000_ChIoctl (struct file *File, unsigned int Command,
                            unsigned long Argument)
 {
+    void __user *argp = (void __user *)Argument;
     struct net_device *dev;
     PFT1000_INFO info;
     struct ft1000_device *ft1000dev;
@@ -579,7 +570,7 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
     switch (cmd) {
     case IOCTL_REGISTER_CMD:
             DEBUG("FT1000:ft1000_ChIoctl: IOCTL_FT1000_REGISTER called\n");
-            result = get_user(tempword, (unsigned short *)Argument);
+            result = get_user(tempword, (__u16 __user*)argp);
             if (result) {
                 DEBUG("result = %d failed to get_user\n", result);
                 break;
@@ -601,7 +592,7 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
 
         get_ver_data.drv_ver = FT1000_DRV_VER;
 
-        if (copy_to_user((PIOCTL_GET_VER)Argument, &get_ver_data, sizeof(get_ver_data)) ) {
+        if (copy_to_user(argp, &get_ver_data, sizeof(get_ver_data)) ) {
             DEBUG("FT1000:ft1000_ChIoctl: copy fault occurred\n");
             result = -EFAULT;
             break;
@@ -651,7 +642,7 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
         do_gettimeofday ( &tv );
         get_stat_data.ConTm = (u32)(tv.tv_sec - info->ConTm);
         DEBUG("Connection Time = %d\n", (int)get_stat_data.ConTm);
-        if (copy_to_user((PIOCTL_GET_DSP_STAT)Argument, &get_stat_data, sizeof(get_stat_data)) ) {
+        if (copy_to_user(argp, &get_stat_data, sizeof(get_stat_data)) ) {
             DEBUG("FT1000:ft1000_ChIoctl: copy fault occurred\n");
             result = -EFAULT;
             break;
@@ -692,7 +683,7 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
                //DEBUG("FT1000:ft1000_ChIoctl: try to SET_DPRAM \n");
 
                 // Get the length field to see how many bytes to copy
-                result = get_user(msgsz, (unsigned short *)Argument);
+                result = get_user(msgsz, (__u16 __user *)argp);
                 msgsz = ntohs (msgsz);
                 //DEBUG("FT1000:ft1000_ChIoctl: length of message = %d\n", msgsz);
 
@@ -708,7 +699,7 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
 			break;
 
                 //if ( copy_from_user(&(dpram_command.dpram_blk), (PIOCTL_DPRAM_BLK)Argument, msgsz+2) ) {
-                if ( copy_from_user(&dpram_data, (PIOCTL_DPRAM_BLK)Argument, msgsz+2) ) {
+                if ( copy_from_user(&dpram_data, argp, msgsz+2) ) {
                     DEBUG("FT1000:ft1000_ChIoctl: copy fault occurred\n");
                     result = -EFAULT;
                 }
@@ -852,7 +843,7 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
             }
 
             result = 0;
-            pioctl_dpram = (PIOCTL_DPRAM_BLK)Argument;
+            pioctl_dpram = argp;
             if (list_empty(&info->app_info[i].app_sqlist) == 0) {
                 //DEBUG("FT1000:ft1000_ChIoctl:Message detected in slow queue\n");
                 spin_lock_irqsave(&free_buff_lock, flags);
@@ -862,7 +853,10 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
                 //DEBUG("FT1000:ft1000_ChIoctl:NumOfMsg for app %d = %d\n", i, info->app_info[i].NumOfMsg);
                 spin_unlock_irqrestore(&free_buff_lock, flags);
                 msglen = ntohs(*(u16 *)pdpram_blk->pbuffer) + PSEUDOSZ;
-                pioctl_dpram->total_len = htons(msglen); /* XXX exploit here */
+                result = get_user(msglen, &pioctl_dpram->total_len);
+		if (result)
+			break;
+		msglen = htons(msglen);
                 //DEBUG("FT1000:ft1000_ChIoctl:msg length = %x\n", msglen);
                 if(copy_to_user (&pioctl_dpram->pseudohdr, pdpram_blk->pbuffer, msglen))
 				{
@@ -935,7 +929,7 @@ static int ft1000_ChRelease (struct inode *Inode, struct file *File)
     // initialize application information
     info->appcnt--;
     DEBUG("ft1000_chdev:%s:appcnt = %d\n", __FUNCTION__, info->appcnt);
-    info->app_info[i].fileobject = 0;
+    info->app_info[i].fileobject = NULL;
 
     return 0;
 }
drivers/staging/ft1000/ft1000-usb/ft1000_download.c +17 -24

143 lines not on this page · raw message

drivers/staging/ft1000/ft1000-usb/ft1000_hw.c +36 -53

224 lines not on this page · raw message

drivers/staging/ft1000/ft1000-usb/ft1000_proc.c +1 -1
index 80faba5..d1ef396 100644
@@ -42,7 +42,7 @@ u16 ft1000_read_dpram16 (struct ft1000_device *ft1000dev, USHORT indx,
 			 PUCHAR buffer, u8 highlow);
 
 
-int
+static int
 ft1000ReadProc (char *page, char **start, off_t off, int count, int *eof,
 		void *data)
 {
drivers/staging/ft1000/ft1000-usb/ft1000_usb.c +2 -19
index f708c09..4aef1c4 100644
@@ -33,7 +33,7 @@ MODULE_SUPPORTED_DEVICE("QFT FT1000 Express Cards");
 
 
 void *pFileStart;
-ULONG FileLength;
+size_t FileLength;
 
 #define VENDOR_ID 0x1291   /* Qualcomm vendor id */
 #define PRODUCT_ID 0x11    /* fake product id */
@@ -46,24 +46,7 @@ static struct usb_device_id id_table[] = {
 
 MODULE_DEVICE_TABLE (usb, id_table);
 
-extern  struct ft1000_device *pdevobj[MAX_NUM_CARDS+2];
-
-char *getfw (char *fn, int *pimgsz);
-
-int ft1000_close(struct net_device *net);
-void dsp_reload (struct ft1000_device *ft1000dev);
-u16 init_ft1000_netdev(struct ft1000_device *ft1000dev);
-u16 reg_ft1000_netdev(struct ft1000_device *ft1000dev, struct usb_interface *intf);
-int ft1000_poll(void* dev_id);
-void ft1000_DestroyDevice(struct net_device *dev);
-u16 ft1000_read_dpram16(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer, u8 highlow);
-u16 ft1000_read_register(struct ft1000_device *ft1000dev, short* Data, u16 nRegIndx);
-BOOLEAN gPollingfailed = FALSE;
-
-void ft1000InitProc(struct net_device *dev);
-void ft1000CleanupProc(FT1000_INFO *info);
-int ft1000_poll_thread(void *arg);
-
+static BOOLEAN gPollingfailed = FALSE;
 int ft1000_poll_thread(void *arg)
 {
     int ret = STATUS_SUCCESS;
drivers/staging/ft1000/ft1000-usb/ft1000_usb.h +39 -2

58 lines not on this page · raw message

Signature · 1 line
1.7.1
#7 lore raw

Re: [PATCH 4/6] staging/ft1000-usb: fix problems found by sparse

I couldn't apply this patch with git. After manual patching it produce compilation errors.
Did you test it?

Quoted 672 lines · Arnd Bergmann

In the original code, address space annotations are missing, which hides a possible unchecked user pointer access.

Two functions use a lot of stack space.

Extern declarations are all in the wrong place, which leads to type differences between caller and callee in some cases.

---
 drivers/staging/ft1000/ft1000-usb/ft1000_chdev.c   |   36 ++++----- .../staging/ft1000/ft1000-usb/ft1000_download.c    |   41 ++++----- drivers/staging/ft1000/ft1000-usb/ft1000_hw.c      |   89 ++++++++------------

 drivers/staging/ft1000/ft1000-usb/ft1000_proc.c    |    2 +-
 drivers/staging/ft1000/ft1000-usb/ft1000_usb.c     |   21 +----
 drivers/staging/ft1000/ft1000-usb/ft1000_usb.h     |   41 +++++++++-
 6 files changed, 110 insertions(+), 120 deletions(-)
drivers/staging/ft1000/ft1000-usb/ft1000_chdev.c +4 -13
index 282deeb..46e72e4 100644
@@ -41,13 +41,9 @@
  #include "ft1000_usb.h"
  //#include "ft1000_ioctl.h"
 
-void ft1000_DestroyDevice(struct net_device *dev);
-u16 ft1000_read_dpram16(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer, u8 highlow);
-u16 ft1000_read_register(struct ft1000_device *ft1000dev, short* Data, u16 nRegIndx);
+static int ft1000_flarion_cnt = 0;
 
-extern inline u16 ft1000_asic_read (struct net_device *dev, u16 offset);
-extern inline void ft1000_asic_write (struct net_device *dev, u16 offset, u16 value);
-extern void CardSendCommand(struct ft1000_device *ft1000dev, unsigned short *ptempbuffer, int size);
+//need to looking usage of ft1000Handle
 
  static int ft1000_ChOpen (struct inode *Inode, struct file *File);
  static unsigned int ft1000_ChPoll(struct file *file, poll_table *wait);
@@ -55,12 +51,6 @@ static long ft1000_ChIoctl(struct file *File, unsigned int Command,
                            unsigned long Argument);
  static int ft1000_ChRelease (struct inode *Inode, struct file *File);
 
-static int ft1000_flarion_cnt = 0;
-
-//need to looking usage of ft1000Handle
-
-
-
  // Global pointer to device object
  static struct ft1000_device *pdevobj[MAX_NUM_CARDS + 2];
  //static devfs_handle_t ft1000Handle[MAX_NUM_CARDS];
@@ -326,7 +316,7 @@ int ft1000_CreateDevice(struct ft1000_device *dev)
         info->app_info[i].nRxMsg = 0;
         info->app_info[i].nTxMsgReject = 0;
         info->app_info[i].nRxMsgMiss = 0;
-        info->app_info[i].fileobject = 0;
+        info->app_info[i].fileobject = NULL;
         info->app_info[i].app_id = i+1;
         info->app_info[i].DspBCMsgFlag = 0;
         info->app_info[i].NumOfMsg = 0;
@@ -539,6 +529,7 @@ static unsigned int ft1000_ChPoll(struct file *file, poll_table *wait)
  static long ft1000_ChIoctl (struct file *File, unsigned int Command,
                            unsigned long Argument)
  {
+    void __user *argp = (void __user *)Argument;
     struct net_device *dev;
     PFT1000_INFO info;
     struct ft1000_device *ft1000dev;
@@ -579,7 +570,7 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
     switch (cmd) {

    case IOCTL_REGISTER_CMD:
            DEBUG("FT1000:ft1000_ChIoctl: IOCTL_FT1000_REGISTER called\n");
-            result = get_user(tempword, (unsigned short *)Argument);
+            result = get_user(tempword, (__u16 __user*)argp); if (result) {
                DEBUG("result = %d failed to get_user\n", result); break;

drivers/staging/ft1000/ft1000-usb/ft1000_chdev.c +10 -7
@@ -601,7 +592,7 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
 
         get_ver_data.drv_ver = FT1000_DRV_VER;
 
-        if (copy_to_user((PIOCTL_GET_VER)Argument, &get_ver_data, sizeof(get_ver_data)) ) {
+        if (copy_to_user(argp, &get_ver_data, sizeof(get_ver_data)) ) {
             DEBUG("FT1000:ft1000_ChIoctl: copy fault occurred\n");
             result = -EFAULT;
             break;
@@ -651,7 +642,7 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
         do_gettimeofday ( &tv );
         get_stat_data.ConTm = (u32)(tv.tv_sec - info->ConTm);
         DEBUG("Connection Time = %d\n", (int)get_stat_data.ConTm);
-        if (copy_to_user((PIOCTL_GET_DSP_STAT)Argument, &get_stat_data, sizeof(get_stat_data)) ) {
+        if (copy_to_user(argp, &get_stat_data, sizeof(get_stat_data)) ) {
             DEBUG("FT1000:ft1000_ChIoctl: copy fault occurred\n");
             result = -EFAULT;
             break;
@@ -692,7 +683,7 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
                //DEBUG("FT1000:ft1000_ChIoctl: try to SET_DPRAM \n");
 
                 // Get the length field to see how many bytes to copy
-                result = get_user(msgsz, (unsigned short *)Argument);
+                result = get_user(msgsz, (__u16 __user *)argp);
                 msgsz = ntohs (msgsz);
                 //DEBUG("FT1000:ft1000_ChIoctl: length of message = %d\n", msgsz);
 
@@ -708,7 +699,7 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
                        break;
 
                 //if ( copy_from_user(&(dpram_command.dpram_blk), (PIOCTL_DPRAM_BLK)Argument, msgsz+2) ) {
-                if ( copy_from_user(&dpram_data, (PIOCTL_DPRAM_BLK)Argument, msgsz+2) ) {
+                if ( copy_from_user(&dpram_data, argp, msgsz+2) ) {
                     DEBUG("FT1000:ft1000_ChIoctl: copy fault occurred\n");
                     result = -EFAULT;
                 }
@@ -852,7 +843,7 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
             }
 
             result = 0;
-            pioctl_dpram = (PIOCTL_DPRAM_BLK)Argument;
+            pioctl_dpram = argp;
             if (list_empty(&info->app_info[i].app_sqlist) == 0) {
                 //DEBUG("FT1000:ft1000_ChIoctl:Message detected in slow queue\n");
                 spin_lock_irqsave(&free_buff_lock, flags);
@@ -862,7 +853,10 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
                 //DEBUG("FT1000:ft1000_ChIoctl:NumOfMsg for app %d = %d\n", i, info->app_info[i].NumOfMsg);
                 spin_unlock_irqrestore(&free_buff_lock, flags);
                 msglen = ntohs(*(u16 *)pdpram_blk->pbuffer) + PSEUDOSZ;
-                pioctl_dpram->total_len = htons(msglen); /* XXX exploit here */
+                result = get_user(msglen, &pioctl_dpram->total_len);
+               if (result)
+                       break;
+               msglen = htons(msglen);
                 //DEBUG("FT1000:ft1000_ChIoctl:msg length = %x\n", msglen);
                 if(copy_to_user (&pioctl_dpram->pseudohdr, pdpram_blk->pbuffer, msglen))
                                {
@@ -935,7 +929,7 @@ static int ft1000_ChRelease (struct inode *Inode, struct file *File)
     // initialize application information
     info->appcnt--;
     DEBUG("ft1000_chdev:%s:appcnt = %d\n", __FUNCTION__, info->appcnt);
-    info->app_info[i].fileobject = 0;
+    info->app_info[i].fileobject = NULL;
 
     return 0;
  }
drivers/staging/ft1000/ft1000-usb/ft1000_download.c +17 -24
index c71a1f4..ba07d5d 100644
@@ -133,15 +133,6 @@ typedef struct _DSP_IMAGE_INFO_V6 {
  } DSP_IMAGE_INFO_V6, *PDSP_IMAGE_INFO_V6;
 
 
-u16 ft1000_read_register(struct ft1000_device *ft1000dev, short* Data, u16 nRegIndx);
-u16 ft1000_write_register(struct ft1000_device *ft1000dev, USHORT value, u16 nRegIndx);
-u16 ft1000_read_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer, USHORT cnt);
-u16 ft1000_write_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer, USHORT cnt);
-u16 ft1000_read_dpram16(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer, u8 highlow);
-u16 ft1000_write_dpram16(struct ft1000_device *ft1000dev, USHORT indx, USHORT value, u8 highlow);
-u16 fix_ft1000_read_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer);
-u16 fix_ft1000_write_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer);
-
  //---------------------------------------------------------------------------
  // Function:    getfw
  //
@@ -154,7 +145,7 @@ u16 fix_ft1000_write_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHA
  // Notes:
  //
  //---------------------------------------------------------------------------
-char *getfw (char *fn, int *pimgsz)
+char *getfw (char *fn, size_t *pimgsz)
  {
     struct file *fd;
     mm_segment_t fs = get_fs();
@@ -190,7 +181,7 @@ char *getfw (char *fn, int *pimgsz)
         return NULL;
     }
     pos = 0;
-    if (vfs_read(fd, pfwimg, fwimgsz, &pos) != fwimgsz) {
+    if (vfs_read(fd, (void __user __force*)pfwimg, fwimgsz, &pos) != fwimgsz) {
        vfree(pfwimg);
        DEBUG("FT1000:%s:failed to read firmware image\n",__FUNCTION__);
        filp_close(fd, current->files);
@@ -216,7 +207,7 @@ char *getfw (char *fn, int *pimgsz)
  // Notes:
  //
  //---------------------------------------------------------------------------
-ULONG check_usb_db (struct ft1000_device *ft1000dev)
+static ULONG check_usb_db (struct ft1000_device *ft1000dev)
  {
    int               loopcnt;
    USHORT            temp;
@@ -295,7 +286,7 @@ ULONG check_usb_db (struct ft1000_device *ft1000dev)
  // Notes:
  //
  //---------------------------------------------------------------------------
-USHORT get_handshake(struct ft1000_device *ft1000dev, USHORT expected_value)
+static USHORT get_handshake(struct ft1000_device *ft1000dev, USHORT expected_value)
  {
    USHORT            handshake;
    int               loopcnt;
@@ -406,7 +397,7 @@ USHORT get_handshake(struct ft1000_device *ft1000dev, USHORT expected_value)
  // Notes:
  //
  //---------------------------------------------------------------------------
-void put_handshake(struct ft1000_device *ft1000dev,USHORT handshake_value)
+static void put_handshake(struct ft1000_device *ft1000dev,USHORT handshake_value)
  {
     ULONG tempx;
     USHORT tempword;
@@ -442,7 +433,7 @@ void put_handshake(struct ft1000_device *ft1000dev,USHORT handshake_value)
 
  }
 
-USHORT get_handshake_usb(struct ft1000_device *ft1000dev, USHORT expected_value)
+static USHORT get_handshake_usb(struct ft1000_device *ft1000dev, USHORT expected_value)
  {
    USHORT            handshake;
    int               loopcnt;
@@ -482,7 +473,7 @@ USHORT get_handshake_usb(struct ft1000_device *ft1000dev, USHORT expected_value)
    return HANDSHAKE_TIMEOUT_VALUE;
  }
 
-void put_handshake_usb(struct ft1000_device *ft1000dev,USHORT handshake_value)
+static void put_handshake_usb(struct ft1000_device *ft1000dev,USHORT handshake_value)
  {
    int i;
 
@@ -501,7 +492,7 @@ void put_handshake_usb(struct ft1000_device *ft1000dev,USHORT handshake_value)
  // Notes:
  //
  //---------------------------------------------------------------------------
-USHORT get_request_type(struct ft1000_device *ft1000dev)
+static USHORT get_request_type(struct ft1000_device *ft1000dev)
  {
    USHORT   request_type;
    ULONG    status;
@@ -533,7 +524,7 @@ USHORT get_request_type(struct ft1000_device *ft1000dev)
 
  }
 
-USHORT get_request_type_usb(struct ft1000_device *ft1000dev)
+static USHORT get_request_type_usb(struct ft1000_device *ft1000dev)
  {
    USHORT   request_type;
    ULONG    status;
@@ -577,7 +568,7 @@ USHORT get_request_type_usb(struct ft1000_device *ft1000dev)
  // Notes:
  //
  //---------------------------------------------------------------------------
-long get_request_value(struct ft1000_device *ft1000dev)
+static long get_request_value(struct ft1000_device *ft1000dev)
  {
    ULONG     value;
    USHORT   tempword;
@@ -605,7 +596,8 @@ long get_request_value(struct ft1000_device *ft1000dev)
 
  }
 
-long get_request_value_usb(struct ft1000_device *ft1000dev)
+#if 0
+static long get_request_value_usb(struct ft1000_device *ft1000dev)
  {
    ULONG     value;
    USHORT   tempword;
@@ -633,6 +625,7 @@ long get_request_value_usb(struct ft1000_device *ft1000dev)
    return value;
 
  }
+#endif
 
  //---------------------------------------------------------------------------
  // Function:    put_request_value
@@ -647,7 +640,7 @@ long get_request_value_usb(struct ft1000_device *ft1000dev)
  // Notes:
  //
  //---------------------------------------------------------------------------
-void put_request_value(struct ft1000_device *ft1000dev, long lvalue)
+static void put_request_value(struct ft1000_device *ft1000dev, long lvalue)
  {
    ULONG    tempx;
    ULONG    status;
@@ -675,7 +668,7 @@ void put_request_value(struct ft1000_device *ft1000dev, long lvalue)
  // Notes:
  //
  //---------------------------------------------------------------------------
-USHORT hdr_checksum(PPSEUDO_HDR pHdr)
+static USHORT hdr_checksum(PPSEUDO_HDR pHdr)
  {
    USHORT   *usPtr = (USHORT *)pHdr;
    USHORT   chksum;
@@ -705,7 +698,7 @@ USHORT hdr_checksum(PPSEUDO_HDR pHdr)
  // Notes:
  //
  //---------------------------------------------------------------------------
-ULONG write_blk (struct ft1000_device *ft1000dev, USHORT **pUsFile, UCHAR **pUcFile, long word_length)
+static ULONG write_blk (struct ft1000_device *ft1000dev, USHORT **pUsFile, UCHAR **pUcFile, long word_length)
  {
    ULONG Status = STATUS_SUCCESS;
    USHORT dpram;
@@ -861,7 +854,7 @@ static void usb_dnld_complete (struct urb *urb)
  // Notes:
  //
  //---------------------------------------------------------------------------
-ULONG write_blk_fifo (struct ft1000_device *ft1000dev, USHORT **pUsFile, UCHAR **pUcFile, long word_length)
+static ULONG write_blk_fifo (struct ft1000_device *ft1000dev, USHORT **pUsFile, UCHAR **pUcFile, long word_length)
  {
    ULONG Status = STATUS_SUCCESS;
    int byte_length;
drivers/staging/ft1000/ft1000-usb/ft1000_hw.c +10 -32
index 4c3b1db..44395c0 100644
@@ -35,24 +35,12 @@
 
  //#define JDEBUG
 
-
-extern void *pFileStart;
-extern ULONG FileLength;
-
-
-extern int numofmsgbuf;
-
-
-int ft1000_poll_thread(void *arg);
-
+static int ft1000_reset(struct net_device *ft1000dev);
+static int ft1000_submit_rx_urb(PFT1000_INFO info);
  static void ft1000_hbchk(u_long data);
-int ft1000_reset(struct net_device *ft1000dev);
  static int ft1000_start_xmit(struct sk_buff *skb, struct net_device *dev);
  static int ft1000_open (struct net_device *dev);
-int ft1000_close (struct net_device *dev);
  static struct net_device_stats *ft1000_netdev_stats(struct net_device *dev);
-u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart, ULONG  FileLength);
-int ft1000_submit_rx_urb(PFT1000_INFO info);
  static struct timer_list poll_timer[MAX_NUM_CARDS];
  static int ft1000_chkcard (struct ft1000_device *dev);
  /*
@@ -67,21 +55,11 @@ static const struct net_device_ops ft1000net_ops = {
  //Jim
 
  static u8 tempbuffer[1600];
-int gCardIndex;
+static int gCardIndex;
 
  #define MAX_RCV_LOOP   100
 
 
-extern struct list_head freercvpool;
-extern spinlock_t free_buff_lock;   // lock to arbitrate free buffer list for receive command data
-
-//end of Jim
-
-extern int ft1000_CreateDevice(struct ft1000_device *dev);
-extern PDPRAM_BLK ft1000_get_buffer (struct list_head *bufflist);
-extern void ft1000_free_buffer (PDPRAM_BLK pdpram_blk, struct list_head *plist);
-
-
  static int atoi(const char *s)
  {
         int k = 0;
@@ -207,7 +185,7 @@ static int ft1000_control(struct ft1000_device *ft1000dev,unsigned int pipe,
  //
  //---------------------------------------------------------------------------
 
-u16 ft1000_read_register(struct ft1000_device *ft1000dev, short* Data, u16 nRegIndx)
+u16 ft1000_read_register(struct ft1000_device *ft1000dev, u16* Data, u16 nRegIndx)
  {
     u16 ret = STATUS_SUCCESS;
 
@@ -472,20 +450,20 @@ u16 ft1000_write_dpram16(struct ft1000_device *ft1000dev, USHORT indx, USHORT va
  //---------------------------------------------------------------------------
  u16 fix_ft1000_read_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer)
  {
-    UCHAR tempbuffer[16];
+    UCHAR buf[16];
     USHORT pos;
     u16 ret = STATUS_SUCCESS;
 
     //DEBUG("fix_ft1000_read_dpram32: indx: %d  \n", indx);
     pos = (indx / 4)*4;
-    ret = ft1000_read_dpram32(ft1000dev, pos, (PUCHAR)&tempbuffer[0], 16);
+    ret = ft1000_read_dpram32(ft1000dev, pos, buf, 16);
     if (ret == STATUS_SUCCESS)
     {
         pos = (indx % 4)*4;
-        *buffer++ = tempbuffer[pos++];
-        *buffer++ = tempbuffer[pos++];
-        *buffer++ = tempbuffer[pos++];
-        *buffer++ = tempbuffer[pos++];
+        *buffer++ = buf[pos++];
+        *buffer++ = buf[pos++];
+        *buffer++ = buf[pos++];
+        *buffer++ = buf[pos++];
     }

    else
    {

drivers/staging/ft1000/ft1000-usb/ft1000_hw.c +7 -7
@@ -524,7 +502,7 @@ u16 fix_ft1000_write_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHA
     USHORT pos1;
     USHORT pos2;
     USHORT i;
-    UCHAR tempbuffer[32];
+    UCHAR buf[32];
     UCHAR resultbuffer[32];
     PUCHAR pdata;
     u16 ret  = STATUS_SUCCESS;
@@ -533,15 +511,15 @@ u16 fix_ft1000_write_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHA
 
     pos1 = (indx / 4)*4;
     pdata = buffer;
-    ret = ft1000_read_dpram32(ft1000dev, pos1, (PUCHAR)&tempbuffer[0], 16);
+    ret = ft1000_read_dpram32(ft1000dev, pos1, buf, 16);
     if (ret == STATUS_SUCCESS)
     {
         pos2 = (indx % 4)*4;
-        tempbuffer[pos2++] = *buffer++;
-        tempbuffer[pos2++] = *buffer++;
-        tempbuffer[pos2++] = *buffer++;
-        tempbuffer[pos2++] = *buffer++;
-        ret = ft1000_write_dpram32(ft1000dev, pos1, (PUCHAR)&tempbuffer[0], 16);
+        buf[pos2++] = *buffer++;
+        buf[pos2++] = *buffer++;
+        buf[pos2++] = *buffer++;
+        buf[pos2++] = *buffer++;
+        ret = ft1000_write_dpram32(ft1000dev, pos1, buf, 16);
     }

    else
    {

drivers/staging/ft1000/ft1000-usb/ft1000_hw.c +19 -14
@@ -556,7 +534,7 @@ u16 fix_ft1000_write_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHA
         buffer = pdata;
         for (i=0; i<16; i++)
         {
-            if (tempbuffer[i] != resultbuffer[i]){
+            if (buf[i] != resultbuffer[i]){
 
                 ret = STATUS_FAILURE;
             }
@@ -596,7 +574,7 @@ u16 fix_ft1000_write_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHA
  //
  //  Returns:    None
  //-----------------------------------------------------------------------
-void card_reset_dsp (struct ft1000_device *ft1000dev, BOOLEAN value)
+static void card_reset_dsp (struct ft1000_device *ft1000dev, BOOLEAN value)
  {
     u16 status = STATUS_SUCCESS;
     USHORT tempword;
@@ -645,7 +623,7 @@ void card_reset_dsp (struct ft1000_device *ft1000dev, BOOLEAN value)
  // Notes:
  //
  //---------------------------------------------------------------------------
-void CardSendCommand(struct ft1000_device *ft1000dev, unsigned char *ptempbuffer, int size)
+void CardSendCommand(struct ft1000_device *ft1000dev, void *ptempbuffer, int size)
  {
     unsigned short temp;
     unsigned char *commandbuf;
@@ -1202,7 +1180,7 @@ u16 reg_ft1000_netdev(struct ft1000_device *ft1000dev, struct usb_interface *int
    return STATUS_SUCCESS;
  }
 
-int ft1000_reset(struct net_device *dev)
+static int ft1000_reset(struct net_device *dev)
  {
     ft1000_reset_card(dev);
     return 0;
@@ -1432,7 +1410,7 @@ static inline u16 ft1000_read_fifo_len (struct net_device *dev)
  //              SUCCESS
  //
  //---------------------------------------------------------------------------
-int ft1000_copy_down_pkt (struct net_device *netdev, u8 *packet, u16 len)
+static int ft1000_copy_down_pkt (struct net_device *netdev, u8 *packet, u16 len)
  {
     FT1000_INFO *pInfo = netdev_priv(netdev);
     struct ft1000_device *pFt1000Dev = pInfo->pFt1000Dev;
@@ -1658,7 +1636,7 @@ static int ft1000_start_xmit(struct sk_buff *skb, struct net_device *dev)
  //              SUCCESS
  //
  //---------------------------------------------------------------------------
-int ft1000_copy_up_pkt (struct urb *urb)
+static int ft1000_copy_up_pkt (struct urb *urb)
  {
     PFT1000_INFO info = urb->context;
     struct ft1000_device *ft1000dev = info->pFt1000Dev;
@@ -1774,7 +1752,7 @@ int ft1000_copy_up_pkt (struct urb *urb)
  //              SUCCESS
  //
  //---------------------------------------------------------------------------
-int ft1000_submit_rx_urb(PFT1000_INFO info)
+static int ft1000_submit_rx_urb(PFT1000_INFO info)
  {
     int result;
     struct ft1000_device *pFt1000Dev = info->pFt1000Dev;
@@ -2102,7 +2080,7 @@ static void ft1000_hbchk(u_long data)
  //          = 1 (successful)
  //
  //---------------------------------------------------------------------------
-BOOLEAN ft1000_receive_cmd (struct ft1000_device *dev, u16 *pbuffer, int maxsz, u16 *pnxtph) {
+static BOOLEAN ft1000_receive_cmd (struct ft1000_device *dev, u16 *pbuffer, int maxsz, u16 *pnxtph) {
     u16 size, ret;
     u16 *ppseudohdr;
     int i;
@@ -2175,7 +2153,7 @@ BOOLEAN ft1000_receive_cmd (struct ft1000_device *dev, u16 *pbuffer, int maxsz,
  }
 
 
-int ft1000_dsp_prov(void *arg)
+static int ft1000_dsp_prov(void *arg)
  {
     struct ft1000_device *dev = (struct ft1000_device *)arg;
        FT1000_INFO *info = (FT1000_INFO *) netdev_priv (dev->net);
@@ -2263,7 +2241,7 @@ int ft1000_dsp_prov(void *arg)
  }
 
 
-int ft1000_proc_drvmsg (struct ft1000_device *dev, u16 size) {
+static int ft1000_proc_drvmsg (struct ft1000_device *dev, u16 size) {
        FT1000_INFO *info = (FT1000_INFO *) netdev_priv (dev->net);
     u16 msgtype;
     u16 tempword;
@@ -2281,9 +2259,11 @@ int ft1000_proc_drvmsg (struct ft1000_device *dev, u16 size) {
     } convert;
 
 
-    char cmdbuffer[1600];
+    char *cmdbuffer = kmalloc(1600, GFP_KERNEL);
+    if (!cmdbuffer)
+       return STATUS_FAILURE;
 
-    status = ft1000_read_dpram32(dev, 0x200, (PUCHAR)&cmdbuffer[0], size);
+    status = ft1000_read_dpram32(dev, 0x200, cmdbuffer, size);
 
 
     //if (ft1000_receive_cmd(dev, &cmdbuffer[0], MAX_CMD_SQSIZE, &tempword))
@@ -2388,7 +2368,7 @@ int ft1000_proc_drvmsg (struct ft1000_device *dev, u16 size) {
                    info->fProvComplete = 0;
                    status = ft1000_dsp_prov(dev);
                    if (status != STATUS_SUCCESS)
-                       return status;
+                       goto out;
                 }
                 else {
                     info->fProvComplete = 1;
@@ -2537,8 +2517,11 @@ int ft1000_proc_drvmsg (struct ft1000_device *dev, u16 size) {
 
     }
 
+    status = STATUS_SUCCESS;
+out:
+    kfree(cmdbuffer);
     DEBUG("return from ft1000_proc_drvmsg\n");
-    return STATUS_SUCCESS;
+    return status;
  }
 
 
drivers/staging/ft1000/ft1000-usb/ft1000_proc.c +1 -1
index 80faba5..d1ef396 100644
@@ -42,7 +42,7 @@ u16 ft1000_read_dpram16 (struct ft1000_device *ft1000dev, USHORT indx,
                         PUCHAR buffer, u8 highlow);
 
 
-int
+static int
  ft1000ReadProc (char *page, char **start, off_t off, int count, int *eof,
                void *data)
  {
drivers/staging/ft1000/ft1000-usb/ft1000_usb.c +2 -19
index f708c09..4aef1c4 100644
@@ -33,7 +33,7 @@ MODULE_SUPPORTED_DEVICE("QFT FT1000 Express Cards");
 
 
  void *pFileStart;
-ULONG FileLength;
+size_t FileLength;
 
  #define VENDOR_ID 0x1291   /* Qualcomm vendor id */
  #define PRODUCT_ID 0x11    /* fake product id */
@@ -46,24 +46,7 @@ static struct usb_device_id id_table[] = {
 
  MODULE_DEVICE_TABLE (usb, id_table);
 
-extern  struct ft1000_device *pdevobj[MAX_NUM_CARDS+2];
-
-char *getfw (char *fn, int *pimgsz);
-
-int ft1000_close(struct net_device *net);
-void dsp_reload (struct ft1000_device *ft1000dev);
-u16 init_ft1000_netdev(struct ft1000_device *ft1000dev);
-u16 reg_ft1000_netdev(struct ft1000_device *ft1000dev, struct usb_interface *intf);
-int ft1000_poll(void* dev_id);
-void ft1000_DestroyDevice(struct net_device *dev);
-u16 ft1000_read_dpram16(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer, u8 highlow);
-u16 ft1000_read_register(struct ft1000_device *ft1000dev, short* Data, u16 nRegIndx);
-BOOLEAN gPollingfailed = FALSE;
-
-void ft1000InitProc(struct net_device *dev);
-void ft1000CleanupProc(FT1000_INFO *info);
-int ft1000_poll_thread(void *arg);
-
+static BOOLEAN gPollingfailed = FALSE;
  int ft1000_poll_thread(void *arg)
  {
     int ret = STATUS_SUCCESS;
drivers/staging/ft1000/ft1000-usb/ft1000_usb.h +39 -3
index a64d468..b0ab918 100644
@@ -102,7 +102,7 @@ typedef struct _PROV_RECORD {
 
  #define UCHAR               u8
  #define USHORT              u16
-#define ULONG               u32
+#define ULONG               u32 /* WTF ??? */
  #define BOOLEAN             u8
  #define PULONG              u32 *
  #define PUSHORT             u16 *
@@ -152,7 +152,6 @@ typedef struct _PROV_RECORD {
 
  #define CIS_NET_ADDR_OFFSET 0xff0
 
-#define MEM_TAG 'FLRN'
  // MAGNEMITE specific
 
  #define FT1000_REG_MAG_UFDR            0x0000  // Uplink FIFO Data Register.
@@ -605,5 +604,43 @@ typedef struct _DPRAM_BLK {
     u16 *pbuffer;
  } __attribute__ ((packed)) DPRAM_BLK, *PDPRAM_BLK;
 
+u16 ft1000_read_register(struct ft1000_device *ft1000dev, u16* Data, u16 nRegIndx);
+u16 ft1000_write_register(struct ft1000_device *ft1000dev, USHORT value, u16 nRegIndx);
+u16 ft1000_read_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer, USHORT cnt);
+u16 ft1000_write_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer, USHORT cnt);
+u16 ft1000_read_dpram16(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer, u8 highlow);
+u16 ft1000_write_dpram16(struct ft1000_device *ft1000dev, USHORT indx, USHORT value, u8 highlow);
+u16 fix_ft1000_read_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer);
+u16 fix_ft1000_write_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer);
+
+extern void *pFileStart;
+extern size_t FileLength;
+extern int numofmsgbuf;
+
+int ft1000_close (struct net_device *dev);
+u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart, ULONG  FileLength);
+
+extern struct list_head freercvpool;
+extern spinlock_t free_buff_lock;   // lock to arbitrate free buffer list for receive command data
+
+int ft1000_CreateDevice(struct ft1000_device *dev);
+void ft1000_DestroyDevice(struct net_device *dev);
+extern void CardSendCommand(struct ft1000_device *ft1000dev, void *ptempbuffer, int size);
+
+PDPRAM_BLK ft1000_get_buffer (struct list_head *bufflist);
+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);
+u16 init_ft1000_netdev(struct ft1000_device *ft1000dev);
+struct usb_interface;
+u16 reg_ft1000_netdev(struct ft1000_device *ft1000dev, struct usb_interface *intf);
+int ft1000_poll(void* dev_id);
+
+void ft1000InitProc(struct net_device *dev);
+void ft1000CleanupProc(FT1000_INFO *info);
+
+
 
  #endif
--
Quoted 3 lines

1.7.1

marek

Signature · 10 lines
as simple and primitive as possible
-------------------------------------------------
Marek Belisko - OPEN-NANDRA
Freelance Developer

Ruska Nova Ves 219 | Presov, 08005 Slovak Republic
Tel: +421 915 052 184
skype: marekwhite
icq: 290551086
web: http://open-nandra.com
#8 lore raw

Re: [PATCH 4/6] staging/ft1000-usb: fix problems found by sparse

Quoted 3 lines · Belisko Marek

I couldn't apply this patch with git. After manual patching it produce compilation errors.
Did you test it?

Of course I tested it, otherwise I would not have found the build warnings!

Still applies and builds fine here.

Arnd

#9 lore raw

PATCH 5/6 staging/bcm: fix most build warnings

In reply to Arnd Bergmann

This removes all warnings I get on a 64 bit build except for those that look unfixable, where we convert a pointer to a 32 bit integer and change its byte order!

---
 drivers/staging/bcm/Bcmchar.c       |   15 +++++++--------
 drivers/staging/bcm/Bcmnet.c        |    4 ++--
 drivers/staging/bcm/CmHost.c        |   10 +++++-----
 drivers/staging/bcm/InterfaceInit.c |    4 ++--
 drivers/staging/bcm/LeakyBucket.c   |   20 ++++++++++----------
 drivers/staging/bcm/Macros.h        |    2 +-
 drivers/staging/bcm/Misc.c          |    2 +-
 drivers/staging/bcm/PHSDefines.h    |    2 +-
 drivers/staging/bcm/Transmit.c      |    4 +++-
 9 files changed, 32 insertions(+), 31 deletions(-)
drivers/staging/bcm/Bcmchar.c +7 -8
index afde77a..2248ae5 100644
@@ -100,7 +100,7 @@ static int bcm_char_release(struct inode *inode, struct file *filp)
     return 0;
 }
 
-static int bcm_char_read(struct file *filp, PCHAR buf, size_t size, loff_t *f_pos)
+static ssize_t bcm_char_read(struct file *filp, char __user *buf, size_t size, loff_t *f_pos)
 {
     PPER_TARANG_DATA pTarang = (PPER_TARANG_DATA)filp->private_data;
 	PMINI_ADAPTER	Adapter = pTarang->Adapter;
@@ -153,8 +153,7 @@ static int bcm_char_read(struct file *filp, PCHAR buf, size_t size, loff_t *f_po
     return PktLen;
 }
 
-static INT bcm_char_ioctl(struct inode *inode, struct file *filp,
-					UINT cmd, ULONG arg)
+static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
 {
     PPER_TARANG_DATA  pTarang = (PPER_TARANG_DATA)filp->private_data;
 	PMINI_ADAPTER 	Adapter = pTarang->Adapter;
@@ -2359,11 +2358,11 @@ static INT bcm_char_ioctl(struct inode *inode, struct file *filp,
 
 
 static struct file_operations bcm_fops = {
-    .owner    = THIS_MODULE,
-    .open     = bcm_char_open,
-    .release  = bcm_char_release,
-    .read     = bcm_char_read,
-    .unlocked_ioctl    = bcm_char_ioctl,
+	.owner    = THIS_MODULE,
+	.open     = bcm_char_open,
+	.release  = bcm_char_release,
+	.read     = bcm_char_read,
+	.unlocked_ioctl    = bcm_char_ioctl,
 	.llseek = no_llseek,
 };
 
drivers/staging/bcm/Bcmnet.c +2 -2
index d4f4800..c619f91 100644
@@ -126,7 +126,7 @@ int register_networkdev(PMINI_ADAPTER Adapter)
 {
 	int result=0;
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
-	int *temp = NULL ;
+	void **temp = NULL; /* actually we're *allocating* the device in alloc_etherdev */
 #endif
 	Adapter->dev = alloc_etherdev(sizeof(PMINI_ADAPTER));
 	if(!Adapter->dev)
@@ -139,7 +139,7 @@ int register_networkdev(PMINI_ADAPTER Adapter)
 	Adapter->dev->priv      			= Adapter;
 #else
 	temp = netdev_priv(Adapter->dev);
-	*temp = (UINT)Adapter;
+	*temp = (void *)Adapter;
 #endif
 	//BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "init adapterptr: %x %x\n", (UINT)Adapter, temp);
 
drivers/staging/bcm/CmHost.c +5 -5
index 328fd1b..f8e9e32 100644
@@ -1792,8 +1792,8 @@ ULONG StoreCmControlResponseMessage(PMINI_ADAPTER Adapter,PVOID pvBuffer,UINT *p
 				(ULONG)pstAddIndication->psfAuthorizedSet)!= 1)
 		return 0;
 
-	pstAddIndication->psfAuthorizedSet = (stServiceFlowParamSI *)
-				ntohl((ULONG)pstAddIndication->psfAuthorizedSet);
+	/* this can't possibly be right */
+	pstAddIndication->psfAuthorizedSet = (stServiceFlowParamSI *)ntohl((ULONG)pstAddIndication->psfAuthorizedSet);
 
 	if(pstAddIndicationAlt->u8Type == DSA_REQ)
 	{
@@ -1886,9 +1886,9 @@ static inline stLocalSFAddIndicationAlt
 	BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,  "AddIndication-u8TID : 0x%X",ntohs(pstAddIndication->u16TID));
 	BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,  "AddIndication-u8CID : 0x%X",ntohs(pstAddIndication->u16CID));
 	BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,  "AddIndication-u16VCID : 0x%X",ntohs(pstAddIndication->u16VCID));
-	BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,  "AddIndication-autorized set loc : 0x%x",ntohl(pstAddIndication->psfAuthorizedSet));
-	BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,  "AddIndication-admitted set loc : 0x%x",ntohl(pstAddIndication->psfAdmittedSet));
-	BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,  "AddIndication-Active set loc : 0x%x",ntohl(pstAddIndication->psfActiveSet));
+	BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,  "AddIndication-autorized set loc : %p",pstAddIndication->psfAuthorizedSet);
+	BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,  "AddIndication-admitted set loc : %p",pstAddIndication->psfAdmittedSet);
+	BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,  "AddIndication-Active set loc : %p",pstAddIndication->psfActiveSet);
 
 	pstAddIndicationDest->u8Type = pstAddIndication->u8Type;
 	pstAddIndicationDest->u8Direction = pstAddIndication->eConnectionDir;
drivers/staging/bcm/InterfaceInit.c +2 -2
index 67d8572..8bf900b 100644
@@ -241,7 +241,7 @@ usbbcm_device_probe(struct usb_interface *intf, const struct usb_device_id *id)
 	psIntfAdapter->interface = intf;
 	usb_set_intfdata(intf, psIntfAdapter);
 
-	BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "psIntfAdapter 0x%x",(unsigned int)psIntfAdapter);
+	BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "psIntfAdapter 0x%p",psIntfAdapter);
 	retval = InterfaceAdapterInit(psIntfAdapter);
 	if(retval)
 	{
@@ -323,7 +323,7 @@ static void usbbcm_disconnect (struct usb_interface *intf)
 		return;
 	}
 	psIntfAdapter = usb_get_intfdata(intf);
-	BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "psIntfAdapter 0x%x",(unsigned int)psIntfAdapter);
+	BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "psIntfAdapter 0x%p",psIntfAdapter);
 	if(psIntfAdapter == NULL)
 	{
 		BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "InterfaceAdapter pointer is NULL");
drivers/staging/bcm/LeakyBucket.c +10 -10
index 1875c82..b407938 100644
@@ -80,9 +80,9 @@ static __inline ULONG GetSFTokenCount(PMINI_ADAPTER Adapter, PacketInfo *psSF)
 	BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TOKEN_COUNTS, DBG_LVL_ALL, "IsPacketAllowedForFlow ===>");
 	/* Validate the parameters */
 	if(NULL == Adapter || (psSF < Adapter->PackInfo &&
-		(UINT)psSF > (UINT) &Adapter->PackInfo[HiPriority]))
+		(uintptr_t)psSF > (uintptr_t) &Adapter->PackInfo[HiPriority]))
 	{
-		BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TOKEN_COUNTS, DBG_LVL_ALL, "IPAFF: Got wrong Parameters:Adapter: %p, QIndex: %d\n", Adapter, (psSF-Adapter->PackInfo));
+		BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TOKEN_COUNTS, DBG_LVL_ALL, "IPAFF: Got wrong Parameters:Adapter: %p, QIndex: %ld\n", Adapter, (psSF-Adapter->PackInfo));
 		return 0;
 	}
 
@@ -94,14 +94,14 @@ static __inline ULONG GetSFTokenCount(PMINI_ADAPTER Adapter, PacketInfo *psSF)
 		}
 		else
 		{
-			BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TOKEN_COUNTS, DBG_LVL_ALL, "Not enough tokens in queue %d Available %u\n",
+			BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TOKEN_COUNTS, DBG_LVL_ALL, "Not enough tokens in queue %ld Available %u\n",
 				psSF-Adapter->PackInfo, psSF->uiCurrentTokenCount);
 			psSF->uiPendedLast = 1;
 		}
 	}
 	else
 	{
-		BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TOKEN_COUNTS, DBG_LVL_ALL, "IPAFF: Queue %d not valid\n", psSF-Adapter->PackInfo);
+		BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TOKEN_COUNTS, DBG_LVL_ALL, "IPAFF: Queue %ld not valid\n", psSF-Adapter->PackInfo);
 	}
 	BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TOKEN_COUNTS, DBG_LVL_ALL, "IsPacketAllowedForFlow <===");
 	return 0;
@@ -113,12 +113,12 @@ static __inline void RemovePacketFromQueue(PacketInfo *pPackInfo , struct sk_buf
 	psQueueCurrent = pPackInfo->FirstTxQueue;
 	while(psQueueCurrent)
 	{
-		if((UINT)Packet == (UINT)psQueueCurrent)
+		if(Packet == psQueueCurrent)
 		{
-			if((UINT)psQueueCurrent == (UINT)pPackInfo->FirstTxQueue)
+			if(psQueueCurrent == pPackInfo->FirstTxQueue)
 			{
 				pPackInfo->FirstTxQueue=psQueueCurrent->next;
-				if((UINT)psQueueCurrent==(UINT)pPackInfo->LastTxQueue)
+				if(psQueueCurrent==pPackInfo->LastTxQueue)
 					pPackInfo->LastTxQueue=NULL;
 			}
 			else
@@ -189,8 +189,8 @@ static __inline VOID CheckAndSendPacketFromIndex
 	int				iPacketLen=0;
 
 
-	BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_PACKETS, DBG_LVL_ALL, "%d ====>", (psSF-Adapter->PackInfo));
-	if(((UINT)psSF != (UINT)&Adapter->PackInfo[HiPriority]) && Adapter->LinkUpStatus && atomic_read(&psSF->uiPerSFTxResourceCount))//Get data packet
+	BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_PACKETS, DBG_LVL_ALL, "%ld ====>", (psSF-Adapter->PackInfo));
+	if((psSF != &Adapter->PackInfo[HiPriority]) && Adapter->LinkUpStatus && atomic_read(&psSF->uiPerSFTxResourceCount))//Get data packet
   	{
 		if(!psSF->ucDirection )
 			return;
@@ -240,7 +240,7 @@ static __inline VOID CheckAndSendPacketFromIndex
 			}
 			else
 			{
-				BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_PACKETS, DBG_LVL_ALL, "For Queue: %d\n", psSF-Adapter->PackInfo);
+				BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_PACKETS, DBG_LVL_ALL, "For Queue: %ld\n", psSF-Adapter->PackInfo);
 				BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_PACKETS, DBG_LVL_ALL, "\nAvailable Tokens = %d required = %d\n",
 					psSF->uiCurrentTokenCount, iPacketLen);
 				//this part indicates that becuase of non-availability of the tokens
drivers/staging/bcm/Macros.h +1 -1
index f559b59..6ee1480 100644
@@ -382,7 +382,7 @@ enum eAbortPattern {
 	#define GET_BCM_ADAPTER(net_dev) ({\
     PMINI_ADAPTER __Adapter = NULL;	\
     if (net_dev)    {   \
-         __Adapter = (PMINI_ADAPTER)(*((UINT *)netdev_priv(net_dev)));  \
+         __Adapter = (PMINI_ADAPTER)(*((unsigned long *)netdev_priv(net_dev)));  \
     } \
     else    {   \
          __Adapter = NULL;  \
drivers/staging/bcm/Misc.c +1 -1
index 5ed58a8..994132f 100644
@@ -26,7 +26,7 @@ InitAdapter(PMINI_ADAPTER psAdapter)
 {
     int i = 0;
 	INT Status = STATUS_SUCCESS ;
-	BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, MP_INIT,  DBG_LVL_ALL,  "Initialising Adapter = 0x%x",(unsigned int) psAdapter);
+	BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, MP_INIT,  DBG_LVL_ALL,  "Initialising Adapter = %p", psAdapter);
 
 	if(psAdapter == NULL)
 	{
drivers/staging/bcm/PHSDefines.h +1 -1
index 9889a99..eed4cfc 100644
@@ -4,7 +4,7 @@
 #define PHS_INVALID_TABLE_INDEX 0xffffffff
 
 /************************* MACROS **********************************************/
-#define PHS_MEM_TAG '_SHP'
+#define PHS_MEM_TAG "_SHP"
 
 
 
drivers/staging/bcm/Transmit.c +3 -1
index 9a076b5..12f9e13 100644
@@ -282,7 +282,9 @@ INT SetupNextSend(PMINI_ADAPTER Adapter, /**<Logical Adapter*/
 					USHORT Vcid)			/**<VCID for this packet*/
 {
 	int		status=0;
+#ifdef GDMA_INTERFACE
 	int dontfree = 0;
+#endif
 	BOOLEAN bHeaderSupressionEnabled = FALSE;
 	B_UINT16            uiClassifierRuleID;
 	int QueueIndex = NO_OF_QUEUES + 1;
@@ -423,7 +425,7 @@ int tx_pkt_handler(PMINI_ADAPTER Adapter  /**< pointer to adapter object*/
 #endif
 
 	UINT calltransmit = 1;
-	BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_PACKETS, DBG_LVL_ALL, "Entring to wait for signal from the interrupt service thread!Adapter = 0x%x",(unsigned int) Adapter);
+	BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_PACKETS, DBG_LVL_ALL, "Entring to wait for signal from the interrupt service thread!Adapter = %p",Adapter);
 
 
 	while(1)
Signature · 1 line
1.7.1
#10 lore raw

PATCH 6/6 staging/bcm: add sparse annotations

In reply to Arnd Bergmann

This marks up the code where sparse complains in most cases. Most of the changes are in the ioctl handling code, which gets __user annotations, finding one unchecked user access.

The rest is mostly about marking functions static when they are only used in one file.

---
 drivers/staging/bcm/Adapter.h             |    2 +-
 drivers/staging/bcm/Bcmchar.c             |  148 ++++++++++++++---------------
 drivers/staging/bcm/Bcmnet.c              |    2 +-
 drivers/staging/bcm/CmHost.c              |    8 +-
 drivers/staging/bcm/Debug.c               |    2 +-
 drivers/staging/bcm/HandleControlPacket.c |    2 +-
 drivers/staging/bcm/IPv6Protocol.c        |    4 +-
 drivers/staging/bcm/InterfaceDld.c        |    6 +-
 drivers/staging/bcm/InterfaceIdleMode.c   |    2 +-
 drivers/staging/bcm/InterfaceIdleMode.h   |    2 +-
 drivers/staging/bcm/InterfaceInit.c       |   26 +++---
 drivers/staging/bcm/Ioctl.h               |    8 +-
 drivers/staging/bcm/LeakyBucket.c         |    2 +-
 drivers/staging/bcm/Misc.c                |   18 ++--
 drivers/staging/bcm/PHSModule.c           |    2 +-
 drivers/staging/bcm/Prototypes.h          |    3 +-
 drivers/staging/bcm/Qos.c                 |    8 +-
 drivers/staging/bcm/led_control.c         |   22 ++--
 drivers/staging/bcm/nvm.c                 |   54 +++++-----
 19 files changed, 160 insertions(+), 161 deletions(-)
drivers/staging/bcm/Adapter.h +1 -1
index a7c0ce9..742ddeb 100644
@@ -652,7 +652,7 @@ typedef struct _ETH_HEADER_STRUC ETH_HEADER_STRUC, *PETH_HEADER_STRUC;
 
 typedef struct FirmwareInfo
 {
-	PVOID		pvMappedFirmwareAddress;
+	void __user *	pvMappedFirmwareAddress;
 	ULONG		u32FirmwareLength;
 	ULONG		u32StartingAddress;
 }__attribute__((packed)) FIRMWARE_INFO, *PFIRMWARE_INFO;
drivers/staging/bcm/Bcmchar.c +71 -77

546 lines not on this page · raw message

drivers/staging/bcm/Bcmnet.c +1 -1
index c619f91..bb9260c 100644
@@ -111,7 +111,7 @@ static struct net_device_stats *bcm_get_stats(struct net_device *dev)
 Register other driver entry points with the kernel
 */
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29)
-struct net_device_ops bcmNetDevOps = {
+static struct net_device_ops bcmNetDevOps = {
     .ndo_open		= bcm_open,
     .ndo_stop 		= bcm_close,
     .ndo_get_stats 	= bcm_get_stats,
drivers/staging/bcm/CmHost.c +4 -4
index f8e9e32..0329f7d 100644
@@ -1014,7 +1014,7 @@ static VOID CopyToAdapter( register PMINI_ADAPTER Adapter,		/**<Pointer to the A
 *
 * Returns	  - None
 *************************************************************************/
-VOID DumpCmControlPacket(PVOID pvBuffer)
+static VOID DumpCmControlPacket(PVOID pvBuffer)
 {
 	UINT 					uiLoopIndex;
 	UINT                    nIndex;
@@ -2362,7 +2362,7 @@ BOOLEAN CmControlResponseMessage(PMINI_ADAPTER Adapter,  /**<Pointer to the Adap
 	return TRUE;
 }
 
-int get_dsx_sf_data_to_application(PMINI_ADAPTER Adapter, UINT uiSFId, PUCHAR user_buffer)
+int get_dsx_sf_data_to_application(PMINI_ADAPTER Adapter, UINT uiSFId, void __user *user_buffer)
 {
 	int status = 0;
 	struct _packet_info *psSfInfo=NULL;
@@ -2375,8 +2375,8 @@ int get_dsx_sf_data_to_application(PMINI_ADAPTER Adapter, UINT uiSFId, PUCHAR us
 	}
 	BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL, "status =%d",status);
 	psSfInfo=&Adapter->PackInfo[status];
-	if(psSfInfo->pstSFIndication && copy_to_user((PCHAR)user_buffer,
-		(PCHAR)psSfInfo->pstSFIndication, sizeof(stLocalSFAddIndicationAlt)))
+	if(psSfInfo->pstSFIndication && copy_to_user(user_buffer,
+		psSfInfo->pstSFIndication, sizeof(stLocalSFAddIndicationAlt)))
 	{
 		BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "copy to user failed SFID %d, present in queue !!!", uiSFId );
 		status = -EFAULT;
drivers/staging/bcm/Debug.c +1 -1
index d01eb12..2703f30 100644
@@ -3,7 +3,7 @@
 static UINT current_debug_level=BCM_SCREAM;
 
 int bcm_print_buffer( UINT debug_level, const char *function_name,
-				  char *file_name, int line_number, unsigned char *buffer, int bufferlen, unsigned int base)
+				  char *file_name, int line_number, unsigned char *buffer, int bufferlen, enum _BASE_TYPE base)
 {
 	static const char * const buff_dump_base[] = {
 		"DEC", "HEX", "OCT", "BIN"
drivers/staging/bcm/HandleControlPacket.c +1 -1
index 8499513..7b2ec28 100644
@@ -223,7 +223,7 @@ int control_packet_handler  (PMINI_ADAPTER Adapter  /**< pointer to adapter obje
 	return STATUS_SUCCESS;
 }
 
-INT flushAllAppQ()
+INT flushAllAppQ(void)
 {
 	PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(gblpnetdev);
 	PPER_TARANG_DATA	pTarang = NULL;
drivers/staging/bcm/IPv6Protocol.c +2 -2
index cb4ca9a..5ec3b89 100644
@@ -1,6 +1,6 @@
 #include "headers.h"
 
-UCHAR * GetNextIPV6ChainedHeader(UCHAR **ppucPayload,UCHAR *pucNextHeader,BOOLEAN *bParseDone,USHORT *pusPayloadLength)
+static UCHAR * GetNextIPV6ChainedHeader(UCHAR **ppucPayload,UCHAR *pucNextHeader,BOOLEAN *bParseDone,USHORT *pusPayloadLength)
 {
 	UCHAR *pucRetHeaderPtr = NULL;
 	UCHAR *pucPayloadPtr = NULL;
@@ -130,7 +130,7 @@ UCHAR * GetNextIPV6ChainedHeader(UCHAR **ppucPayload,UCHAR *pucNextHeader,BOOLEA
 }
 
 
-UCHAR GetIpv6ProtocolPorts(UCHAR *pucPayload,USHORT *pusSrcPort,USHORT *pusDestPort,USHORT usPayloadLength,UCHAR ucNextHeader)
+static UCHAR GetIpv6ProtocolPorts(UCHAR *pucPayload,USHORT *pusSrcPort,USHORT *pusDestPort,USHORT usPayloadLength,UCHAR ucNextHeader)
 {
 	UCHAR *pIpv6HdrScanContext = pucPayload;
 	BOOLEAN bDone = FALSE;
drivers/staging/bcm/InterfaceDld.c +3 -3
index f9761db..8825b8e 100644
@@ -22,7 +22,7 @@ int InterfaceFileDownload( PVOID arg,
     while(1)
     {
         oldfs=get_fs(); set_fs(get_ds());
-        len=vfs_read(flp, buff, MAX_TRANSFER_CTRL_BYTE_USB, &pos);
+        len=vfs_read(flp, (void __force __user *)buff, MAX_TRANSFER_CTRL_BYTE_USB, &pos);
         set_fs(oldfs);
         if(len<=0)
         {
@@ -83,7 +83,7 @@ int InterfaceFileReadbackFromChip( PVOID arg,
     while(1)
     {
         oldfs=get_fs(); set_fs(get_ds());
-        len=vfs_read(flp, buff, MAX_TRANSFER_CTRL_BYTE_USB, &pos);
+        len=vfs_read(flp, (void __force __user *)buff, MAX_TRANSFER_CTRL_BYTE_USB, &pos);
         set_fs(oldfs);
         fw_down++;
         if(len<=0)
@@ -381,7 +381,7 @@ int bcm_ioctl_fw_download(PMINI_ADAPTER Adapter, FIRMWARE_INFO *psFwInfo)
 			BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL,"Failed in allocation memory");
 			return -ENOMEM;
 		}
-		retval = copy_from_user(buff,(PUCHAR)psFwInfo->pvMappedFirmwareAddress, psFwInfo->u32FirmwareLength);
+		retval = copy_from_user(buff,psFwInfo->pvMappedFirmwareAddress, psFwInfo->u32FirmwareLength);
 		if(retval != STATUS_SUCCESS)
 		{
 			BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "copying buffer from user space failed");
drivers/staging/bcm/InterfaceIdleMode.c +1 -1
index d99fc7c..0750382 100644
@@ -42,7 +42,7 @@ send to f/w with in 200 ms after the Idle/Shutdown req issued
 */
 
 
-int InterfaceIdleModeRespond(PMINI_ADAPTER Adapter,int* puiBuffer)
+int InterfaceIdleModeRespond(PMINI_ADAPTER Adapter, unsigned int* puiBuffer)
 {
 	int	status = STATUS_SUCCESS;
 	unsigned int	uiRegRead = 0;
drivers/staging/bcm/InterfaceIdleMode.h +1 -1
index f87c132..1bc723d 100644
@@ -3,7 +3,7 @@
 
 INT InterfaceIdleModeWakeup(PMINI_ADAPTER Adapter);
 
-INT InterfaceIdleModeRespond(PMINI_ADAPTER Adapter,PINT puiBuffer);
+INT InterfaceIdleModeRespond(PMINI_ADAPTER Adapter, unsigned int *puiBuffer);
 
 VOID InterfaceWriteIdleModeWakePattern(PMINI_ADAPTER Adapter);
 
drivers/staging/bcm/InterfaceInit.c +14 -12
index 8bf900b..81523b1 100644
@@ -68,12 +68,12 @@ static int usbbcm_release(struct inode *inode, struct file *file)
 	return 0;
 }
 
-static ssize_t usbbcm_read(struct file *file, char *buffer, size_t count, loff_t *ppos)
+static ssize_t usbbcm_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
 {
 	return 0;
 }
 
-static ssize_t usbbcm_write(struct file *file, const char *user_buffer, size_t count, loff_t *ppos)
+static ssize_t usbbcm_write(struct file *file, const char __user *user_buffer, size_t count, loff_t *ppos)
 {
 	return 0;
 }
@@ -188,14 +188,12 @@ usbbcm_device_probe(struct usb_interface *intf, const struct usb_device_id *id)
 	}
 
 	/* Allocate Adapter structure */
-	if((psAdapter = kmalloc(sizeof(MINI_ADAPTER), GFP_KERNEL)) == NULL)
+	if((psAdapter = kzalloc(sizeof(MINI_ADAPTER), GFP_KERNEL)) == NULL)
 	{
-		//BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_PRINTK, 0, 0, "Out of memory");
+		BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_PRINTK, 0, 0, "Out of memory");
 		return -ENOMEM;
 	}
 
-	memset(psAdapter, 0, sizeof(MINI_ADAPTER));
-
     /* Init default driver debug state */
 
     psAdapter->stDebugState.debug_level = DBG_LVL_CURR;
@@ -618,9 +616,9 @@ INT InterfaceAdapterInit(PS_INTERFACE_ADAPTER psIntfAdapter)
 				if((psIntfAdapter->bHighSpeedDevice == FALSE) && bcm_usb_endpoint_is_bulk_out(endpoint))
 				{
 					// Once BULK is selected in FS mode. Revert it back to INT. Else USB_IF will fail.
-					UINT uiData = ntohl(EP2_CFG_INT);
+					UINT _uiData = ntohl(EP2_CFG_INT);
 					BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,"Reverting Bulk to INT as it is FS MODE");
-					BeceemEEPROMBulkWrite(psIntfAdapter->psAdapter,(PUCHAR)&uiData,0x136,4,TRUE);
+					BeceemEEPROMBulkWrite(psIntfAdapter->psAdapter,(PUCHAR)&_uiData,0x136,4,TRUE);
 				}
 			}
 			else
@@ -773,7 +771,8 @@ INT InterfaceAdapterInit(PS_INTERFACE_ADAPTER psIntfAdapter)
 
 	return 0;
 }
-int InterfaceSuspend (struct usb_interface *intf, pm_message_t message)
+
+static int InterfaceSuspend (struct usb_interface *intf, pm_message_t message)
 {
 	PS_INTERFACE_ADAPTER  psIntfAdapter = usb_get_intfdata(intf);
 	BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "=================================\n");
@@ -802,7 +801,8 @@ int InterfaceSuspend (struct usb_interface *intf, pm_message_t message)
 
 	return 0;
 }
-int InterfaceResume (struct usb_interface *intf)
+
+static int InterfaceResume (struct usb_interface *intf)
 {
     PS_INTERFACE_ADAPTER  psIntfAdapter = usb_get_intfdata(intf);
 	printk("=================================\n");
@@ -816,12 +816,14 @@ int InterfaceResume (struct usb_interface *intf)
 	InterfaceRx(psIntfAdapter);
 	return 0;
 }
-int InterfacePreReset(struct usb_interface *intf)
+
+static int InterfacePreReset(struct usb_interface *intf)
 {
     printk("====================>");
 	return STATUS_SUCCESS;
 }
-int InterfacePostReset(struct usb_interface *intf)
+
+static int InterfacePostReset(struct usb_interface *intf)
 {
     printk("Do Post chip reset setting here if it is required");
    	return STATUS_SUCCESS;
drivers/staging/bcm/Ioctl.h +4 -4
index 2651fc2..e4f8eb7 100644
@@ -18,9 +18,9 @@ typedef struct wrmbuffer
 
 typedef struct ioctlbuffer
 {
-	PVOID	InputBuffer;
+	void __user *InputBuffer;
 	ULONG	InputLength;
-	PVOID	OutputBuffer;
+	void __user *OutputBuffer;
 	ULONG	OutputLength;
 }__attribute__((packed)) IOCTL_BUFFER, *PIOCTL_BUFFER;
 
@@ -209,7 +209,7 @@ typedef struct _DEVICE_DRIVER_INFO
 typedef  struct _NVM_READWRITE
 {
 
-	void *pBuffer;
+	void __user *pBuffer;
 // Data to be written from|read to. Memory should be allocated by the caller.
 
 	uint32_t  uiOffset;
@@ -269,7 +269,7 @@ typedef struct _FLASH2X_READWRITE
 	B_UINT32 offset;		//Offset within Section.
 	B_UINT32 numOfBytes;	//NOB from the offset
 	B_UINT32  bVerify;
-	PVOID pDataBuff;	//Buffer for reading/writing
+	void __user *pDataBuff;	//Buffer for reading/writing
 
 }FLASH2X_READWRITE, *PFLASH2X_READWRITE;
 /*
drivers/staging/bcm/LeakyBucket.c +1 -1
index b407938..cae3823 100644
@@ -15,7 +15,7 @@
 * Returns     - None
 **********************************************************************/
 
-VOID UpdateTokenCount(register PMINI_ADAPTER Adapter)
+static VOID UpdateTokenCount(register PMINI_ADAPTER Adapter)
 {
 	ULONG 	liCurrentTime;
 	INT 	i = 0;
drivers/staging/bcm/Misc.c +11 -7
index 994132f..22550f7 100644
@@ -503,6 +503,7 @@ INT CopyBufferToControlPacket(PMINI_ADAPTER Adapter,/**<Logical Adapter*/
 	return Status;
 }
 
+#if 0
 /*****************************************************************
 * Function    - SendStatisticsPointerRequest()
 *
@@ -514,7 +515,7 @@ INT CopyBufferToControlPacket(PMINI_ADAPTER Adapter,/**<Logical Adapter*/
 *
 * Returns     - None.
 *****************************************************************/
-VOID SendStatisticsPointerRequest(PMINI_ADAPTER Adapter,
+static VOID SendStatisticsPointerRequest(PMINI_ADAPTER Adapter,
 								PLINK_REQUEST	pstStatisticsPtrRequest)
 {
 	BCM_DEBUG_PRINT(Adapter,DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "======>");
@@ -526,7 +527,7 @@ VOID SendStatisticsPointerRequest(PMINI_ADAPTER Adapter,
 	BCM_DEBUG_PRINT(Adapter,DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "<=====");
 	return;
 }
-
+#endif
 
 
 void SendLinkDown(PMINI_ADAPTER Adapter)
@@ -1379,7 +1380,7 @@ int bcm_parse_target_params(PMINI_ADAPTER Adapter)
 		return -ENOENT;
 	}
 	oldfs=get_fs();	set_fs(get_ds());
-	len=vfs_read(flp, buff, BUFFER_1K, &pos);
+	len=vfs_read(flp, (void __user __force *)buff, BUFFER_1K, &pos);
 	set_fs(oldfs);
 
 	if(len != sizeof(STARGETPARAMS))
@@ -1535,7 +1536,9 @@ VOID doPowerAutoCorrection(PMINI_ADAPTER psAdapter)
 		BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL,"Using Forced User Choice: %lx\n", psAdapter->ulPowerSaveMode);
 	}
 }
-unsigned char *ReadMacAddrEEPROM(PMINI_ADAPTER Adapter, ulong dwAddress)
+
+#if 0
+static unsigned char *ReadMacAddrEEPROM(PMINI_ADAPTER Adapter, ulong dwAddress)
 {
 	unsigned char *pucmacaddr = NULL;
 	int status = 0, i=0;
@@ -1575,6 +1578,7 @@ unsigned char *ReadMacAddrEEPROM(PMINI_ADAPTER Adapter, ulong dwAddress)
 OUT:
 	return pucmacaddr;
 }
+#endif
 
 #if 0
 INT ReadMacAddressFromEEPROM(PMINI_ADAPTER Adapter)
@@ -1614,7 +1618,7 @@ INT ReadMacAddressFromEEPROM(PMINI_ADAPTER Adapter)
 }
 #endif
 
-void convertEndian(B_UINT8 rwFlag, PUINT puiBuffer, UINT uiByteCount)
+static void convertEndian(B_UINT8 rwFlag, PUINT puiBuffer, UINT uiByteCount)
 {
 	UINT uiIndex = 0;
 
@@ -1814,7 +1818,7 @@ exit:
 }
 
 
-VOID HandleShutDownModeWakeup(PMINI_ADAPTER Adapter)
+static VOID HandleShutDownModeWakeup(PMINI_ADAPTER Adapter)
 {
 	int clear_abort_pattern = 0,Status = 0;
 	BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "====>\n");
@@ -1844,7 +1848,7 @@ VOID HandleShutDownModeWakeup(PMINI_ADAPTER Adapter)
 	BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "<====\n");
 }
 
-VOID SendShutModeResponse(PMINI_ADAPTER Adapter)
+static VOID SendShutModeResponse(PMINI_ADAPTER Adapter)
 {
 	CONTROL_MESSAGE		stShutdownResponse;
 	UINT NVMAccess = 0,lowPwrAbortMsg = 0;
drivers/staging/bcm/PHSModule.c +1 -1
index 8ba8489..8a38cf4 100644
@@ -1345,7 +1345,7 @@ BOOLEAN DerefPhsRule(IN B_UINT16  uiClsId,S_CLASSIFIER_TABLE *psaClassifiertable
 	}
 }
 
-void DumpBuffer(PVOID BuffVAddress, int xferSize)
+static void DumpBuffer(PVOID BuffVAddress, int xferSize)
 {
 	int i;
 	int iPrintLength;
drivers/staging/bcm/Prototypes.h +1 -2
index 7718937..70ec8bc 100644
@@ -108,8 +108,7 @@ int wrmalt (PMINI_ADAPTER Adapter, UINT uiAddress, PUINT pucBuff, size_t sSize);
 
 int rdmalt (PMINI_ADAPTER Adapter, UINT uiAddress, PUINT pucBuff, size_t sSize);
 
-int get_dsx_sf_data_to_application(PMINI_ADAPTER Adapter, UINT uiSFId,
-	PUCHAR user_buffer);
+int get_dsx_sf_data_to_application(PMINI_ADAPTER Adapter, UINT uiSFId, void __user * user_buffer);
 
 void SendLinkDown(PMINI_ADAPTER Adapter);
 
drivers/staging/bcm/Qos.c +4 -4
index 0003825..913a1e1 100644
@@ -692,7 +692,7 @@ USHORT ClassifyPacket(PMINI_ADAPTER Adapter,struct sk_buff* skb)
 		return INVALID_QUEUE_INDEX;
 }
 
-BOOLEAN EthCSMatchSrcMACAddress(S_CLASSIFIER_RULE *pstClassifierRule,PUCHAR Mac)
+static BOOLEAN EthCSMatchSrcMACAddress(S_CLASSIFIER_RULE *pstClassifierRule,PUCHAR Mac)
 {
 	UINT i=0;
     PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(gblpnetdev);
@@ -709,7 +709,7 @@ BOOLEAN EthCSMatchSrcMACAddress(S_CLASSIFIER_RULE *pstClassifierRule,PUCHAR Mac)
 	return TRUE;
 }
 
-BOOLEAN EthCSMatchDestMACAddress(S_CLASSIFIER_RULE *pstClassifierRule,PUCHAR Mac)
+static BOOLEAN EthCSMatchDestMACAddress(S_CLASSIFIER_RULE *pstClassifierRule,PUCHAR Mac)
 {
 	UINT i=0;
     PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(gblpnetdev);
@@ -726,7 +726,7 @@ BOOLEAN EthCSMatchDestMACAddress(S_CLASSIFIER_RULE *pstClassifierRule,PUCHAR Mac
 	return TRUE;
 }
 
-BOOLEAN EthCSMatchEThTypeSAP(S_CLASSIFIER_RULE *pstClassifierRule,struct sk_buff* skb,PS_ETHCS_PKT_INFO pstEthCsPktInfo)
+static BOOLEAN EthCSMatchEThTypeSAP(S_CLASSIFIER_RULE *pstClassifierRule,struct sk_buff* skb,PS_ETHCS_PKT_INFO pstEthCsPktInfo)
 {
     PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(gblpnetdev);
 	if((pstClassifierRule->ucEtherTypeLen==0)||
@@ -761,7 +761,7 @@ BOOLEAN EthCSMatchEThTypeSAP(S_CLASSIFIER_RULE *pstClassifierRule,struct sk_buff
 
 }
 
-BOOLEAN EthCSMatchVLANRules(S_CLASSIFIER_RULE *pstClassifierRule,struct sk_buff* skb,PS_ETHCS_PKT_INFO pstEthCsPktInfo)
+static BOOLEAN EthCSMatchVLANRules(S_CLASSIFIER_RULE *pstClassifierRule,struct sk_buff* skb,PS_ETHCS_PKT_INFO pstEthCsPktInfo)
 {
 	BOOLEAN bClassificationSucceed = FALSE;
 	USHORT usVLANID;
drivers/staging/bcm/led_control.c +11 -11
index 0d07664..97adaae 100644
@@ -22,7 +22,7 @@ BOOLEAN IsReqGpioIsLedInNVM(PMINI_ADAPTER Adapter, UINT gpios)
 		return TRUE;
 }
 
-INT LED_Blink(PMINI_ADAPTER Adapter, UINT GPIO_Num, UCHAR uiLedIndex, ULONG timeout, INT num_of_time, LedEventInfo_t currdriverstate)
+static INT LED_Blink(PMINI_ADAPTER Adapter, UINT GPIO_Num, UCHAR uiLedIndex, ULONG timeout, INT num_of_time, LedEventInfo_t currdriverstate)
 {
 	int Status = STATUS_SUCCESS;
 	BOOLEAN bInfinite = FALSE;
@@ -69,7 +69,7 @@ INT LED_Blink(PMINI_ADAPTER Adapter, UINT GPIO_Num, UCHAR uiLedIndex, ULONG time
 	return Status;
 }
 
-INT ScaleRateofTransfer(ULONG rate)
+static INT ScaleRateofTransfer(ULONG rate)
 {
 	if(rate <= 3)
 		return rate;
@@ -91,7 +91,7 @@ INT ScaleRateofTransfer(ULONG rate)
 
 
 
-INT LED_Proportional_Blink(PMINI_ADAPTER Adapter, UCHAR GPIO_Num_tx,
+static INT LED_Proportional_Blink(PMINI_ADAPTER Adapter, UCHAR GPIO_Num_tx,
 		UCHAR uiTxLedIndex, UCHAR GPIO_Num_rx, UCHAR uiRxLedIndex, LedEventInfo_t currdriverstate)
 {
 	/* Initial values of TX and RX packets*/
@@ -281,7 +281,7 @@ INT LED_Proportional_Blink(PMINI_ADAPTER Adapter, UCHAR GPIO_Num_tx,
 //  <OSAL_STATUS_CODE>
 //-----------------------------------------------------------------------------
 
-INT ValidateDSDParamsChecksum(
+static INT ValidateDSDParamsChecksum(
 													PMINI_ADAPTER Adapter,
 													ULONG  ulParamOffset,
 													USHORT usParamLen )
@@ -293,7 +293,7 @@ INT ValidateDSDParamsChecksum(
 
 	BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL,"LED Thread:ValidateDSDParamsChecksum: 0x%lx 0x%X",ulParamOffset, usParamLen);
 
-	puBuffer = OsalMemAlloc(usParamLen,'!MEM');
+	puBuffer = OsalMemAlloc(usParamLen,"!MEM");
 	if(!puBuffer)
 	{
 		BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL,"LED Thread: ValidateDSDParamsChecksum Allocation failed");
@@ -362,7 +362,7 @@ exit:
 //  <OSAL_STATUS_CODE>
 //-----------------------------------------------------------------------------
 
-INT ValidateHWParmStructure(PMINI_ADAPTER Adapter, ULONG ulHwParamOffset)
+static INT ValidateHWParmStructure(PMINI_ADAPTER Adapter, ULONG ulHwParamOffset)
 {
 
 	INT Status = STATUS_SUCCESS ;
@@ -383,7 +383,7 @@ INT ValidateHWParmStructure(PMINI_ADAPTER Adapter, ULONG ulHwParamOffset)
 	return Status;
 } /* ValidateHWParmStructure() */
 
-int ReadLEDInformationFromEEPROM(PMINI_ADAPTER Adapter, UCHAR GPIO_Array[])
+static int ReadLEDInformationFromEEPROM(PMINI_ADAPTER Adapter, UCHAR GPIO_Array[])
 {
 	int Status = STATUS_SUCCESS;
 
@@ -493,7 +493,7 @@ int ReadLEDInformationFromEEPROM(PMINI_ADAPTER Adapter, UCHAR GPIO_Array[])
 }
 
 
-int ReadConfigFileStructure(PMINI_ADAPTER Adapter, BOOLEAN *bEnableThread)
+static int ReadConfigFileStructure(PMINI_ADAPTER Adapter, BOOLEAN *bEnableThread)
 {
 	int Status = STATUS_SUCCESS;
 	UCHAR GPIO_Array[NUM_OF_LEDS+1]; /*Array to store GPIO numbers from EEPROM*/
@@ -610,7 +610,7 @@ int ReadConfigFileStructure(PMINI_ADAPTER Adapter, BOOLEAN *bEnableThread)
 //
 //-----------------------------------------------------------------------------
 
-VOID LedGpioInit(PMINI_ADAPTER Adapter)
+static VOID LedGpioInit(PMINI_ADAPTER Adapter)
 {
 	UINT uiResetValue = 0;
 	UINT uiIndex      = 0;
@@ -631,7 +631,7 @@ VOID LedGpioInit(PMINI_ADAPTER Adapter)
 }
 //-----------------------------------------------------------------------------
 
-INT BcmGetGPIOPinInfo(PMINI_ADAPTER Adapter, UCHAR *GPIO_num_tx, UCHAR *GPIO_num_rx ,UCHAR *uiLedTxIndex, UCHAR *uiLedRxIndex,LedEventInfo_t currdriverstate)
+static INT BcmGetGPIOPinInfo(PMINI_ADAPTER Adapter, UCHAR *GPIO_num_tx, UCHAR *GPIO_num_rx ,UCHAR *uiLedTxIndex, UCHAR *uiLedRxIndex,LedEventInfo_t currdriverstate)
 {
 	UINT uiIndex = 0;
 
@@ -676,7 +676,7 @@ INT BcmGetGPIOPinInfo(PMINI_ADAPTER Adapter, UCHAR *GPIO_num_tx, UCHAR *GPIO_num
 	}
 	return STATUS_SUCCESS ;
 }
-VOID LEDControlThread(PMINI_ADAPTER Adapter)
+static VOID LEDControlThread(PMINI_ADAPTER Adapter)
 {
 	UINT uiIndex = 0;
 	UCHAR GPIO_num = 0;
drivers/staging/bcm/nvm.c +27 -27

216 lines not on this page · raw message

Signature · 1 line
1.7.1
#11 lore raw
In reply to Arnd Bergmann
Quoted 7 lines · Arnd Bergmann

My previous version of the first patch (staging: make new character devices nonseekable) was untested and broke compilation in multiple ways.

To make up for this, please take the fixed version and some patches to fix basic problems in those two drivers, as found by building with sparse.

Thanks for ft1000 patches. I'll test tomorrow when will have ft1000 device available and let you know if there will be some regression. Thanks for patches.

Quoted 36 lines

       Arnd

Arnd Bergmann (6):
 staging: make new character devices nonseekable stagin/ft1000-usb: fix unlocked_ioctl prototype staging/ft1000-usb: fix build warnings staging/ft1000-usb: fix problems found by sparse staging/bcm: fix most build warnings staging/bcm: add sparse annotations

 drivers/staging/bcm/Adapter.h                      |    2 +-
 drivers/staging/bcm/Bcmchar.c                      |  168 ++++++++++----------
 drivers/staging/bcm/Bcmnet.c                       |    6 +-
 drivers/staging/bcm/CmHost.c                       |   18 +-

 drivers/staging/bcm/Debug.c                        |    2 +- drivers/staging/bcm/HandleControlPacket.c          |    2 +- drivers/staging/bcm/IPv6Protocol.c                 |    4 +- drivers/staging/bcm/InterfaceDld.c                 |    6 +- drivers/staging/bcm/InterfaceIdleMode.c            |    2 +- drivers/staging/bcm/InterfaceIdleMode.h            |    2 +- drivers/staging/bcm/InterfaceInit.c                |   31 ++-- drivers/staging/bcm/Ioctl.h                        |    8 +- drivers/staging/bcm/LeakyBucket.c                  |   22 ++-- drivers/staging/bcm/Macros.h                       |    2 +- drivers/staging/bcm/Misc.c                         |   20 ++- drivers/staging/bcm/PHSDefines.h                   |    2 +- drivers/staging/bcm/PHSModule.c                    |    2 +- drivers/staging/bcm/Prototypes.h                   |    3 +- drivers/staging/bcm/Qos.c                          |    8 +- drivers/staging/bcm/Transmit.c                     |    4 +- drivers/staging/bcm/led_control.c                  |   22 ++-- drivers/staging/bcm/nvm.c                          |   54 +++--- drivers/staging/ft1000/ft1000-usb/ft1000_chdev.c   |   92 ++++++------ .../staging/ft1000/ft1000-usb/ft1000_download.c    |   45 +++--- drivers/staging/ft1000/ft1000-usb/ft1000_hw.c      |   95 +++++-------

Quoted 6 lines
 drivers/staging/ft1000/ft1000-usb/ft1000_proc.c    |    2 +-
 drivers/staging/ft1000/ft1000-usb/ft1000_usb.c     |   25 +---
 drivers/staging/ft1000/ft1000-usb/ft1000_usb.h     |   43 +++++-
 28 files changed, 348 insertions(+), 344 deletions(-)

marek

Signature · 11 lines
as simple and primitive as possible
-------------------------------------------------
Marek Belisko - OPEN-NANDRA
Freelance Developer

Ruska Nova Ves 219 | Presov, 08005 Slovak Republic
Tel: +421 915 052 184
skype: marekwhite
icq: 290551086
web: http://open-nandra.com
���{.n�+�������+%�����ݶ��w��{.n�+����{��G�����{ay�ʇڙ�,j��f���h��������z_�(�階�ݢj"���m������G������?����&���~��iO��z��v�^�m����������?�I�