From dbe84c5aad583a4194666d2d925a5cda53852631 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Sun, 1 Feb 2009 18:02:28 +0000 Subject: [iobuf] Add iob_disown() and use it where it simplifies code There are many functions that take ownership of the I/O buffer they are passed as a parameter. The caller should not retain a pointer to the I/O buffer. Use iob_disown() to automatically nullify the caller's pointer, e.g.: xfer_deliver_iob ( xfer, iob_disown ( iobuf ) ); This will ensure that iobuf is set to NULL for any code after the call to xfer_deliver_iob(). iob_disown() is currently used only in places where it simplifies the code, by avoiding an extra line explicitly setting the I/O buffer pointer to NULL. It should ideally be used with each call to any function that takes ownership of an I/O buffer. (The SSA optimisations will ensure that use of iob_disown() gets optimised away in cases where the caller makes no further use of the I/O buffer pointer anyway.) If gcc ever introduces an __attribute__((free)), indicating that use of a function argument after a function call should generate a warning, then we should use this to identify all applicable function call sites, and add iob_disown() as necessary. --- src/interface/efi/efi_snp.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/interface/efi/efi_snp.c') diff --git a/src/interface/efi/efi_snp.c b/src/interface/efi/efi_snp.c index 491d2a80..771b9174 100644 --- a/src/interface/efi/efi_snp.c +++ b/src/interface/efi/efi_snp.c @@ -602,10 +602,9 @@ efi_snp_transmit ( EFI_SIMPLE_NETWORK_PROTOCOL *snp, } /* Transmit packet */ - if ( ( rc = netdev_tx ( snpdev->netdev, iobuf ) ) != 0 ) { + if ( ( rc = netdev_tx ( snpdev->netdev, iob_disown ( iobuf ) ) ) != 0){ DBGC ( snpdev, "SNPDEV %p TX could not transmit: %s\n", snpdev, strerror ( rc ) ); - iobuf = NULL; efirc = RC_TO_EFIRC ( rc ); goto err_tx; } -- cgit v1.2.3-55-g7522