Skip to contentSkip to conversation

staging: Check for Null return of allocated skb in fw_download_code

PATCH New Nicholas Krause 1 participant 2 messages Aug 13, 2014 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: Check for Null return of allocated skb in fw_download_code

This patch checks if we are getting a Null allocated skb in the while/do loop of this function. Further more no reference checking is needing as skb_put is only working with the packet defined by skb and not allocating a new one. Further more I am breaking out of the loop in order to make sure we call nic_write_byte and cause no errors with writing the nic byte(s) of private date and then call rt_status which I changed to false in the loop with my additon of checking the allocated skb.

---
 drivers/staging/rtl8192e/rtl8192e/r8192E_firmware.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/staging/rtl8192e/rtl8192e/r8192E_firmware.c +4 -0
index 1a95d1f..829af66 100644
@@ -61,6 +61,10 @@ static bool fw_download_code(struct net_device *dev, u8 *code_virtual_address,
 		}
 
 		skb  = dev_alloc_skb(frag_length + 4);
+		if( skb == NULL) {
+			rt_status =  false ;
+			break;
+		}	
 		memcpy((unsigned char *)(skb->cb), &dev, sizeof(dev));
 		tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
 		tcb_desc->queue_index = TXCMD_QUEUE;
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/1 staging: Check for Null return of allocated skb in fw_download_code

Quoted 29 lines · Nicholas Krause

This patch checks if we are getting a Null allocated skb in the while/do loop of this function. Further more no reference checking is needing as skb_put is only working with the packet defined by skb and not allocating a new one. Further more I am breaking out of the loop in order to make sure we call nic_write_byte and cause no errors with writing the nic byte(s) of private date and then call rt_status which I changed to false in the loop with my additon of checking the allocated skb.

---
 drivers/staging/rtl8192e/rtl8192e/r8192E_firmware.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/staging/rtl8192e/rtl8192e/r8192E_firmware.c +4 -1
index 1a95d1f..829af66 100644
@@ -61,6 +61,10 @@ static bool fw_download_code(struct net_device *dev, u8 *code_virtual_address,
                }
 
                skb  = dev_alloc_skb(frag_length + 4);
+               if( skb == NULL) {
+                       rt_status =  false ;
+                       break;
+               }
                memcpy((unsigned char *)(skb->cb), &dev, sizeof(dev));
                tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
                tcb_desc->queue_index = TXCMD_QUEUE;
--
Quoted 2 lines

1.9.1

If you didn't read my other emails, skb_put is not allocating another skb and therefore no memory leaks
as you guys stated. By the way thanks for the input, I should have read the code more carefully first.
Nick