Index: uspace/srv/net/structures/packet/packet.c
===================================================================
--- uspace/srv/net/structures/packet/packet.c	(revision 1e2e0c1eeb07d0d3faf4a5b53314c73e3b0c1a2a)
+++ uspace/srv/net/structures/packet/packet.c	(revision aadf01ebd2c032bc8dd43a6e06ae5715e6c2710f)
@@ -59,14 +59,14 @@
  *  @param[in] packet_id The packet identifier.
  */
-#define PACKET_MAP_PAGE( packet_id )	((( packet_id ) - 1 ) / PACKET_MAP_SIZE )
+#define PACKET_MAP_PAGE(packet_id)	(((packet_id) - 1) / PACKET_MAP_SIZE)
 
 /** Returns the packet index in the corresponding packet map page.
  *  @param[in] packet_id The packet identifier.
  */
-#define PACKET_MAP_INDEX( packet_id )	((( packet_id ) - 1 ) % PACKET_MAP_SIZE )
+#define PACKET_MAP_INDEX(packet_id)	(((packet_id) - 1) % PACKET_MAP_SIZE)
 
 /** Type definition of the packet map page.
  */
-typedef packet_t packet_map_t[ PACKET_MAP_SIZE ];
+typedef packet_t packet_map_t[PACKET_MAP_SIZE];
 /** Type definition of the packet map page pointer.
  */
@@ -77,5 +77,5 @@
  *  @see generic_field.h
  */
-GENERIC_FIELD_DECLARE( gpm, packet_map_t );
+GENERIC_FIELD_DECLARE(gpm, packet_map_t);
 
 /** Releases the packet.
@@ -84,5 +84,5 @@
  *  @returns EINVAL if the packet is not valid.
  */
-int packet_destroy( packet_t packet );
+int packet_destroy(packet_t packet);
 
 /** Packet map global data.
@@ -91,77 +91,83 @@
 	/** Safety lock.
 	 */
-	fibril_rwlock_t	lock;
+	fibril_rwlock_t lock;
 	/** Packet map.
 	 */
-	gpm_t	packet_map;
+	gpm_t packet_map;
 } pm_globals;
 
