mirror of https://github.com/ipxe/ipxe.git
[refcnt] Add ref_init() wrapper function
Standardise on using ref_init() to initialise an embedded reference count, to match the coding style used by other embedded objects. Signed-off-by: Michael Brown <mcb30@ipxe.org>pull/1/head
parent
f4faa27dfd
commit
4bfd5b52c1
|
@ -264,7 +264,7 @@ int create_downloader ( struct job_interface *job, struct image *image,
|
||||||
downloader = zalloc ( sizeof ( *downloader ) );
|
downloader = zalloc ( sizeof ( *downloader ) );
|
||||||
if ( ! downloader )
|
if ( ! downloader )
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
downloader->refcnt.free = downloader_free;
|
ref_init ( &downloader->refcnt, downloader_free );
|
||||||
job_init ( &downloader->job, &downloader_job_operations,
|
job_init ( &downloader->job, &downloader_job_operations,
|
||||||
&downloader->refcnt );
|
&downloader->refcnt );
|
||||||
xfer_init ( &downloader->xfer, &downloader_xfer_operations,
|
xfer_init ( &downloader->xfer, &downloader_xfer_operations,
|
||||||
|
|
|
@ -59,6 +59,7 @@ static int hw_open ( struct xfer_interface *xfer, struct uri *uri __unused ) {
|
||||||
hw = zalloc ( sizeof ( *hw ) );
|
hw = zalloc ( sizeof ( *hw ) );
|
||||||
if ( ! hw )
|
if ( ! hw )
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
ref_init ( &hw->refcnt, NULL );
|
||||||
xfer_init ( &hw->xfer, &hw_xfer_operations, &hw->refcnt );
|
xfer_init ( &hw->xfer, &hw_xfer_operations, &hw->refcnt );
|
||||||
process_init ( &hw->process, hw_step, &hw->refcnt );
|
process_init ( &hw->process, hw_step, &hw->refcnt );
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ struct image * alloc_image ( void ) {
|
||||||
|
|
||||||
image = zalloc ( sizeof ( *image ) );
|
image = zalloc ( sizeof ( *image ) );
|
||||||
if ( image ) {
|
if ( image ) {
|
||||||
image->refcnt.free = free_image;
|
ref_init ( &image->refcnt, free_image );
|
||||||
}
|
}
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
|
@ -198,7 +198,7 @@ int open ( const char *uri_string ) {
|
||||||
file = zalloc ( sizeof ( *file ) );
|
file = zalloc ( sizeof ( *file ) );
|
||||||
if ( ! file )
|
if ( ! file )
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
file->refcnt.free = posix_file_free;
|
ref_init ( &file->refcnt, posix_file_free );
|
||||||
file->fd = fd;
|
file->fd = fd;
|
||||||
file->rc = -EINPROGRESS;
|
file->rc = -EINPROGRESS;
|
||||||
xfer_init ( &file->xfer, &posix_file_xfer_operations,
|
xfer_init ( &file->xfer, &posix_file_xfer_operations,
|
||||||
|
|
|
@ -121,6 +121,7 @@ static int numeric_resolv ( struct resolv_interface *resolv,
|
||||||
numeric = zalloc ( sizeof ( *numeric ) );
|
numeric = zalloc ( sizeof ( *numeric ) );
|
||||||
if ( ! numeric )
|
if ( ! numeric )
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
ref_init ( &numeric->refcnt, NULL );
|
||||||
resolv_init ( &numeric->resolv, &null_resolv_ops, &numeric->refcnt );
|
resolv_init ( &numeric->resolv, &null_resolv_ops, &numeric->refcnt );
|
||||||
process_init ( &numeric->process, numeric_step, &numeric->refcnt );
|
process_init ( &numeric->process, numeric_step, &numeric->refcnt );
|
||||||
memcpy ( &numeric->sa, sa, sizeof ( numeric->sa ) );
|
memcpy ( &numeric->sa, sa, sizeof ( numeric->sa ) );
|
||||||
|
@ -256,6 +257,7 @@ int resolv ( struct resolv_interface *resolv, const char *name,
|
||||||
mux = zalloc ( sizeof ( *mux ) + name_len );
|
mux = zalloc ( sizeof ( *mux ) + name_len );
|
||||||
if ( ! mux )
|
if ( ! mux )
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
ref_init ( &mux->refcnt, NULL );
|
||||||
resolv_init ( &mux->parent, &null_resolv_ops, &mux->refcnt );
|
resolv_init ( &mux->parent, &null_resolv_ops, &mux->refcnt );
|
||||||
resolv_init ( &mux->child, &resolv_mux_child_ops, &mux->refcnt );
|
resolv_init ( &mux->child, &resolv_mux_child_ops, &mux->refcnt );
|
||||||
mux->resolver = table_start ( RESOLVERS );
|
mux->resolver = table_start ( RESOLVERS );
|
||||||
|
@ -389,6 +391,7 @@ int xfer_open_named_socket ( struct xfer_interface *xfer, int semantics,
|
||||||
named = zalloc ( sizeof ( *named ) );
|
named = zalloc ( sizeof ( *named ) );
|
||||||
if ( ! named )
|
if ( ! named )
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
ref_init ( &named->refcnt, NULL );
|
||||||
xfer_init ( &named->xfer, &named_xfer_ops, &named->refcnt );
|
xfer_init ( &named->xfer, &named_xfer_ops, &named->refcnt );
|
||||||
resolv_init ( &named->resolv, &named_resolv_ops, &named->refcnt );
|
resolv_init ( &named->resolv, &named_resolv_ops, &named->refcnt );
|
||||||
named->semantics = semantics;
|
named->semantics = semantics;
|
||||||
|
|
|
@ -482,6 +482,7 @@ int srp_attach ( struct scsi_device *scsi, const char *root_path ) {
|
||||||
rc = -ENOMEM;
|
rc = -ENOMEM;
|
||||||
goto err_alloc;
|
goto err_alloc;
|
||||||
}
|
}
|
||||||
|
ref_init ( &srp->refcnt, NULL );
|
||||||
xfer_init ( &srp->socket, &srp_xfer_operations, &srp->refcnt );
|
xfer_init ( &srp->socket, &srp_xfer_operations, &srp->refcnt );
|
||||||
srp->transport = transport;
|
srp->transport = transport;
|
||||||
DBGC ( srp, "SRP %p using %s\n", srp, root_path );
|
DBGC ( srp, "SRP %p using %s\n", srp, root_path );
|
||||||
|
|
|
@ -41,7 +41,7 @@ EMBED_ALL
|
||||||
/* Image structures for all embedded images */
|
/* Image structures for all embedded images */
|
||||||
#undef EMBED
|
#undef EMBED
|
||||||
#define EMBED( _index, _path, _name ) { \
|
#define EMBED( _index, _path, _name ) { \
|
||||||
.refcnt = { .free = embedded_image_free, }, \
|
.refcnt = REF_INIT ( embedded_image_free ), \
|
||||||
.name = _name, \
|
.name = _name, \
|
||||||
.data = ( userptr_t ) ( embedded_image_ ## _index ## _data ), \
|
.data = ( userptr_t ) ( embedded_image_ ## _index ## _data ), \
|
||||||
.len = ( size_t ) embedded_image_ ## _index ## _len, \
|
.len = ( size_t ) embedded_image_ ## _index ## _len, \
|
||||||
|
|
|
@ -40,6 +40,41 @@ struct refcnt {
|
||||||
void ( * free ) ( struct refcnt *refcnt );
|
void ( * free ) ( struct refcnt *refcnt );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialise a reference counter
|
||||||
|
*
|
||||||
|
* @v refcnt Reference counter
|
||||||
|
* @v free Freeing function
|
||||||
|
*/
|
||||||
|
static inline __attribute__ (( always_inline )) void
|
||||||
|
ref_init ( struct refcnt *refcnt,
|
||||||
|
void ( * free ) ( struct refcnt *refcnt ) ) {
|
||||||
|
refcnt->free = free;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialise a reference counter
|
||||||
|
*
|
||||||
|
* @v refcnt Reference counter
|
||||||
|
* @v free Free containing object
|
||||||
|
*/
|
||||||
|
#define ref_init( refcnt, free ) do { \
|
||||||
|
if ( __builtin_constant_p ( (free) ) && ( (free) == NULL ) ) { \
|
||||||
|
/* Skip common case of no initialisation required */ \
|
||||||
|
} else { \
|
||||||
|
ref_init ( (refcnt), (free) ); \
|
||||||
|
} \
|
||||||
|
} while ( 0 )
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialise a static reference counter
|
||||||
|
*
|
||||||
|
* @v free Free containing object
|
||||||
|
*/
|
||||||
|
#define REF_INIT( free ) { \
|
||||||
|
.free = free, \
|
||||||
|
}
|
||||||
|
|
||||||
extern struct refcnt * ref_get ( struct refcnt *refcnt );
|
extern struct refcnt * ref_get ( struct refcnt *refcnt );
|
||||||
extern void ref_put ( struct refcnt *refcnt );
|
extern void ref_put ( struct refcnt *refcnt );
|
||||||
|
|
||||||
|
|
|
@ -438,7 +438,7 @@ int aoe_attach ( struct ata_device *ata, struct net_device *netdev,
|
||||||
aoe = zalloc ( sizeof ( *aoe ) );
|
aoe = zalloc ( sizeof ( *aoe ) );
|
||||||
if ( ! aoe )
|
if ( ! aoe )
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
aoe->refcnt.free = aoe_free;
|
ref_init ( &aoe->refcnt, aoe_free );
|
||||||
aoe->netdev = netdev_get ( netdev );
|
aoe->netdev = netdev_get ( netdev );
|
||||||
memcpy ( aoe->target, netdev->ll_broadcast, sizeof ( aoe->target ) );
|
memcpy ( aoe->target, netdev->ll_broadcast, sizeof ( aoe->target ) );
|
||||||
aoe->tag = AOE_TAG_MAGIC;
|
aoe->tag = AOE_TAG_MAGIC;
|
||||||
|
|
|
@ -271,6 +271,7 @@ static struct settings_operations dhcppkt_settings_operations = {
|
||||||
*/
|
*/
|
||||||
void dhcppkt_init ( struct dhcp_packet *dhcppkt, struct dhcphdr *data,
|
void dhcppkt_init ( struct dhcp_packet *dhcppkt, struct dhcphdr *data,
|
||||||
size_t len ) {
|
size_t len ) {
|
||||||
|
ref_init ( &dhcppkt->refcnt, NULL );
|
||||||
dhcppkt->dhcphdr = data;
|
dhcppkt->dhcphdr = data;
|
||||||
dhcppkt->max_len = len;
|
dhcppkt->max_len = len;
|
||||||
dhcpopt_init ( &dhcppkt->options, &dhcppkt->dhcphdr->options,
|
dhcpopt_init ( &dhcppkt->options, &dhcppkt->dhcphdr->options,
|
||||||
|
|
|
@ -383,6 +383,7 @@ int ib_cmrc_open ( struct xfer_interface *xfer, struct ib_device *ibdev,
|
||||||
rc = -ENOMEM;
|
rc = -ENOMEM;
|
||||||
goto err_alloc;
|
goto err_alloc;
|
||||||
}
|
}
|
||||||
|
ref_init ( &cmrc->refcnt, NULL );
|
||||||
xfer_init ( &cmrc->xfer, &ib_cmrc_xfer_operations, &cmrc->refcnt );
|
xfer_init ( &cmrc->xfer, &ib_cmrc_xfer_operations, &cmrc->refcnt );
|
||||||
cmrc->ibdev = ibdev;
|
cmrc->ibdev = ibdev;
|
||||||
memcpy ( &cmrc->dgid, dgid, sizeof ( cmrc->dgid ) );
|
memcpy ( &cmrc->dgid, dgid, sizeof ( cmrc->dgid ) );
|
||||||
|
|
|
@ -328,7 +328,7 @@ struct net_device * alloc_netdev ( size_t priv_size ) {
|
||||||
total_len = ( sizeof ( *netdev ) + priv_size );
|
total_len = ( sizeof ( *netdev ) + priv_size );
|
||||||
netdev = zalloc ( total_len );
|
netdev = zalloc ( total_len );
|
||||||
if ( netdev ) {
|
if ( netdev ) {
|
||||||
netdev->refcnt.free = free_netdev;
|
ref_init ( &netdev->refcnt, free_netdev );
|
||||||
netdev->link_rc = -EUNKNOWN_LINK_STATUS;
|
netdev->link_rc = -EUNKNOWN_LINK_STATUS;
|
||||||
INIT_LIST_HEAD ( &netdev->tx_queue );
|
INIT_LIST_HEAD ( &netdev->tx_queue );
|
||||||
INIT_LIST_HEAD ( &netdev->rx_queue );
|
INIT_LIST_HEAD ( &netdev->rx_queue );
|
||||||
|
|
|
@ -224,6 +224,7 @@ static int tcp_open ( struct xfer_interface *xfer, struct sockaddr *peer,
|
||||||
if ( ! tcp )
|
if ( ! tcp )
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
DBGC ( tcp, "TCP %p allocated\n", tcp );
|
DBGC ( tcp, "TCP %p allocated\n", tcp );
|
||||||
|
ref_init ( &tcp->refcnt, NULL );
|
||||||
xfer_init ( &tcp->xfer, &tcp_xfer_operations, &tcp->refcnt );
|
xfer_init ( &tcp->xfer, &tcp_xfer_operations, &tcp->refcnt );
|
||||||
tcp->prev_tcp_state = TCP_CLOSED;
|
tcp->prev_tcp_state = TCP_CLOSED;
|
||||||
tcp->tcp_state = TCP_STATE_SENT ( TCP_SYN );
|
tcp->tcp_state = TCP_STATE_SENT ( TCP_SYN );
|
||||||
|
|
|
@ -491,7 +491,7 @@ static int ftp_open ( struct xfer_interface *xfer, struct uri *uri ) {
|
||||||
ftp = zalloc ( sizeof ( *ftp ) );
|
ftp = zalloc ( sizeof ( *ftp ) );
|
||||||
if ( ! ftp )
|
if ( ! ftp )
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
ftp->refcnt.free = ftp_free;
|
ref_init ( &ftp->refcnt, ftp_free );
|
||||||
xfer_init ( &ftp->xfer, &ftp_xfer_operations, &ftp->refcnt );
|
xfer_init ( &ftp->xfer, &ftp_xfer_operations, &ftp->refcnt );
|
||||||
ftp->uri = uri_get ( uri );
|
ftp->uri = uri_get ( uri );
|
||||||
xfer_init ( &ftp->control, &ftp_control_operations, &ftp->refcnt );
|
xfer_init ( &ftp->control, &ftp_control_operations, &ftp->refcnt );
|
||||||
|
|
|
@ -547,7 +547,7 @@ int http_open_filter ( struct xfer_interface *xfer, struct uri *uri,
|
||||||
http = zalloc ( sizeof ( *http ) );
|
http = zalloc ( sizeof ( *http ) );
|
||||||
if ( ! http )
|
if ( ! http )
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
http->refcnt.free = http_free;
|
ref_init ( &http->refcnt, http_free );
|
||||||
xfer_init ( &http->xfer, &http_xfer_operations, &http->refcnt );
|
xfer_init ( &http->xfer, &http_xfer_operations, &http->refcnt );
|
||||||
http->uri = uri_get ( uri );
|
http->uri = uri_get ( uri );
|
||||||
xfer_init ( &http->socket, &http_socket_operations, &http->refcnt );
|
xfer_init ( &http->socket, &http_socket_operations, &http->refcnt );
|
||||||
|
|
|
@ -1792,7 +1792,7 @@ int iscsi_attach ( struct scsi_device *scsi, const char *root_path ) {
|
||||||
iscsi = zalloc ( sizeof ( *iscsi ) );
|
iscsi = zalloc ( sizeof ( *iscsi ) );
|
||||||
if ( ! iscsi )
|
if ( ! iscsi )
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
iscsi->refcnt.free = iscsi_free;
|
ref_init ( &iscsi->refcnt, iscsi_free );
|
||||||
xfer_init ( &iscsi->socket, &iscsi_socket_operations, &iscsi->refcnt );
|
xfer_init ( &iscsi->socket, &iscsi_socket_operations, &iscsi->refcnt );
|
||||||
process_init ( &iscsi->process, iscsi_tx_step, &iscsi->refcnt );
|
process_init ( &iscsi->process, iscsi_tx_step, &iscsi->refcnt );
|
||||||
|
|
||||||
|
|
|
@ -1731,7 +1731,7 @@ int add_tls ( struct xfer_interface *xfer, struct xfer_interface **next ) {
|
||||||
if ( ! tls )
|
if ( ! tls )
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
memset ( tls, 0, sizeof ( *tls ) );
|
memset ( tls, 0, sizeof ( *tls ) );
|
||||||
tls->refcnt.free = free_tls;
|
ref_init ( &tls->refcnt, free_tls );
|
||||||
filter_init ( &tls->plainstream, &tls_plainstream_operations,
|
filter_init ( &tls->plainstream, &tls_plainstream_operations,
|
||||||
&tls->cipherstream, &tls_cipherstream_operations,
|
&tls->cipherstream, &tls_cipherstream_operations,
|
||||||
&tls->refcnt );
|
&tls->refcnt );
|
||||||
|
|
|
@ -110,6 +110,7 @@ static int udp_open_common ( struct xfer_interface *xfer,
|
||||||
if ( ! udp )
|
if ( ! udp )
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
DBGC ( udp, "UDP %p allocated\n", udp );
|
DBGC ( udp, "UDP %p allocated\n", udp );
|
||||||
|
ref_init ( &udp->refcnt, NULL );
|
||||||
xfer_init ( &udp->xfer, &udp_xfer_operations, &udp->refcnt );
|
xfer_init ( &udp->xfer, &udp_xfer_operations, &udp->refcnt );
|
||||||
if ( st_peer )
|
if ( st_peer )
|
||||||
memcpy ( &udp->peer, st_peer, sizeof ( udp->peer ) );
|
memcpy ( &udp->peer, st_peer, sizeof ( udp->peer ) );
|
||||||
|
|
|
@ -1439,7 +1439,7 @@ int start_dhcp ( struct job_interface *job, struct net_device *netdev ) {
|
||||||
dhcp = zalloc ( sizeof ( *dhcp ) );
|
dhcp = zalloc ( sizeof ( *dhcp ) );
|
||||||
if ( ! dhcp )
|
if ( ! dhcp )
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
dhcp->refcnt.free = dhcp_free;
|
ref_init ( &dhcp->refcnt, dhcp_free );
|
||||||
job_init ( &dhcp->job, &dhcp_job_operations, &dhcp->refcnt );
|
job_init ( &dhcp->job, &dhcp_job_operations, &dhcp->refcnt );
|
||||||
xfer_init ( &dhcp->xfer, &dhcp_xfer_operations, &dhcp->refcnt );
|
xfer_init ( &dhcp->xfer, &dhcp_xfer_operations, &dhcp->refcnt );
|
||||||
dhcp->netdev = netdev_get ( netdev );
|
dhcp->netdev = netdev_get ( netdev );
|
||||||
|
@ -1542,7 +1542,7 @@ int start_pxebs ( struct job_interface *job, struct net_device *netdev,
|
||||||
sizeof ( *ip ) /* terminator */ );
|
sizeof ( *ip ) /* terminator */ );
|
||||||
if ( ! dhcp )
|
if ( ! dhcp )
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
dhcp->refcnt.free = dhcp_free;
|
ref_init ( &dhcp->refcnt, dhcp_free );
|
||||||
job_init ( &dhcp->job, &dhcp_job_operations, &dhcp->refcnt );
|
job_init ( &dhcp->job, &dhcp_job_operations, &dhcp->refcnt );
|
||||||
xfer_init ( &dhcp->xfer, &dhcp_xfer_operations, &dhcp->refcnt );
|
xfer_init ( &dhcp->xfer, &dhcp_xfer_operations, &dhcp->refcnt );
|
||||||
dhcp->netdev = netdev_get ( netdev );
|
dhcp->netdev = netdev_get ( netdev );
|
||||||
|
|
|
@ -503,6 +503,7 @@ static int dns_resolv ( struct resolv_interface *resolv,
|
||||||
rc = -ENOMEM;
|
rc = -ENOMEM;
|
||||||
goto err_alloc_dns;
|
goto err_alloc_dns;
|
||||||
}
|
}
|
||||||
|
ref_init ( &dns->refcnt, NULL );
|
||||||
resolv_init ( &dns->resolv, &null_resolv_ops, &dns->refcnt );
|
resolv_init ( &dns->resolv, &null_resolv_ops, &dns->refcnt );
|
||||||
xfer_init ( &dns->socket, &dns_socket_operations, &dns->refcnt );
|
xfer_init ( &dns->socket, &dns_socket_operations, &dns->refcnt );
|
||||||
dns->timer.expired = dns_timer_expired;
|
dns->timer.expired = dns_timer_expired;
|
||||||
|
|
|
@ -748,7 +748,7 @@ static int slam_open ( struct xfer_interface *xfer, struct uri *uri ) {
|
||||||
slam = zalloc ( sizeof ( *slam ) );
|
slam = zalloc ( sizeof ( *slam ) );
|
||||||
if ( ! slam )
|
if ( ! slam )
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
slam->refcnt.free = slam_free;
|
ref_init ( &slam->refcnt, slam_free );
|
||||||
xfer_init ( &slam->xfer, &slam_xfer_operations, &slam->refcnt );
|
xfer_init ( &slam->xfer, &slam_xfer_operations, &slam->refcnt );
|
||||||
xfer_init ( &slam->socket, &slam_socket_operations, &slam->refcnt );
|
xfer_init ( &slam->socket, &slam_socket_operations, &slam->refcnt );
|
||||||
xfer_init ( &slam->mc_socket, &slam_mc_socket_operations,
|
xfer_init ( &slam->mc_socket, &slam_mc_socket_operations,
|
||||||
|
|
|
@ -1134,7 +1134,7 @@ static int tftp_core_open ( struct xfer_interface *xfer, struct uri *uri,
|
||||||
tftp = zalloc ( sizeof ( *tftp ) );
|
tftp = zalloc ( sizeof ( *tftp ) );
|
||||||
if ( ! tftp )
|
if ( ! tftp )
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
tftp->refcnt.free = tftp_free;
|
ref_init ( &tftp->refcnt, tftp_free );
|
||||||
xfer_init ( &tftp->xfer, &tftp_xfer_operations, &tftp->refcnt );
|
xfer_init ( &tftp->xfer, &tftp_xfer_operations, &tftp->refcnt );
|
||||||
tftp->uri = uri_get ( uri );
|
tftp->uri = uri_get ( uri );
|
||||||
xfer_init ( &tftp->socket, &tftp_socket_operations, &tftp->refcnt );
|
xfer_init ( &tftp->socket, &tftp_socket_operations, &tftp->refcnt );
|
||||||
|
|
Loading…
Reference in New Issue