rem: if (status == B_TIMED_OUT || status == B_WOULD_BLOCK)
add: if (status != B_OK)
context: write_port_etc(port_id id, int32 msgCode, const void *msgBuffer,	size_t bufferSize, uint32 flags, bigtime_t timeout){	cpu_status state;	sem_id cachedSem;	status_t status;	port_msg *msg;	bool userCopy = (flags & PORT_FLAG_USE_USER_MEMCPY) > 0;	int slot;	if (!sPortsActive || id < 0)		return B_BAD_PORT_ID;	// mask irrelevant flags (for acquire_sem() usage)	flags = flags & (B_CAN_INTERRUPT | B_TIMEOUT);	slot = id % sMaxPorts;	if (bufferSize > PORT_MAX_MESSAGE_SIZE)		return EINVAL;	state = disable_interrupts();	GRAB_PORT_LOCK(sPorts[slot]);	if (sPorts[slot].id != id) {		RELEASE_PORT_LOCK(sPorts[slot]);		restore_interrupts(state);		TRACE(("write_port_etc: invalid port_id %ld\n", id));		return B_BAD_PORT_ID;	}	if (sPorts[slot].capacity == 0) {		RELEASE_PORT_LOCK(sPorts[slot]);		restore_interrupts(state);		TRACE(("write_port_etc: port %ld closed\n", id));		return B_BAD_PORT_ID;	}	// store sem_id in local variable 	cachedSem = sPorts[slot].write_sem;	RELEASE_PORT_LOCK(sPorts[slot]);	restore_interrupts(state);	status = acquire_sem_etc(cachedSem, 1, flags, timeout);		// get 1 entry from the queue, block if needed	if (status == B_BAD_SEM_ID || status == B_INTERRUPTED) {		/* somebody deleted the port or the sem while we were waiting */		return B_BAD_PORT_ID;	}	if (status == B_TIMED_OUT || status == B_WOULD_BLOCK)		return status;	if (status != B_NO_ERROR) {		dprintf("write_port_etc: unknown error %ld\n", status);		return status;	}	msg = get_port_msg(msgCode, bufferSize);	if (msg == NULL)		return B_NO_MEMORY;	if (bufferSize > 0) {		if (userCopy) {			// copy from user memory			if ((status = cbuf_user_memcpy_to_chain(msg->buffer_chain, 0, msgBuffer, bufferSize)) < B_OK)				return status;		} else {			// copy from kernel memory			if ((status = cbuf_memcpy_to_chain(msg->buffer_chain, 0, msgBuffer, bufferSize)) < 0)				return status;		}	}	// attach message to queue	state = disable_interrupts();	GRAB_PORT_LOCK(sPorts[slot]);	// first, let's check if the port is still alive	if (sPorts[slot].id == -1) {		// the port has been deleted in the meantime		RELEASE_PORT_LOCK(sPorts[slot]);		restore_interrupts(state);		put_port_msg(msg);		return B_BAD_PORT_ID;	}	list_add_item(&sPorts[slot].msg_queue, msg);	// store sem_id in local variable 	cachedSem = sPorts[slot].read_sem;	RELEASE_PORT_LOCK(sPorts[slot]);	restore_interrupts(state);	// release sem, allowing read (might reschedule)	release_sem(cachedSem);	return B_NO_ERROR;}