-GENERIC_FIELD_IMPLEMENT( gpm, packet_map_t );
-
-int packet_destroy( packet_t packet ){
-	if( ! packet_is_valid( packet )) return EINVAL;
-	return munmap( packet, packet->length );
-}
-
-int pm_init( void ){
+GENERIC_FIELD_IMPLEMENT(gpm, packet_map_t);
+
+int packet_destroy(packet_t packet){
+	if(! packet_is_valid(packet)){
+		return EINVAL;
+	}
+	return munmap(packet, packet->length);
+}
+
+int pm_init(void){
 	ERROR_DECLARE;
 
-	fibril_rwlock_initialize( & pm_globals.lock );
-	fibril_rwlock_write_lock( & pm_globals.lock );
-	ERROR_PROPAGATE( gpm_initialize( & pm_globals.packet_map ));
-	fibril_rwlock_write_unlock( & pm_globals.lock );
-	return EOK;
-}
-
-packet_t pm_find( packet_id_t packet_id ){
+	fibril_rwlock_initialize(&pm_globals.lock);
+	fibril_rwlock_write_lock(&pm_globals.lock);
+	ERROR_PROPAGATE(gpm_initialize(&pm_globals.packet_map));
+	fibril_rwlock_write_unlock(&pm_globals.lock);
+	return EOK;
+}
+
+packet_t pm_find(packet_id_t packet_id){
 	packet_map_ref map;
 	packet_t packet;
 
-	if( ! packet_id ) return NULL;
-	fibril_rwlock_read_lock( & pm_globals.lock );
-	if( packet_id > PACKET_MAP_SIZE * gpm_count( & pm_globals.packet_map )){
-		fibril_rwlock_read_unlock( & pm_globals.lock );
-		return NULL;
-	}
-	map = gpm_get_index( & pm_globals.packet_map, PACKET_MAP_PAGE( packet_id ));
-	if( ! map ){
-		fibril_rwlock_read_unlock( & pm_globals.lock );
-		return NULL;
-	}
-	packet = ( * map )[ PACKET_MAP_INDEX( packet_id ) ];
-	fibril_rwlock_read_unlock( & pm_globals.lock );
+	if(! packet_id){
+		return NULL;
+	}
+	fibril_rwlock_read_lock(&pm_globals.lock);
+	if(packet_id > PACKET_MAP_SIZE * gpm_count(&pm_globals.packet_map)){
+		fibril_rwlock_read_unlock(&pm_globals.lock);
+		return NULL;
+	}
+	map = gpm_get_index(&pm_globals.packet_map, PACKET_MAP_PAGE(packet_id));
+	if(! map){
+		fibril_rwlock_read_unlock(&pm_globals.lock);
+		return NULL;
+	}
+	packet = (*map)[PACKET_MAP_INDEX(packet_id)];
+	fibril_rwlock_read_unlock(&pm_globals.lock);
 	return packet;
 }
 
-int pm_add( packet_t packet ){
+int pm_add(packet_t packet){
 	ERROR_DECLARE;
 
 	packet_map_ref map;
 
-	if( ! packet_is_valid( packet )) return EINVAL;
-	fibril_rwlock_write_lock( & pm_globals.lock );
-	if( PACKET_MAP_PAGE( packet->packet_id ) < gpm_count( & pm_globals.packet_map )){
-		map = gpm_get_index( & pm_globals.packet_map, PACKET_MAP_PAGE( packet->packet_id ));
+	if(! packet_is_valid(packet)){
+		return EINVAL;
+	}
+	fibril_rwlock_write_lock(&pm_globals.lock);
+	if(PACKET_MAP_PAGE(packet->packet_id) < gpm_count(&pm_globals.packet_map)){
+		map = gpm_get_index(&pm_globals.packet_map, PACKET_MAP_PAGE(packet->packet_id));
 	}else{
 		do{
-			map = ( packet_map_ref ) malloc( sizeof( packet_map_t ));
-			if( ! map ){
-				fibril_rwlock_write_unlock( & pm_globals.lock );
+			map = (packet_map_ref) malloc(sizeof(packet_map_t));
+			if(! map){
+				fibril_rwlock_write_unlock(&pm_globals.lock);
 				return ENOMEM;
 			}
-			bzero( map, sizeof( packet_map_t ));
-			if(( ERROR_CODE = gpm_add( & pm_globals.packet_map, map )) < 0 ){
-				fibril_rwlock_write_unlock( & pm_globals.lock );
-				free( map );
+			bzero(map, sizeof(packet_map_t));
+			if((ERROR_CODE = gpm_add(&pm_globals.packet_map, map)) < 0){
+				fibril_rwlock_write_unlock(&pm_globals.lock);
+				free(map);
 				return ERROR_CODE;
 			}
-		}while( PACKET_MAP_PAGE( packet->packet_id ) >= gpm_count( & pm_globals.packet_map ));
-	}
-	( * map )[ PACKET_MAP_INDEX( packet->packet_id ) ] = packet;
-	fibril_rwlock_write_unlock( & pm_globals.lock );
-	return EOK;
-}
-
-void pm_destroy( void ){
+		}while(PACKET_MAP_PAGE(packet->packet_id) >= gpm_count(&pm_globals.packet_map));
+	}
+	(*map)[PACKET_MAP_INDEX(packet->packet_id)] = packet;
+	fibril_rwlock_write_unlock(&pm_globals.lock);
+	return EOK;
+}
+
+void pm_destroy(void){
 	int count;
 	int index;
@@ -169,30 +175,32 @@
 	packet_t packet;
 
-	fibril_rwlock_write_lock( & pm_globals.lock );
-	count = gpm_count( & pm_globals.packet_map );
-	while( count > 0 ){
-		map = gpm_get_index( & pm_globals.packet_map, count - 1 );
-		for( index = PACKET_MAP_SIZE - 1; index >= 0; -- index ){
-			packet = ( * map )[ index ];
-			if( packet_is_valid( packet )){
-				munmap( packet, packet->length );
+	fibril_rwlock_write_lock(&pm_globals.lock);
+	count = gpm_count(&pm_globals.packet_map);
+	while(count > 0){
+		map = gpm_get_index(&pm_globals.packet_map, count - 1);
+		for(index = PACKET_MAP_SIZE - 1; index >= 0; -- index){
+			packet = (*map)[index];
+			if(packet_is_valid(packet)){
+				munmap(packet, packet->length);
 			}
 		}
 	}
-	gpm_destroy( & pm_globals.packet_map );
+	gpm_destroy(&pm_globals.packet_map);
 	// leave locked
 }
 
-int pq_add( packet_t * first, packet_t packet, size_t order, size_t metric ){
-	packet_t	item;
-
-	if(( ! first ) || ( ! packet_is_valid( packet ))) return EINVAL;
-	pq_set_order( packet, order, metric );
-	if( packet_is_valid( * first )){
+int pq_add(packet_t * first, packet_t packet, size_t order, size_t metric){
+	packet_t item;
+
+	if((! first) || (! packet_is_valid(packet))){
+		return EINVAL;
+	}
+	pq_set_order(packet, order, metric);
+	if(packet_is_valid(*first)){
 		item = * first;
 		do{
-			if( item->order < order ){
-				if( item->next ){
-					item = pm_find( item->next );
+			if(item->order < order){
+				if(item->next){
+					item = pm_find(item->next);
 				}else{
 					item->next = packet->packet_id;
@@ -204,27 +212,31 @@
 				packet->next = item->packet_id;
 				item->previous = packet->packet_id;
-				item = pm_find( packet->previous );
-				if( item ){
+				item = pm_find(packet->previous);
+				if(item){
 					item->next = packet->packet_id;
 				}else{
-					* first = packet;
+					*first = packet;
 				}
 				return EOK;
 			}
-		}while( packet_is_valid( item ));
-	}
-	* first = packet;
-	return EOK;
-}
-
-packet_t pq_find( packet_t packet, size_t order ){
-	packet_t	item;
-
-	if( ! packet_is_valid( packet )) return NULL;
-	if( packet->order == order ) return packet;
-	item = pm_find( packet->next );
-	while( item && ( item != packet )){
-		item = pm_find( item->next );
-		if( item->order == order ){
+		}while(packet_is_valid(item));
+	}
+	*first = packet;
+	return EOK;
+}
+
+packet_t pq_find(packet_t packet, size_t order){
+	packet_t item;
+
+	if(! packet_is_valid(packet)){
+		return NULL;
+	}
+	if(packet->order == order){
+		return packet;
+	}
+	item = pm_find(packet->next);
+	while(item && (item != packet)){
+		item = pm_find(item->next);
+		if(item->order == order){
 			return item;
 		}
@@ -233,26 +245,32 @@
 }
 
-int	pq_insert_after( packet_t packet, packet_t new_packet ){
-	packet_t	item;
-
-	if( !( packet_is_valid( packet ) && packet_is_valid( new_packet ))) return EINVAL;
+int pq_insert_after(packet_t packet, packet_t new_packet){
+	packet_t item;
+
+	if(!(packet_is_valid(packet) && packet_is_valid(new_packet))){
+		return EINVAL;
+	}
 	new_packet->previous = packet->packet_id;
 	new_packet->next = packet->next;
-	item = pm_find( packet->next );
-	if( item ) item->previous = new_packet->packet_id;
+	item = pm_find(packet->next);
+	if(item){
+		item->previous = new_packet->packet_id;
+	}
 	packet->next = new_packet->packet_id;
 	return EOK;
 }
 
-packet_t pq_detach( packet_t packet ){
+packet_t pq_detach(packet_t packet){
 	packet_t next;
 	packet_t previous;
 
-	if( ! packet_is_valid( packet )) return NULL;
-	next = pm_find( packet->next );
-	if( next ){
+	if(! packet_is_valid(packet)){
+		return NULL;
+	}
+	next = pm_find(packet->next);
+	if(next){
 		next->previous = packet->previous;
-		previous = pm_find( next->previous );
-		if( previous ){
+		previous = pm_find(next->previous);
+		if(previous){
 			previous->next = next->packet_id;
 		}
@@ -263,6 +281,8 @@
 }
 
-int pq_set_order( packet_t packet, size_t order, size_t metric ){
-	if( ! packet_is_valid( packet )) return EINVAL;
+int pq_set_order(packet_t packet, size_t order, size_t metric){
+	if(! packet_is_valid(packet)){
+		return EINVAL;
+	}
 	packet->order = order;
 	packet->metric = metric;
@@ -270,33 +290,45 @@
 }
 
-int pq_get_order( packet_t packet, size_t * order, size_t * metric ){
-	if( ! packet_is_valid( packet )) return EINVAL;
-	if( order ) * order = packet->order;
-	if( metric ) * metric = packet->metric;
-	return EOK;
-}
-
-void pq_destroy( packet_t first, void ( * packet_release )( packet_t packet )){
-	packet_t	actual;
-	packet_t	next;
+int pq_get_order(packet_t packet, size_t * order, size_t * metric){
+	if(! packet_is_valid(packet)){
+		return EINVAL;
+	}
+	if(order){
+		*order = packet->order;
+	}
+	if(metric){
+		*metric = packet->metric;
+	}
+	return EOK;
+}
+
+void pq_destroy(packet_t first, void (*packet_release)(packet_t packet)){
+	packet_t actual;
+	packet_t next;
 
 	actual = first;
-	while( packet_is_valid( actual )){
-		next = pm_find( actual->next );
+	while(packet_is_valid(actual)){
+		next = pm_find(actual->next);
 		actual->next = 0;
 		actual->previous = 0;
-		if( packet_release ) packet_release( actual );
+		if(packet_release){
+			packet_release(actual);
+		}
 		actual = next;
 	}
 }
 
-packet_t pq_next( packet_t packet ){
-	if( ! packet_is_valid( packet )) return NULL;
-	return pm_find( packet->next );
-}
-
-packet_t pq_previous( packet_t packet ){
-	if( ! packet_is_valid( packet )) return NULL;
-	return pm_find( packet->previous );
+packet_t pq_next(packet_t packet){
+	if(! packet_is_valid(packet)){
+		return NULL;
+	}
+	return pm_find(packet->next);
+}
+
+packet_t pq_previous(packet_t packet){
+	if(! packet_is_valid(packet)){
+		return NULL;
+	}
+	return pm_find(packet->previous);
 }
 
