static ssize_t r3964_write(struct tty_struct *tty, struct file *file, const unsigned char *data, size_t count) { struct r3964_info *pInfo = tty->disc_data; struct r3964_block_header *pHeader; struct r3964_client_info *pClient; unsigned char *new_data; TRACE_L("write request, %d characters", count); if (!pInfo) return -EIO; if (count > R3964_MTU) { if (pInfo->flags & R3964_DEBUG) { TRACE_L(KERN_WARNING "r3964_write: truncating user " "packet from %u to mtu %d", count, R3964_MTU); } count = R3964_MTU; } new_data = kmalloc(count + sizeof(struct r3964_block_header), GFP_KERNEL); TRACE_M("r3964_write - kmalloc %p", new_data); if (new_data == NULL) { if (pInfo->flags & R3964_DEBUG) { printk(KERN_ERR "r3964_write: no memory\n"); } return -ENOSPC; } pHeader = (struct r3964_block_header *)new_data; pHeader->data = new_data + sizeof(struct r3964_block_header); pHeader->length = count; pHeader->locks = 0; pHeader->owner = NULL; tty_lock(); pClient = findClient(pInfo, task_pid(current)); if (pClient) { pHeader->owner = pClient; } memcpy(pHeader->data, data, count); if (pInfo->flags & R3964_DEBUG) { dump_block(pHeader->data, count); } add_tx_queue(pInfo, pHeader); trigger_transmit(pInfo); tty_unlock(); return 0; }
static ssize_t r3964_write(struct tty_struct *tty, struct file *file, const unsigned char *data, size_t count) { struct r3964_info *pInfo = (struct r3964_info *)tty->disc_data; struct r3964_block_header *pHeader; struct r3964_client_info *pClient; unsigned char *new_data; TRACE_L("write request, %d characters", count); /* * Verify the pointers */ if (!pInfo) return -EIO; /* * Ensure that the caller does not wish to send too much. */ if (count > R3964_MTU) { if (pInfo->flags & R3964_DEBUG) { TRACE_L(KERN_WARNING "r3964_write: truncating user " "packet from %u to mtu %d", count, R3964_MTU); } count = R3964_MTU; } /* * Allocate a buffer for the data and copy it from the buffer with header prepended */ new_data = kmalloc(count + sizeof(struct r3964_block_header), GFP_KERNEL); TRACE_M("r3964_write - kmalloc %p", new_data); if (new_data == NULL) { if (pInfo->flags & R3964_DEBUG) { printk(KERN_ERR "r3964_write: no memory\n"); } return -ENOSPC; } pHeader = (struct r3964_block_header *)new_data; pHeader->data = new_data + sizeof(struct r3964_block_header); pHeader->length = count; pHeader->locks = 0; pHeader->owner = NULL; pClient = findClient(pInfo, task_pid(current)); if (pClient) { pHeader->owner = pClient; } memcpy(pHeader->data, data, count); /* We already verified this */ if (pInfo->flags & R3964_DEBUG) { dump_block(pHeader->data, count); } /* * Add buffer to transmit-queue: */ add_tx_queue(pInfo, pHeader); trigger_transmit(pInfo); return 0; }