瀏覽代碼

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

tags/v0.9.3
Michael Brown 18 年之前
父節點
當前提交
1488cd3b73
共有 2 個檔案被更改,包括 6 行新增3 行删除
  1. 2
    2
      src/include/gpxe/pkbuff.h
  2. 4
    1
      src/net/pkbuff.c

+ 2
- 2
src/include/gpxe/pkbuff.h 查看文件

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

+ 4
- 1
src/net/pkbuff.c 查看文件

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

Loading…
取消
儲存