static ssize_t diag_dbgfs_read_usbinfo(struct file *file, char __user *ubuf, size_t count, loff_t *ppos) { char *buf = NULL; int ret = 0; int i = 0; unsigned int buf_size; unsigned int bytes_remaining = 0; unsigned int bytes_written = 0; unsigned int bytes_in_buffer = 0; struct diag_usb_info *usb_info = NULL; if (diag_dbgfs_usbinfo_index >= NUM_DIAG_USB_DEV) { /* Done. Reset to prepare for future requests */ diag_dbgfs_usbinfo_index = 0; return 0; } buf = kzalloc(sizeof(char) * DEBUG_BUF_SIZE, GFP_KERNEL); if (ZERO_OR_NULL_PTR(buf)) { pr_err("diag: %s, Error allocating memory\n", __func__); return -ENOMEM; } buf_size = ksize(buf); bytes_remaining = buf_size; for (i = diag_dbgfs_usbinfo_index; i < NUM_DIAG_USB_DEV; i++) { usb_info = &diag_usb[i]; if (!usb_info->enabled) continue; bytes_written = scnprintf(buf+bytes_in_buffer, bytes_remaining, "id: %d\n" "name: %s\n" "hdl: %p\n" "connected: %d\n" "enabled: %d\n" "mempool: %s\n" "read pending: %d\n" "read count: %lu\n" "write count: %lu\n" "read work pending: %d\n" "read done work pending: %d\n" "connect work pending: %d\n" "disconnect work pending: %d\n\n", usb_info->id, usb_info->name, usb_info->hdl, usb_info->connected, usb_info->enabled, DIAG_MEMPOOL_GET_NAME(usb_info->mempool), usb_info->read_pending, usb_info->read_cnt, usb_info->write_cnt, work_pending(&usb_info->read_work), work_pending(&usb_info->read_done_work), work_pending(&usb_info->connect_work), work_pending(&usb_info->disconnect_work)); bytes_in_buffer += bytes_written; /* Check if there is room to add another table entry */ bytes_remaining = buf_size - bytes_in_buffer; if (bytes_remaining < bytes_written) break; } diag_dbgfs_usbinfo_index = i+1; *ppos = 0; ret = simple_read_from_buffer(ubuf, count, ppos, buf, bytes_in_buffer); kfree(buf); return ret; }
static ssize_t diag_dbgfs_read_mhiinfo(struct file *file, char __user *ubuf, size_t count, loff_t *ppos) { char *buf = NULL; int ret = 0; int i = 0; unsigned int buf_size; unsigned int bytes_remaining = 0; unsigned int bytes_written = 0; unsigned int bytes_in_buffer = 0; struct diag_mhi_info *mhi_info = NULL; if (diag_dbgfs_mhiinfo_index >= NUM_MHI_DEV) { /* Done. Reset to prepare for future requests */ diag_dbgfs_mhiinfo_index = 0; return 0; } buf = kzalloc(sizeof(char) * DEBUG_BUF_SIZE, GFP_KERNEL); if (ZERO_OR_NULL_PTR(buf)) { pr_err("diag: %s, Error allocating memory\n", __func__); return -ENOMEM; } buf_size = ksize(buf); bytes_remaining = buf_size; for (i = diag_dbgfs_mhiinfo_index; i < NUM_MHI_DEV; i++) { mhi_info = &diag_mhi[i]; bytes_written = scnprintf(buf+bytes_in_buffer, bytes_remaining, "id: %d\n" "name: %s\n" "bridge index: %s\n" "mempool: %s\n" "read ch opened: %d\n" "read ch hdl: %pK\n" "write ch opened: %d\n" "write ch hdl: %pK\n" "read work pending: %d\n" "read done work pending: %d\n" "open work pending: %d\n" "close work pending: %d\n\n", mhi_info->id, mhi_info->name, DIAG_BRIDGE_GET_NAME(mhi_info->dev_id), DIAG_MEMPOOL_GET_NAME(mhi_info->mempool), mhi_info->read_ch.opened, mhi_info->read_ch.hdl, mhi_info->write_ch.opened, mhi_info->write_ch.hdl, work_pending(&mhi_info->read_work), work_pending(&mhi_info->read_done_work), work_pending(&mhi_info->open_work), work_pending(&mhi_info->close_work)); bytes_in_buffer += bytes_written; /* Check if there is room to add another table entry */ bytes_remaining = buf_size - bytes_in_buffer; if (bytes_remaining < bytes_written) break; } diag_dbgfs_mhiinfo_index = i+1; *ppos = 0; ret = simple_read_from_buffer(ubuf, count, ppos, buf, bytes_in_buffer); kfree(buf); return ret; }