static ssize_t uwbrdev_read(struct file *file, char *buf, size_t count, loff_t *ppos) { struct buffer_descriptor *bufdsc; struct net_adapter *adapter; struct process_descriptor *procdsc; int rlen = 0; adapter = (struct net_adapter *)(file->private_data); if ((adapter == NULL) || adapter->halted) { pr_debug("can't find adapter or Device Removed"); return -ENODEV; } if (buf == NULL) { pr_debug("BUFFER is NULL"); return -EFAULT; /* bad address */ } procdsc = process_by_id(adapter, current->tgid); if (procdsc == NULL) { pr_debug("uwbrdev_read: process %d not exist", current->tgid); return -ESRCH; } if (procdsc->irp == true) { pr_warn("%s: Read was sent twice by process %d\n", __func__, current->tgid); return -EEXIST; } bufdsc = buffer_by_type(adapter, procdsc->type); if (bufdsc == NULL) { procdsc->irp = true; if (wait_event_interruptible(procdsc->read_wait, ((procdsc->irp == false) || (adapter->halted == true)))) { procdsc->irp = false; adapter->pdata->g_cfg->temp_tgid = current->tgid; return -ERESTARTSYS; } if (adapter->halted) { pr_debug("uwbrdev_read: Card Removed" "Indicated to Appln..."); procdsc->irp = false; adapter->pdata->g_cfg->temp_tgid = current->tgid; return -ENODEV; } } if (count == 1500) { /* app passes read count as 1500 */ spin_lock(&adapter->ctl.apps.lock); bufdsc = buffer_by_type(adapter, procdsc->type); if (!bufdsc) { pr_debug("uwbrdev_read: Fail...node is null"); spin_unlock(&adapter->ctl.apps.lock); return -1; } spin_unlock(&adapter->ctl.apps.lock); if (copy_to_user(buf, bufdsc->buffer, bufdsc->length)) { pr_debug("uwbrdev_read: copy_to_user \ failed len=%u !!", bufdsc->length); return -EFAULT; }
ssize_t uwbrdev_read(struct file *file, char *buf, size_t count, loff_t *ppos) { struct buffer_descriptor *dsc; struct net_adapter *adapter; struct process_descriptor *process; int rlen = 0; adapter = (struct net_adapter *)(file->private_data); if ((adapter == NULL) || adapter->halted) { dump_debug("can't find adapter or Device Removed"); return -ENODEV; } if (buf == NULL) { dump_debug("BUFFER is NULL"); return -EFAULT; /* bad address */ } process = process_by_id(adapter, current->tgid); if (process == NULL) { dump_debug("uwbrdev_read: " "process %d not exist", current->tgid); return -ESRCH; } if (process->irp == FALSE) { dsc = buffer_by_type(adapter->ctl.q_received.head, process->type); if (dsc == NULL) { process->irp = TRUE; if (wait_event_interruptible(process->read_wait, ((process->irp == FALSE) || (adapter->halted == TRUE)))) { process->irp = FALSE; adapter->pdata->g_cfg->temp_tgid = current->tgid; return -ERESTARTSYS; } if (adapter->halted == TRUE) { dump_debug("uwbrdev_read: " "Card Removed " "Indicated to Appln..."); process->irp = FALSE; adapter->pdata->g_cfg->temp_tgid = current->tgid; return -ENODEV; } } if (count == 1500) { /* app passes read count as 1500 */ spin_lock(&adapter->ctl.apps.lock); dsc = buffer_by_type(adapter->ctl.q_received.head, process->type); if (!dsc) { dump_debug("uwbrdev_read: Fail...node is null"); spin_unlock(&adapter->ctl.apps.lock); return -1; } spin_unlock(&adapter->ctl.apps.lock); if (copy_to_user(buf, dsc->buffer, dsc->length)) { dump_debug("uwbrdev_read:copy_to_user failed" "len=%lu !!", dsc->length); return -EFAULT; } spin_lock(&adapter->ctl.apps.lock); rlen = dsc->length; hw_return_packet(adapter, dsc->type); spin_unlock(&adapter->ctl.apps.lock); } } else { dump_debug("uwbrdev_read: Read was sent twice " "by process %d", current->tgid); return -EEXIST; } return rlen; }