Browse Source

Fix a couple of broken assertions, and align the buffer correctly.

tags/v0.9.3
Michael Brown 18 years ago
parent
commit
1488cd3b73
2 changed files with 6 additions and 3 deletions
  1. 2
    2
      src/include/gpxe/pkbuff.h
  2. 4
    1
      src/net/pkbuff.c

+ 2
- 2
src/include/gpxe/pkbuff.h View File

33
  * This structure is used to represent a network packet within gPXE.
33
  * This structure is used to represent a network packet within gPXE.
34
  */
34
  */
35
 struct pk_buff {
35
 struct pk_buff {
36
-	/** Head of the buffer */
36
+	/** Start of the buffer */
37
 	void *head;
37
 	void *head;
38
 	/** Start of data */
38
 	/** Start of data */
39
 	void *data;
39
 	void *data;
87
  */
87
  */
88
 static inline void * pkb_pull ( struct pk_buff *pkb, size_t len ) {
88
 static inline void * pkb_pull ( struct pk_buff *pkb, size_t len ) {
89
 	pkb->data += len;
89
 	pkb->data += len;
90
-	assert ( pkb->data >= pkb->tail );
90
+	assert ( pkb->data <= pkb->tail );
91
 	return pkb->data;
91
 	return pkb->data;
92
 }
92
 }
93
 
93
 

+ 4
- 1
src/net/pkbuff.c View File

40
 	void *data;
40
 	void *data;
41
 
41
 
42
 	/* Align buffer length */
42
 	/* Align buffer length */
43
-	len = ( len + __alignof__ ( *pkb ) - 1 ) & ~ __alignof__ ( *pkb );
43
+	len = ( len + __alignof__( *pkb ) - 1 ) & ~( __alignof__( *pkb ) - 1 );
44
 	
44
 	
45
 	/* Allocate memory for buffer plus descriptor */
45
 	/* Allocate memory for buffer plus descriptor */
46
 	data = malloc_dma ( len + sizeof ( *pkb ), PKBUFF_ALIGN );
46
 	data = malloc_dma ( len + sizeof ( *pkb ), PKBUFF_ALIGN );
60
  */
60
  */
61
 void free_pkb ( struct pk_buff *pkb ) {
61
 void free_pkb ( struct pk_buff *pkb ) {
62
 	if ( pkb ) {
62
 	if ( pkb ) {
63
+		assert ( pkb->head <= pkb->data );
64
+		assert ( pkb->data <= pkb->tail );
65
+		assert ( pkb->tail <= pkb->end );
63
 		free_dma ( pkb->head,
66
 		free_dma ( pkb->head,
64
 			   ( pkb->end - pkb->head ) + sizeof ( *pkb ) );
67
 			   ( pkb->end - pkb->head ) + sizeof ( *pkb ) );
65
 	}
68
 	}

Loading…
Cancel
Save