mirror of
https://github.com/ipxe/ipxe
synced 2025-12-15 00:12:19 +03:00
Fix a couple of broken assertions, and align the buffer correctly.
This commit is contained in:
@@ -33,7 +33,7 @@ struct ll_protocol;
|
|||||||
* This structure is used to represent a network packet within gPXE.
|
* This structure is used to represent a network packet within gPXE.
|
||||||
*/
|
*/
|
||||||
struct pk_buff {
|
struct pk_buff {
|
||||||
/** Head of the buffer */
|
/** Start of the buffer */
|
||||||
void *head;
|
void *head;
|
||||||
/** Start of data */
|
/** Start of data */
|
||||||
void *data;
|
void *data;
|
||||||
@@ -87,7 +87,7 @@ static inline void * pkb_push ( struct pk_buff *pkb, size_t len ) {
|
|||||||
*/
|
*/
|
||||||
static inline void * pkb_pull ( struct pk_buff *pkb, size_t len ) {
|
static inline void * pkb_pull ( struct pk_buff *pkb, size_t len ) {
|
||||||
pkb->data += len;
|
pkb->data += len;
|
||||||
assert ( pkb->data >= pkb->tail );
|
assert ( pkb->data <= pkb->tail );
|
||||||
return pkb->data;
|
return pkb->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ struct pk_buff * alloc_pkb ( size_t len ) {
|
|||||||
void *data;
|
void *data;
|
||||||
|
|
||||||
/* Align buffer length */
|
/* Align buffer length */
|
||||||
len = ( len + __alignof__ ( *pkb ) - 1 ) & ~ __alignof__ ( *pkb );
|
len = ( len + __alignof__( *pkb ) - 1 ) & ~( __alignof__( *pkb ) - 1 );
|
||||||
|
|
||||||
/* Allocate memory for buffer plus descriptor */
|
/* Allocate memory for buffer plus descriptor */
|
||||||
data = malloc_dma ( len + sizeof ( *pkb ), PKBUFF_ALIGN );
|
data = malloc_dma ( len + sizeof ( *pkb ), PKBUFF_ALIGN );
|
||||||
@@ -60,6 +60,9 @@ struct pk_buff * alloc_pkb ( size_t len ) {
|
|||||||
*/
|
*/
|
||||||
void free_pkb ( struct pk_buff *pkb ) {
|
void free_pkb ( struct pk_buff *pkb ) {
|
||||||
if ( pkb ) {
|
if ( pkb ) {
|
||||||
|
assert ( pkb->head <= pkb->data );
|
||||||
|
assert ( pkb->data <= pkb->tail );
|
||||||
|
assert ( pkb->tail <= pkb->end );
|
||||||
free_dma ( pkb->head,
|
free_dma ( pkb->head,
|
||||||
( pkb->end - pkb->head ) + sizeof ( *pkb ) );
|
( pkb->end - pkb->head ) + sizeof ( *pkb ) );
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user