Memory allocations cleanups
Subsystems (2)
PATCH 3/3 Memory allocations cleanups
This patch replaces the bunch of arbitrary 64 and 128 bytes alloc_skb() calls with more accurate allocation sizes.
--- include/net/irda/irlan_common.h | 10 ++++++- include/net/irda/irlap_frame.h | 31 +++++++++++++++++++- include/net/irda/irlmp.h | 2 + net/irda/af_irda.c | 3 +- net/irda/ircomm/ircomm_lmp.c | 4 +-- net/irda/iriap.c | 9 +++--- net/irda/iriap_event.c | 2 + net/irda/irlan/irlan_common.c | 46 ++++++++++++++++++++++++------ net/irda/irlan/irlan_provider.c | 12 ++++++-- net/irda/irlap_frame.c | 59 +++++++++++++++++++++------------------ net/irda/irlmp.c | 2 + net/irda/irttp.c | 14 +++++---- 12 files changed, 136 insertions(+), 58 deletions(-)
include/net/irda/irlan_common.h +9 -1
@@ -98,7 +98,15 @@ #define IRLAN_BYTE 0#define IRLAN_SHORT 1#define IRLAN_ARRAY 2 -#define IRLAN_MAX_HEADER (TTP_HEADER+LMP_HEADER+LAP_MAX_HEADER) +/* IrLAN sits on top if IrTTP */ +#define IRLAN_MAX_HEADER (TTP_HEADER+LMP_HEADER) +/* 1 byte for the command code and 1 byte for the parameter count */ +#define IRLAN_CMD_HEADER 2 + +#define IRLAN_STRING_PARAMETER_LEN (name, value) (1 + strlen((name)) + 2 \ + + strlen ((value))) +#define IRLAN_BYTE_PARAMETER_LEN (name) (1 + strlen((name)) + 2 + 1) +#define IRLAN_SHORT_PARAMETER_LEN (name) (1 + strlen((name)) + 2 + 2)/* * IrLAN client
include/net/irda/irlap_frame.h +29 -2
@@ -74,6 +74,19 @@ #define RSP_FRAME 0x00#define PF_BIT 0x10/* Poll/final bit */ +/* Some IrLAP field lengths */ +/* +* Only baud rate triplet is 4 bytes (PV can be 2 bytes). +* All others params (7) are 3 bytes, so that's 7*3 + 1*4 bytes. +*/ +#define IRLAP_NEGOCIATION_PARAMS_LEN 25 +#define IRLAP_DISCOVERY_INFO_LEN 32 + +struct disc_frame { +__u8 caddr;/* Connection address */ +__u8 control; +}IRDA_PACK ; +struct xid_frame {__u8 caddr;/* Connection address */ __u8 control;
@@ -95,11 +108,25 @@ struct test_frame {struct ua_frame {__u8 caddr;__u8 control; -__u32 saddr;/* Source device address */ __u32 daddr;/* Dest device address */ }IRDA_PACK ; - + +struct dm_frame { +__u8 caddr;/* Connection address */ +__u8 control; +}IRDA_PACK ; + +struct rd_frame { +__u8 caddr;/* Connection address */ +__u8 control; +}IRDA_PACK ; + +struct rr_frame { +__u8 caddr;/* Connection address */ +__u8 control; +}IRDA_PACK ; +struct i_frame {__u8 caddr;__u8 control;
include/net/irda/irlmp.h +1 -1
@@ -48,7 +48,7 @@ #define LSAP_CONNLESS 0x70 /* Connection#define DEV_ADDR_ANY 0xffffffff#define LMP_HEADER 2/* Dest LSAP + Source LSAP */ -#define LMP_CONTROL_HEADER 4 +#define LMP_CONTROL_HEADER 4/* LMP_HEADER + opcode + parameter */ #define LMP_PID_HEADER 1/* Used by Ultra */ #define LMP_MAX_HEADER (LMP_CONTROL_HEADER+LAP_MAX_HEADER)
net/irda/af_irda.c +2 -1
@@ -309,7 +309,8 @@ static void irda_connect_response(struct IRDA_ASSERT(self != NULL, return;); - skb =alloc_skb (64 ,GFP_ATOMIC ); + skb =alloc_skb (TTP_MAX_HEADER +TTP_SAR_HEADER , +GFP_ATOMIC );if (skb ==NULL ) {IRDA_DEBUG (0 ,"%s() Unable to allocate sk_buff!\n" , __FUNCTION__);
net/irda/ircomm/ircomm_lmp.c +2 -2
@@ -81,7 +81,7 @@ static int ircomm_lmp_connect_response(s/* Any userdata supplied? */ if (userdata ==NULL ) { - tx_skb =alloc_skb (64 ,GFP_ATOMIC ); + tx_skb =alloc_skb (LMP_MAX_HEADER ,GFP_ATOMIC );if (!tx_skb)return -ENOMEM ;
@@ -115,7 +115,7 @@ static int ircomm_lmp_disconnect_requestIRDA_DEBUG (0 ,"%s()\n" , __FUNCTION__ );if (!userdata) { - tx_skb =alloc_skb (64 ,GFP_ATOMIC ); + tx_skb =alloc_skb (LMP_MAX_HEADER ,GFP_ATOMIC );if (!tx_skb)return -ENOMEM ;
net/irda/iriap.c +5 -4
@@ -345,10 +345,11 @@ static void iriap_disconnect_request(str IRDA_ASSERT(self != NULL, return;); IRDA_ASSERT(self->magic == IAS_MAGIC, return;); - tx_skb =alloc_skb (64 ,GFP_ATOMIC ); + tx_skb =alloc_skb (LMP_MAX_HEADER ,GFP_ATOMIC );if (tx_skb ==NULL ) { -IRDA_DEBUG (0 ,"%s(), Could not allocate an sk_buff of length %d\n" , - __FUNCTION__,64 ); +IRDA_DEBUG (0 , +"%s(), Could not allocate an sk_buff of length %d\n" , + __FUNCTION__,LMP_MAX_HEADER );return ; }
@@ -701,7 +702,7 @@ void iriap_send_ack(struct iriap_cb *sel IRDA_ASSERT(self != NULL, return;); IRDA_ASSERT(self->magic == IAS_MAGIC, return;); - tx_skb =alloc_skb (64 ,GFP_ATOMIC ); + tx_skb =alloc_skb (LMP_MAX_HEADER +1 ,GFP_ATOMIC );if (!tx_skb)return ;
net/irda/iriap_event.c +1 -1
@@ -365,7 +365,7 @@ static void state_r_disconnect(struct irswitch (event) {case IAP_LM_CONNECT_INDICATION : - tx_skb =alloc_skb (64 ,GFP_ATOMIC ); + tx_skb =alloc_skb (LMP_MAX_HEADER ,GFP_ATOMIC );if (tx_skb ==NULL ) {IRDA_WARNING ("%s: unable to malloc!\n" , __FUNCTION__);return ;
net/irda/irlan/irlan_common.c +37 -9
100 lines not on this page · raw message
net/irda/irlan/irlan_provider.c +9 -3
@@ -296,7 +296,14 @@ void irlan_provider_send_reply(struct ir IRDA_ASSERT(self != NULL, return;); IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;); - skb =alloc_skb (128 ,GFP_ATOMIC ); + skb =alloc_skb (IRLAN_MAX_HEADER +IRLAN_CMD_HEADER + +/* Bigger param length comes from CMD_GET_MEDIA_CHAR */ +IRLAN_STRING_PARAMETER_LEN ("FILTER_TYPE" ,"DIRECTED" ) + +IRLAN_STRING_PARAMETER_LEN ("FILTER_TYPE" ,"BORADCAST" ) + +IRLAN_STRING_PARAMETER_LEN ("FILTER_TYPE" ,"MULTICAST" ) + +IRLAN_STRING_PARAMETER_LEN ("ACCESS_TYPE" ,"HOSTED" ), +GFP_ATOMIC ); +if (!skb)return ;
@@ -354,8 +361,7 @@ void irlan_provider_send_reply(struct ir }else skb->data[1 ] =0x02 ;/* 2 parameters */ irlan_insert_byte_param (skb,"DATA_CHAN" , self->stsap_sel_data); -irlan_insert_array_param (skb,"RECONNECT_KEY" ,"LINUX RULES!" , -12 ); +irlan_insert_string_param (skb,"RECONNECT_KEY" ,"LINUX RULES!" );break ;case CMD_FILTER_OPERATION :irlan_filter_request (self, skb);
net/irda/irlap_frame.c +32 -27
145 lines not on this page · raw message
net/irda/irlmp.c +1 -1
@@ -392,7 +392,7 @@ int irlmp_connect_request(struct lsap_cb/* Any userdata? */ if (tx_skb ==NULL ) { - tx_skb =alloc_skb (64 ,GFP_ATOMIC ); + tx_skb =alloc_skb (LMP_MAX_HEADER ,GFP_ATOMIC );if (!tx_skb)return -ENOMEM ;
net/irda/irttp.c +8 -6
@@ -804,12 +804,12 @@ static inline void irttp_give_credit(str self->send_credit, self->avail_credit, self->remote_credit);/* Give credit to peer */ - tx_skb =alloc_skb (64 ,GFP_ATOMIC ); + tx_skb =alloc_skb (TTP_MAX_HEADER ,GFP_ATOMIC );if (!tx_skb)return ;/* Reserve space for LMP, and LAP header */ -skb_reserve (tx_skb, self->max_header_size); +skb_reserve (tx_skb,LMP_MAX_HEADER );/* * Since we can transmit and receive frames concurrently,
@@ -1093,7 +1093,8 @@ int irttp_connect_request(struct tsap_cb/* Any userdata supplied? */ if (userdata ==NULL ) { - tx_skb =alloc_skb (64 ,GFP_ATOMIC ); + tx_skb =alloc_skb (TTP_MAX_HEADER +TTP_SAR_HEADER , +GFP_ATOMIC );if (!tx_skb)return -ENOMEM ;
@@ -1341,7 +1342,8 @@ int irttp_connect_response(struct tsap_c/* Any userdata supplied? */ if (userdata ==NULL ) { - tx_skb =alloc_skb (64 ,GFP_ATOMIC ); + tx_skb =alloc_skb (TTP_MAX_HEADER +TTP_SAR_HEADER , +GFP_ATOMIC );if (!tx_skb)return -ENOMEM ;
@@ -1540,14 +1542,14 @@ int irttp_disconnect_request(struct tsapif (!userdata) {struct sk_buff *tx_skb; - tx_skb =alloc_skb (64 ,GFP_ATOMIC ); + tx_skb =alloc_skb (LMP_MAX_HEADER ,GFP_ATOMIC );if (!tx_skb)return -ENOMEM ;/* * Reserve space for MUX and LAP header */ -skb_reserve (tx_skb,TTP_MAX_HEADER ); +skb_reserve (tx_skb,LMP_MAX_HEADER ); userdata = tx_skb; }
Signature · 1 line
1.4.1.1
From: Samuel Ortiz <[email protected]>
Date: Mon, 11 Sep 2006 08:47:00 +0300
Quoted 4 lines
This patch replaces the bunch of arbitrary 64 and 128 bytes
alloc_skb()calls with more accurate allocation sizes.Signed-off-by Samuel Ortiz <[email protected]>
Also applied, thanks.
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV