summaryrefslogtreecommitdiffstats
path: root/src/net/udp/tftp.c
diff options
context:
space:
mode:
authorMichael Brown2009-02-01 19:02:28 +0100
committerMichael Brown2009-02-01 21:16:10 +0100
commitdbe84c5aad583a4194666d2d925a5cda53852631 (patch)
tree401417d56c1f4108345c1489d40c68bf6c098cf7 /src/net/udp/tftp.c
parent[contrib] Update qemu documentation (diff)
downloadipxe-dbe84c5aad583a4194666d2d925a5cda53852631.tar.gz
ipxe-dbe84c5aad583a4194666d2d925a5cda53852631.tar.xz
ipxe-dbe84c5aad583a4194666d2d925a5cda53852631.zip
[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.
Diffstat (limited to 'src/net/udp/tftp.c')
-rw-r--r--src/net/udp/tftp.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/src/net/udp/tftp.c b/src/net/udp/tftp.c
index 13734b0f..ec6b1b40 100644
--- a/src/net/udp/tftp.c
+++ b/src/net/udp/tftp.c
@@ -763,9 +763,8 @@ static int tftp_rx_data ( struct tftp_request *tftp,
memset ( &meta, 0, sizeof ( meta ) );
meta.whence = SEEK_SET;
meta.offset = offset;
- rc = xfer_deliver_iob_meta ( &tftp->xfer, iobuf, &meta );
- iobuf = NULL;
- if ( rc != 0 ) {
+ if ( ( rc = xfer_deliver_iob_meta ( &tftp->xfer, iob_disown ( iobuf ),
+ &meta ) ) != 0 ) {
DBGC ( tftp, "TFTP %p could not deliver data: %s\n",
tftp, strerror ( rc ) );
goto done;
@@ -887,8 +886,7 @@ static int tftp_rx ( struct tftp_request *tftp,
rc = tftp_rx_oack ( tftp, iobuf->data, len );
break;
case htons ( TFTP_DATA ):
- rc = tftp_rx_data ( tftp, iobuf );
- iobuf = NULL;
+ rc = tftp_rx_data ( tftp, iob_disown ( iobuf ) );
break;
case htons ( TFTP_ERROR ):
rc = tftp_rx_error ( tftp, iobuf->data, len );