diff --git a/scst/src/dev_handlers/scst_user.c b/scst/src/dev_handlers/scst_user.c index d982d5e6e..bf0bfd479 100644 --- a/scst/src/dev_handlers/scst_user.c +++ b/scst/src/dev_handlers/scst_user.c @@ -46,7 +46,7 @@ for details. #endif #define DEV_USER_CMD_HASH_ORDER 6 -#define DEV_USER_ATTACH_TIMEOUT (5*HZ) +#define DEV_USER_ATTACH_TIMEOUT (5 * HZ) struct scst_user_dev { /* @@ -160,50 +160,42 @@ struct scst_user_cmd { static void dev_user_free_ucmd(struct scst_user_cmd *ucmd); -static struct page *dev_user_alloc_pages(struct scatterlist *sg, - gfp_t gfp_mask, void *priv); +static struct page *dev_user_alloc_pages(struct scatterlist *sg, gfp_t gfp_mask, void *priv); static void dev_user_free_sg_entries(struct scatterlist *sg, int sg_count, void *priv); static void dev_user_add_to_ready(struct scst_user_cmd *ucmd); -static void dev_user_unjam_cmd(struct scst_user_cmd *ucmd, int busy, - unsigned long *flags); +static void dev_user_unjam_cmd(struct scst_user_cmd *ucmd, int busy, unsigned long *flags); static int dev_user_process_reply_on_free(struct scst_user_cmd *ucmd); -static int dev_user_process_reply_tm_exec(struct scst_user_cmd *ucmd, - int status); +static int dev_user_process_reply_tm_exec(struct scst_user_cmd *ucmd, int status); static int dev_user_process_reply_sess(struct scst_user_cmd *ucmd, int status); -static int dev_user_register_dev(struct file *file, - const struct scst_user_dev_desc *dev_desc); +static int dev_user_register_dev(struct file *file, const struct scst_user_dev_desc *dev_desc); static int dev_user_unregister_dev(struct file *file); static int dev_user_flush_cache(struct file *file); static int dev_user_capacity_changed(struct file *file); static int dev_user_prealloc_buffer(struct file *file, void __user *arg); -static int __dev_user_set_opt(struct scst_user_dev *dev, - const struct scst_user_opt *opt); +static int __dev_user_set_opt(struct scst_user_dev *dev, const struct scst_user_opt *opt); static int dev_user_set_opt(struct file *file, const struct scst_user_opt *opt); static int dev_user_get_opt(struct file *file, void __user *arg); static __poll_t dev_user_poll(struct file *filp, poll_table *wait); -static long dev_user_ioctl(struct file *file, unsigned int cmd, - unsigned long arg); +static long dev_user_ioctl(struct file *file, unsigned int cmd, unsigned long arg); static int dev_user_release(struct inode *inode, struct file *file); static int dev_user_exit_dev(struct scst_user_dev *dev); - -static ssize_t dev_user_sysfs_commands_show(struct kobject *kobj, - struct kobj_attribute *attr, char *buf); +static ssize_t dev_user_sysfs_commands_show(struct kobject *kobj, struct kobj_attribute *attr, + char *buf); static struct kobj_attribute dev_user_commands_attr = - __ATTR(commands, S_IRUGO, dev_user_sysfs_commands_show, NULL); + __ATTR(commands, 0444, dev_user_sysfs_commands_show, NULL); static const struct attribute *dev_user_dev_attrs[] = { &dev_user_commands_attr.attr, NULL, }; - static int dev_usr_parse(struct scst_cmd *cmd); /** Data **/ @@ -263,7 +255,7 @@ static inline bool ucmd_get_check(struct scst_user_cmd *ucmd) */ } else { TRACE_DBG("ucmd %p, new ref_cnt %d", ucmd, - atomic_read(&ucmd->ucmd_ref)); + atomic_read(&ucmd->ucmd_ref)); res = false; } return res; @@ -299,13 +291,12 @@ static inline int calc_num_pg(unsigned long buf, int len) static void __dev_user_not_reg(void) { - TRACE_MGMT_DBG("%s", "Device not registered"); - return; + TRACE_MGMT_DBG("Device not registered"); } static inline int dev_user_check_reg(struct scst_user_dev *dev) { - if (dev == NULL) { + if (!dev) { __dev_user_not_reg(); return -ENODEV; } @@ -317,8 +308,7 @@ static inline int scst_user_cmd_hashfn(int h) return h & ((1 << DEV_USER_CMD_HASH_ORDER) - 1); } -static inline struct scst_user_cmd *__ucmd_find_hash(struct scst_user_dev *dev, - unsigned int h) +static inline struct scst_user_cmd *__ucmd_find_hash(struct scst_user_dev *dev, unsigned int h) { struct list_head *head; struct scst_user_cmd *ucmd; @@ -341,16 +331,17 @@ static void cmd_insert_hash(struct scst_user_cmd *ucmd) unsigned long flags; spin_lock_irqsave(&dev->udev_cmd_threads.cmd_list_lock, flags); + do { ucmd->h = dev->handle_counter++; u = __ucmd_find_hash(dev, ucmd->h); - } while (u != NULL); + } while (u); + head = &dev->ucmd_hash[scst_user_cmd_hashfn(ucmd->h)]; list_add_tail(&ucmd->hash_list_entry, head); spin_unlock_irqrestore(&dev->udev_cmd_threads.cmd_list_lock, flags); TRACE_DBG("Inserted ucmd %p, h=%d (dev %s)", ucmd, ucmd->h, dev->name); - return; } static inline void cmd_remove_hash(struct scst_user_cmd *ucmd) @@ -362,7 +353,6 @@ static inline void cmd_remove_hash(struct scst_user_cmd *ucmd) spin_unlock_irqrestore(&ucmd->dev->udev_cmd_threads.cmd_list_lock, flags); TRACE_DBG("Removed ucmd %p, h=%d", ucmd, ucmd->h); - return; } static void dev_user_free_ucmd(struct scst_user_cmd *ucmd) @@ -372,16 +362,14 @@ static void dev_user_free_ucmd(struct scst_user_cmd *ucmd) TRACE_MEM("Freeing ucmd %p", ucmd); cmd_remove_hash(ucmd); - EXTRACHECKS_BUG_ON(ucmd->cmd != NULL); + EXTRACHECKS_BUG_ON(ucmd->cmd); kmem_cache_free(user_cmd_cachep, ucmd); TRACE_EXIT(); - return; } -static struct page *dev_user_alloc_pages(struct scatterlist *sg, - gfp_t gfp_mask, void *priv) +static struct page *dev_user_alloc_pages(struct scatterlist *sg, gfp_t gfp_mask, void *priv) { struct scst_user_cmd *ucmd = priv; int offset = 0; @@ -390,12 +378,12 @@ static struct page *dev_user_alloc_pages(struct scatterlist *sg, /* *sg supposed to be zeroed */ - TRACE_MEM("ucmd %p, ubuff %lx, ucmd->cur_data_page %d", ucmd, - ucmd->ubuff, ucmd->cur_data_page); + TRACE_MEM("ucmd %p, ubuff %lx, ucmd->cur_data_page %d", + ucmd, ucmd->ubuff, ucmd->cur_data_page); if (ucmd->cur_data_page == 0) { TRACE_MEM("ucmd->first_page_offset %d", - ucmd->first_page_offset); + ucmd->first_page_offset); offset = ucmd->first_page_offset; ucmd_get(ucmd); } @@ -403,12 +391,11 @@ static struct page *dev_user_alloc_pages(struct scatterlist *sg, if (ucmd->cur_data_page >= ucmd->num_data_pages) goto out; - sg_set_page(sg, ucmd->data_pages[ucmd->cur_data_page], - PAGE_SIZE - offset, offset); + sg_set_page(sg, ucmd->data_pages[ucmd->cur_data_page], PAGE_SIZE - offset, offset); ucmd->cur_data_page++; - TRACE_MEM("page=%p, length=%d, offset=%d", sg_page(sg), sg->length, - sg->offset); + TRACE_MEM("page=%p, length=%d, offset=%d", + sg_page(sg), sg->length, sg->offset); TRACE_BUFFER("Page data", sg_virt(sg), sg->length); out: @@ -421,7 +408,7 @@ static void dev_user_on_cached_mem_free(struct scst_user_cmd *ucmd) TRACE_ENTRY(); TRACE_MEM("Preparing ON_CACHED_MEM_FREE (ucmd %p, h %d, ubuff %lx)", - ucmd, ucmd->h, ucmd->ubuff); + ucmd, ucmd->h, ucmd->ubuff); ucmd->user_cmd_payload_len = offsetof(struct scst_user_get_cmd, on_cached_mem_free) + @@ -435,7 +422,6 @@ static void dev_user_on_cached_mem_free(struct scst_user_cmd *ucmd) dev_user_add_to_ready(ucmd); TRACE_EXIT(); - return; } static void dev_user_unmap_buf(struct scst_user_cmd *ucmd) @@ -444,8 +430,8 @@ static void dev_user_unmap_buf(struct scst_user_cmd *ucmd) TRACE_ENTRY(); - TRACE_MEM("Unmapping data pages (ucmd %p, ubuff %lx, num %d)", ucmd, - ucmd->ubuff, ucmd->num_data_pages); + TRACE_MEM("Unmapping data pages (ucmd %p, ubuff %lx, num %d)", + ucmd, ucmd->ubuff, ucmd->num_data_pages); for (i = 0; i < ucmd->num_data_pages; i++) { struct page *page = ucmd->data_pages[i]; @@ -460,17 +446,16 @@ static void dev_user_unmap_buf(struct scst_user_cmd *ucmd) ucmd->data_pages = NULL; TRACE_EXIT(); - return; } static void __dev_user_free_sg_entries(struct scst_user_cmd *ucmd) { TRACE_ENTRY(); - sBUG_ON(ucmd->data_pages == NULL); + sBUG_ON(!ucmd->data_pages); TRACE_MEM("Freeing data pages (ucmd=%p, ubuff=%lx, buff_cached=%d)", - ucmd, ucmd->ubuff, ucmd->buff_cached); + ucmd, ucmd->ubuff, ucmd->buff_cached); dev_user_unmap_buf(ucmd); @@ -480,31 +465,27 @@ static void __dev_user_free_sg_entries(struct scst_user_cmd *ucmd) ucmd_put(ucmd); TRACE_EXIT(); - return; } -static void dev_user_free_sg_entries(struct scatterlist *sg, int sg_count, - void *priv) +static void dev_user_free_sg_entries(struct scatterlist *sg, int sg_count, void *priv) { struct scst_user_cmd *ucmd = priv; - TRACE_MEM("Freeing data pages (sg=%p, sg_count=%d, priv %p)", sg, - sg_count, ucmd); + TRACE_MEM("Freeing data pages (sg=%p, sg_count=%d, priv %p)", + sg, sg_count, ucmd); __dev_user_free_sg_entries(ucmd); - - return; } static inline int is_buff_cached(struct scst_user_cmd *ucmd) { int mem_reuse_type = ucmd->dev->memory_reuse_type; - if ((mem_reuse_type == SCST_USER_MEM_REUSE_ALL) || - ((ucmd->cmd->data_direction == SCST_DATA_READ) && - (mem_reuse_type == SCST_USER_MEM_REUSE_READ)) || - ((ucmd->cmd->data_direction == SCST_DATA_WRITE) && - (mem_reuse_type == SCST_USER_MEM_REUSE_WRITE))) + if (mem_reuse_type == SCST_USER_MEM_REUSE_ALL || + (ucmd->cmd->data_direction == SCST_DATA_READ && + mem_reuse_type == SCST_USER_MEM_REUSE_READ) || + (ucmd->cmd->data_direction == SCST_DATA_WRITE && + mem_reuse_type == SCST_USER_MEM_REUSE_WRITE)) return 1; else return 0; @@ -513,7 +494,7 @@ static inline int is_buff_cached(struct scst_user_cmd *ucmd) static inline int is_need_offs_page(unsigned long buf, int len) { return ((buf & ~PAGE_MASK) != 0) && - ((buf & PAGE_MASK) != ((buf+len-1) & PAGE_MASK)); + ((buf & PAGE_MASK) != ((buf + len - 1) & PAGE_MASK)); } /* @@ -557,7 +538,7 @@ static int dev_user_alloc_sg(struct scst_user_cmd *ucmd, int cached_buff) if (ucmd->ubuff == 0) flags |= SGV_POOL_NO_ALLOC_ON_CACHE_MISS; } else { - TRACE_MEM("%s", "Not cached buff"); + TRACE_MEM("Not cached buff"); flags |= SGV_POOL_ALLOC_NO_CACHED; if (ucmd->ubuff == 0) { res = 1; @@ -571,47 +552,43 @@ static int dev_user_alloc_sg(struct scst_user_cmd *ucmd, int cached_buff) } ucmd->buff_cached = cached_buff; - cmd->sg = sgv_pool_alloc(pool, bufflen, gfp_mask, flags, &cmd->sg_cnt, - &ucmd->sgv, &dev->udev_mem_lim, ucmd); - if (cmd->sg != NULL) { + cmd->sg = sgv_pool_alloc(pool, bufflen, gfp_mask, flags, &cmd->sg_cnt, &ucmd->sgv, + &dev->udev_mem_lim, ucmd); + if (cmd->sg) { struct scst_user_cmd *buf_ucmd = sgv_get_priv(ucmd->sgv); - TRACE_MEM("Buf ucmd %p (cmd->sg_cnt %d, last seg len %d, " - "last_len %d, bufflen %d)", buf_ucmd, cmd->sg_cnt, - cmd->sg[cmd->sg_cnt-1].length, last_len, bufflen); + TRACE_MEM("Buf ucmd %p (cmd->sg_cnt %d, last seg len %d, last_len %d, bufflen %d)", + buf_ucmd, cmd->sg_cnt, cmd->sg[cmd->sg_cnt - 1].length, + last_len, bufflen); ucmd->ubuff = buf_ucmd->ubuff; ucmd->buf_ucmd = buf_ucmd; - EXTRACHECKS_BUG_ON((ucmd->data_pages != NULL) && - (ucmd != buf_ucmd)); + EXTRACHECKS_BUG_ON(ucmd->data_pages && ucmd != buf_ucmd); if (last_len != 0) { - cmd->sg[cmd->sg_cnt-1].length &= PAGE_MASK; - cmd->sg[cmd->sg_cnt-1].length += last_len; + cmd->sg[cmd->sg_cnt - 1].length &= PAGE_MASK; + cmd->sg[cmd->sg_cnt - 1].length += last_len; } - TRACE_MEM("Buf alloced (ucmd %p, cached_buff %d, ubuff %lx, " - "last seg len %d)", ucmd, cached_buff, ucmd->ubuff, - cmd->sg[cmd->sg_cnt-1].length); + TRACE_MEM("Buf alloced (ucmd %p, cached_buff %d, ubuff %lx, last seg len %d)", + ucmd, cached_buff, ucmd->ubuff, cmd->sg[cmd->sg_cnt - 1].length); if (cmd->data_direction == SCST_DATA_BIDI) { cmd->out_sg = &cmd->sg[out_sg_pages]; cmd->out_sg_cnt = cmd->sg_cnt - out_sg_pages; cmd->sg_cnt = out_sg_pages; TRACE_MEM("cmd %p, out_sg %p, out_sg_cnt %d, sg_cnt %d", - cmd, cmd->out_sg, cmd->out_sg_cnt, cmd->sg_cnt); + cmd, cmd->out_sg, cmd->out_sg_cnt, cmd->sg_cnt); } if (unlikely(cmd->sg_cnt > cmd->tgt_dev->max_sg_cnt)) { static int ll; - if ((ll < 10) || TRACING_MINOR()) { - PRINT_INFO("Unable to complete command due to " - "SG IO count limitation (requested %d, " - "available %d, tgt lim %d)", - cmd->sg_cnt, cmd->tgt_dev->max_sg_cnt, - cmd->tgt->sg_tablesize); + if (ll < 10 || TRACING_MINOR()) { + PRINT_INFO("Unable to complete command due to SG IO count limitation (requested %d, available %d, tgt lim %d)", + cmd->sg_cnt, cmd->tgt_dev->max_sg_cnt, + cmd->tgt->sg_tablesize); ll++; } cmd->sg = NULL; @@ -619,12 +596,11 @@ static int dev_user_alloc_sg(struct scst_user_cmd *ucmd, int cached_buff) res = -1; } } else { - TRACE_MEM("Buf not alloced (ucmd %p, h %d, buff_cached, %d, " - "sg_cnt %d, ubuff %lx, sgv %p", ucmd, ucmd->h, - ucmd->buff_cached, cmd->sg_cnt, ucmd->ubuff, ucmd->sgv); + TRACE_MEM("Buf not alloced (ucmd %p, h %d, buff_cached, %d, sg_cnt %d, ubuff %lx, sgv %p", + ucmd, ucmd->h, ucmd->buff_cached, cmd->sg_cnt, ucmd->ubuff, ucmd->sgv); if (unlikely(cmd->sg_cnt == 0)) { TRACE_MEM("Refused allocation (ucmd %p)", ucmd); - sBUG_ON(ucmd->sgv != NULL); + sBUG_ON(ucmd->sgv); res = -1; } else { switch (ucmd->state) { @@ -659,7 +635,8 @@ static int dev_user_alloc_space(struct scst_user_cmd *ucmd) rc = dev_user_alloc_sg(ucmd, is_buff_cached(ucmd)); if (rc == 0) goto out; - else if (rc < 0) { + + if (rc < 0) { scst_set_busy(cmd); res = scst_get_cmd_abnormal_done_state(cmd); goto out; @@ -678,7 +655,7 @@ static int dev_user_alloc_space(struct scst_user_cmd *ucmd) ucmd->user_cmd.subcode = SCST_USER_ALLOC_MEM; ucmd->user_cmd.alloc_cmd.sess_h = (unsigned long)cmd->tgt_dev; memcpy(ucmd->user_cmd.alloc_cmd.cdb, cmd->cdb, - min_t(int, SCST_MAX_CDB_SIZE, cmd->cdb_len)); + min_t(int, SCST_MAX_CDB_SIZE, cmd->cdb_len)); ucmd->user_cmd.alloc_cmd.cdb_len = cmd->cdb_len; ucmd->user_cmd.alloc_cmd.alloc_len = ucmd->buff_cached ? (cmd->sg_cnt << PAGE_SHIFT) : cmd->bufflen; @@ -686,8 +663,8 @@ static int dev_user_alloc_space(struct scst_user_cmd *ucmd) ucmd->user_cmd.alloc_cmd.data_direction = cmd->data_direction; ucmd->user_cmd.alloc_cmd.sn = cmd->tgt_sn; - TRACE_DBG("Preparing ALLOC_MEM for user space (ucmd=%p, h=%d, " - "alloc_len %d)", ucmd, ucmd->h, ucmd->user_cmd.alloc_cmd.alloc_len); + TRACE_DBG("Preparing ALLOC_MEM for user space (ucmd=%p, h=%d, alloc_len %d)", + ucmd, ucmd->h, ucmd->user_cmd.alloc_cmd.alloc_len); dev_user_add_to_ready(ucmd); @@ -698,17 +675,16 @@ out: return res; } -static struct scst_user_cmd *dev_user_alloc_ucmd(struct scst_user_dev *dev, - gfp_t gfp_mask) +static struct scst_user_cmd *dev_user_alloc_ucmd(struct scst_user_dev *dev, gfp_t gfp_mask) { struct scst_user_cmd *ucmd = NULL; TRACE_ENTRY(); ucmd = kmem_cache_zalloc(user_cmd_cachep, gfp_mask); - if (unlikely(ucmd == NULL)) { - TRACE(TRACE_OUT_OF_MEM, "Unable to allocate " - "user cmd (gfp_mask %x)", gfp_mask); + if (unlikely(!ucmd)) { + TRACE(TRACE_OUT_OF_MEM, "Unable to allocate user cmd (gfp_mask %x)", + gfp_mask); goto out; } ucmd->dev = dev; @@ -733,9 +709,9 @@ static int dev_user_parse(struct scst_cmd *cmd) TRACE_ENTRY(); - if (cmd->dh_priv == NULL) { + if (!cmd->dh_priv) { ucmd = dev_user_alloc_ucmd(dev, gfp_mask); - if (unlikely(ucmd == NULL)) { + if (unlikely(!ucmd)) { if (atomic) { res = SCST_CMD_STATE_NEED_THREAD_CTX; goto out; @@ -773,19 +749,19 @@ static int dev_user_parse(struct scst_cmd *cmd) case SCST_USER_PARSE_EXCEPTION: TRACE_DBG("PARSE EXCEPTION: ucmd %p", ucmd); rc = dev->generic_parse(cmd); - if ((rc == 0) && (cmd->op_flags & SCST_INFO_VALID)) + if (rc == 0 && (cmd->op_flags & SCST_INFO_VALID)) break; - else if (rc == SCST_CMD_STATE_NEED_THREAD_CTX) { - TRACE_MEM("Restarting PARSE to thread context " - "(ucmd %p)", ucmd); + if (rc == SCST_CMD_STATE_NEED_THREAD_CTX) { + TRACE_MEM("Restarting PARSE to thread context (ucmd %p)", + ucmd); res = SCST_CMD_STATE_NEED_THREAD_CTX; goto out; } fallthrough; case SCST_USER_PARSE_CALL: - TRACE_DBG("Preparing PARSE for user space (ucmd=%p, h=%d, " - "bufflen %d)", ucmd, ucmd->h, cmd->bufflen); + TRACE_DBG("Preparing PARSE for user space (ucmd=%p, h=%d, bufflen %d)", + ucmd, ucmd->h, cmd->bufflen); ucmd->user_cmd_payload_len = offsetof(struct scst_user_get_cmd, parse_cmd) + sizeof(ucmd->user_cmd.parse_cmd); @@ -793,7 +769,7 @@ static int dev_user_parse(struct scst_cmd *cmd) ucmd->user_cmd.subcode = SCST_USER_PARSE; ucmd->user_cmd.parse_cmd.sess_h = (unsigned long)cmd->tgt_dev; memcpy(ucmd->user_cmd.parse_cmd.cdb, cmd->cdb, - min_t(int, SCST_MAX_CDB_SIZE, cmd->cdb_len)); + min_t(int, SCST_MAX_CDB_SIZE, cmd->cdb_len)); ucmd->user_cmd.parse_cmd.cdb_len = cmd->cdb_len; ucmd->user_cmd.parse_cmd.timeout = cmd->timeout / HZ; ucmd->user_cmd.parse_cmd.lba = cmd->lba; @@ -886,7 +862,7 @@ static void dev_user_flush_dcache(struct scst_user_cmd *ucmd) struct vm_area_struct *vma; vma = find_vma(current->mm, start); - if (vma != NULL) + if (vma) flush_anon_page(vma, page, start); } #endif @@ -897,7 +873,6 @@ static void dev_user_flush_dcache(struct scst_user_cmd *ucmd) out: TRACE_EXIT(); - return; } static enum scst_exec_res dev_user_exec(struct scst_cmd *cmd) @@ -907,10 +882,9 @@ static enum scst_exec_res dev_user_exec(struct scst_cmd *cmd) TRACE_ENTRY(); - TRACE_DBG("Preparing EXEC for user space (ucmd=%p, h=%d, lba %lld, " - "bufflen %d, data_len %lld, ubuff %lx)", ucmd, ucmd->h, - (long long)cmd->lba, cmd->bufflen, (long long)cmd->data_len, - ucmd->ubuff); + TRACE_DBG("Preparing EXEC for user space (ucmd=%p, h=%d, lba %lld, bufflen %d, data_len %lld, ubuff %lx)", + ucmd, ucmd->h, (long long)cmd->lba, cmd->bufflen, (long long)cmd->data_len, + ucmd->ubuff); if (cmd->data_direction & SCST_DATA_WRITE) dev_user_flush_dcache(ucmd); @@ -922,13 +896,13 @@ static enum scst_exec_res dev_user_exec(struct scst_cmd *cmd) ucmd->user_cmd.subcode = SCST_USER_EXEC; ucmd->user_cmd.exec_cmd.sess_h = (unsigned long)cmd->tgt_dev; memcpy(ucmd->user_cmd.exec_cmd.cdb, cmd->cdb, - min_t(int, SCST_MAX_CDB_SIZE, cmd->cdb_len)); + min_t(int, SCST_MAX_CDB_SIZE, cmd->cdb_len)); ucmd->user_cmd.exec_cmd.cdb_len = cmd->cdb_len; ucmd->user_cmd.exec_cmd.lba = cmd->lba; ucmd->user_cmd.exec_cmd.bufflen = cmd->bufflen; ucmd->user_cmd.exec_cmd.data_len = cmd->data_len; ucmd->user_cmd.exec_cmd.pbuf = ucmd->ubuff; - if ((ucmd->ubuff == 0) && (cmd->data_direction != SCST_DATA_NONE)) { + if (ucmd->ubuff == 0 && cmd->data_direction != SCST_DATA_NONE) { ucmd->user_cmd.exec_cmd.alloc_len = ucmd->buff_cached ? (cmd->sg_cnt << PAGE_SHIFT) : cmd->bufflen; } @@ -949,15 +923,14 @@ static enum scst_exec_res dev_user_exec(struct scst_cmd *cmd) return res; } -static void dev_user_ext_copy_remap(struct scst_cmd *cmd, - struct scst_ext_copy_seg_descr *seg) +static void dev_user_ext_copy_remap(struct scst_cmd *cmd, struct scst_ext_copy_seg_descr *seg) { struct scst_user_cmd *ucmd = cmd->dh_priv; TRACE_ENTRY(); - TRACE_DBG("Preparing EXT_COPY_REMAP for user space (ucmd=%p, h=%d, " - "seg %p)", ucmd, ucmd->h, seg); + TRACE_DBG("Preparing EXT_COPY_REMAP for user space (ucmd=%p, h=%d, seg %p)", + ucmd, ucmd->h, seg); ucmd->user_cmd_payload_len = offsetof(struct scst_user_get_cmd, remap_cmd) + @@ -977,20 +950,18 @@ static void dev_user_ext_copy_remap(struct scst_cmd *cmd, dev_user_add_to_ready(ucmd); TRACE_EXIT(); - return; } static void dev_user_free_sgv(struct scst_user_cmd *ucmd) { - if (ucmd->sgv != NULL) { + if (ucmd->sgv) { sgv_pool_free(ucmd->sgv, &ucmd->dev->udev_mem_lim); ucmd->sgv = NULL; - } else if (ucmd->data_pages != NULL) { + } else if (ucmd->data_pages) { /* We mapped pages, but for some reason didn't allocate them */ ucmd_get(ucmd); __dev_user_free_sg_entries(ucmd); } - return; } static void dev_user_on_free_cmd(struct scst_cmd *cmd) @@ -999,14 +970,14 @@ static void dev_user_on_free_cmd(struct scst_cmd *cmd) TRACE_ENTRY(); - if (unlikely(ucmd == NULL)) + if (unlikely(!ucmd)) goto out; - TRACE_MEM("ucmd %p, cmd %p, buff_cached %d, ubuff %lx", ucmd, ucmd->cmd, - ucmd->buff_cached, ucmd->ubuff); + TRACE_MEM("ucmd %p, cmd %p, buff_cached %d, ubuff %lx", + ucmd, ucmd->cmd, ucmd->buff_cached, ucmd->ubuff); ucmd->cmd = NULL; - if ((cmd->data_direction & SCST_DATA_WRITE) && ucmd->buf_ucmd != NULL) + if ((cmd->data_direction & SCST_DATA_WRITE) && ucmd->buf_ucmd) ucmd->buf_ucmd->buf_dirty = 1; if (ucmd->dev->on_free_cmd_type == SCST_USER_ON_FREE_CMD_IGNORE) { @@ -1071,7 +1042,6 @@ static void dev_user_set_block_shift(struct scst_cmd *cmd, int block_shift) } TRACE_EXIT(); - return; } static void dev_user_set_block_size(struct scst_cmd *cmd, int block_size) @@ -1085,9 +1055,9 @@ static void dev_user_set_block_size(struct scst_cmd *cmd, int block_size) * called, when there are existing commands. */ TRACE_DBG("dev %p, new block size %d", dev, block_size); - if (block_size != 0) + if (block_size != 0) { dev->block_size = block_size; - else { + } else { struct scst_user_dev *udev = cmd->dev->dh_priv; dev->block_size = udev->def_block_size; @@ -1095,7 +1065,6 @@ static void dev_user_set_block_size(struct scst_cmd *cmd, int block_size) dev->block_shift = -1; /* not used */ TRACE_EXIT(); - return; } static int dev_user_disk_done(struct scst_cmd *cmd) @@ -1148,21 +1117,18 @@ static inline void dev_user_add_to_ready_head(struct scst_user_cmd *ucmd) */ if (unlikely(dev_user_mgmt_ucmd(u))) continue; - TRACE_DBG("Adding ucmd %p (state %d) after mgmt ucmd %p (state " - "%d)", ucmd, ucmd->state, u, u->state); - list_add_tail(&ucmd->ready_cmd_list_entry, - &u->ready_cmd_list_entry); + TRACE_DBG("Adding ucmd %p (state %d) after mgmt ucmd %p (state %d)", + ucmd, ucmd->state, u, u->state); + list_add_tail(&ucmd->ready_cmd_list_entry, &u->ready_cmd_list_entry); goto out; } - TRACE_DBG("Adding ucmd %p (state %d) to tail " - "of mgmt ready cmd list", ucmd, ucmd->state); - list_add_tail(&ucmd->ready_cmd_list_entry, - &dev->ready_cmd_list); + TRACE_DBG("Adding ucmd %p (state %d) to tail of mgmt ready cmd list", + ucmd, ucmd->state); + list_add_tail(&ucmd->ready_cmd_list_entry, &dev->ready_cmd_list); out: TRACE_EXIT(); - return; } static void dev_user_add_to_ready(struct scst_user_cmd *ucmd) @@ -1185,8 +1151,7 @@ static void dev_user_add_to_ready(struct scst_user_cmd *ucmd) ucmd->this_state_unjammed = 0; - if ((ucmd->state == UCMD_STATE_PARSING) || - (ucmd->state == UCMD_STATE_BUF_ALLOCING)) { + if (ucmd->state == UCMD_STATE_PARSING || ucmd->state == UCMD_STATE_BUF_ALLOCING) { /* * If we don't put such commands in the queue head, then under * high load we might delay threads, waiting for memory @@ -1201,10 +1166,10 @@ static void dev_user_add_to_ready(struct scst_user_cmd *ucmd) dev_user_add_to_ready_head(ucmd); do_wake = 1; } else { - if ((ucmd->cmd != NULL) && - unlikely((ucmd->cmd->queue_type == SCST_CMD_QUEUE_HEAD_OF_QUEUE))) { + if (ucmd->cmd && + unlikely(ucmd->cmd->queue_type == SCST_CMD_QUEUE_HEAD_OF_QUEUE)) { TRACE_DBG("Adding HQ ucmd %p to head of ready cmd list", - ucmd); + ucmd); dev_user_add_to_ready_head(ucmd); } else { TRACE_DBG("Adding ucmd %p to ready cmd list", ucmd); @@ -1224,11 +1189,9 @@ static void dev_user_add_to_ready(struct scst_user_cmd *ucmd) spin_unlock_irqrestore(&dev->udev_cmd_threads.cmd_list_lock, flags); TRACE_EXIT(); - return; } -static int dev_user_map_buf(struct scst_user_cmd *ucmd, unsigned long ubuff, - int num_pg) +static int dev_user_map_buf(struct scst_user_cmd *ucmd, unsigned long ubuff, int num_pg) { int res = 0, rc; int i; @@ -1239,24 +1202,23 @@ static int dev_user_map_buf(struct scst_user_cmd *ucmd, unsigned long ubuff, if (unlikely(ubuff == 0)) goto out_nomem; - sBUG_ON(ucmd->data_pages != NULL); + sBUG_ON(ucmd->data_pages); ucmd->num_data_pages = num_pg; ucmd->data_pages = kmalloc_array(ucmd->num_data_pages, sizeof(*ucmd->data_pages), GFP_KERNEL); - if (ucmd->data_pages == NULL) { - TRACE(TRACE_OUT_OF_MEM, "Unable to allocate data_pages array " - "(num_data_pages=%d)", ucmd->num_data_pages); + if (!ucmd->data_pages) { + TRACE(TRACE_OUT_OF_MEM, "Unable to allocate data_pages array (num_data_pages=%d)", + ucmd->num_data_pages); res = -ENOMEM; goto out_nomem; } - TRACE_MEM("Mapping buffer (ucmd %p, ubuff %lx, ucmd->num_data_pages %d," - " first_page_offset %d, len %d)", ucmd, ubuff, - ucmd->num_data_pages, (int)(ubuff & ~PAGE_MASK), - (ucmd->cmd != NULL) ? ucmd->cmd->bufflen : -1); + TRACE_MEM("Mapping buffer (ucmd %p, ubuff %lx, ucmd->num_data_pages %d, first_page_offset %d, len %d)", + ucmd, ubuff, ucmd->num_data_pages, (int)(ubuff & ~PAGE_MASK), + ucmd->cmd ? ucmd->cmd->bufflen : -1); #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 8, 0) down_read(&tsk->mm->mmap_sem); @@ -1283,18 +1245,18 @@ out: return res; out_nomem: - if (ucmd->cmd != NULL) + if (ucmd->cmd) scst_set_busy(ucmd->cmd); /* fall through */ out_err: - if (ucmd->cmd != NULL) + if (ucmd->cmd) scst_set_cmd_abnormal_done_state(ucmd->cmd); goto out; out_unmap: PRINT_ERROR("Failed to get %d user pages (rc %d)", - ucmd->num_data_pages, rc); + ucmd->num_data_pages, rc); if (rc > 0) { for (i = 0; i < rc; i++) put_page(ucmd->data_pages[i]); @@ -1302,13 +1264,13 @@ out_unmap: kfree(ucmd->data_pages); ucmd->data_pages = NULL; res = -EFAULT; - if (ucmd->cmd != NULL) + if (ucmd->cmd) scst_set_cmd_error(ucmd->cmd, SCST_LOAD_SENSE(scst_sense_internal_failure)); goto out_err; } static int dev_user_process_reply_alloc(struct scst_user_cmd *ucmd, - struct scst_user_reply_cmd *reply) + struct scst_user_reply_cmd *reply) { int res = 0; struct scst_cmd *cmd = ucmd->cmd; @@ -1322,15 +1284,14 @@ static int dev_user_process_reply_alloc(struct scst_user_cmd *ucmd, if (ucmd->buff_cached) { if (unlikely((reply->alloc_reply.pbuf & ~PAGE_MASK) != 0)) { - PRINT_ERROR("Supplied pbuf %llx isn't " - "page aligned", - reply->alloc_reply.pbuf); + PRINT_ERROR("Supplied pbuf %llx isn't page aligned", + reply->alloc_reply.pbuf); goto out_hwerr; } pages = cmd->sg_cnt; - } else - pages = calc_num_pg(reply->alloc_reply.pbuf, - cmd->bufflen); + } else { + pages = calc_num_pg(reply->alloc_reply.pbuf, cmd->bufflen); + } res = dev_user_map_buf(ucmd, reply->alloc_reply.pbuf, pages); } else { scst_set_busy(ucmd->cmd); @@ -1340,7 +1301,7 @@ static int dev_user_process_reply_alloc(struct scst_user_cmd *ucmd, out_process: scst_process_active_cmd(cmd, false); - TRACE_DBG("%s", "ALLOC_MEM finished"); + TRACE_DBG("ALLOC_MEM finished"); TRACE_EXIT_RES(res); return res; @@ -1352,11 +1313,10 @@ out_hwerr: } static int dev_user_process_reply_parse(struct scst_user_cmd *ucmd, - struct scst_user_reply_cmd *reply) + struct scst_user_reply_cmd *reply) { int res = 0, rc; - struct scst_user_scsi_cmd_reply_parse *preply = - &reply->parse_reply; + struct scst_user_scsi_cmd_reply_parse *preply = &reply->parse_reply; struct scst_cmd *cmd = ucmd->cmd; TRACE_ENTRY(); @@ -1367,18 +1327,18 @@ static int dev_user_process_reply_parse(struct scst_user_cmd *ucmd, if (unlikely(preply->queue_type > SCST_CMD_QUEUE_ACA)) goto out_inval; - if (unlikely((preply->data_direction != SCST_DATA_WRITE) && - (preply->data_direction != SCST_DATA_READ) && - (preply->data_direction != SCST_DATA_BIDI) && - (preply->data_direction != SCST_DATA_NONE))) + if (unlikely(preply->data_direction != SCST_DATA_WRITE && + preply->data_direction != SCST_DATA_READ && + preply->data_direction != SCST_DATA_BIDI && + preply->data_direction != SCST_DATA_NONE)) goto out_inval; - if (unlikely((preply->data_direction != SCST_DATA_NONE) && - (preply->bufflen == 0))) + if (unlikely(preply->data_direction != SCST_DATA_NONE && + preply->bufflen == 0)) goto out_inval; - if (unlikely((preply->bufflen < 0) || (preply->out_bufflen < 0) || - (preply->data_len < 0) || (preply->lba < 0))) + if (unlikely(preply->bufflen < 0 || preply->out_bufflen < 0 || + preply->data_len < 0 || preply->lba < 0)) goto out_inval; if (unlikely(preply->cdb_len > cmd->cdb_len)) @@ -1387,11 +1347,10 @@ static int dev_user_process_reply_parse(struct scst_user_cmd *ucmd, if (!(preply->op_flags & SCST_INFO_VALID)) goto out_inval; - TRACE_DBG("ucmd %p, queue_type %x, data_direction, %x, lba %lld, " - "bufflen %d, data_len %lld, pbuf %llx, cdb_len %d, op_flags %x", - ucmd, preply->queue_type, preply->data_direction, - (long long)preply->lba, preply->bufflen, (long long)preply->data_len, - reply->alloc_reply.pbuf, preply->cdb_len, preply->op_flags); + TRACE_DBG("ucmd %p, queue_type %x, data_direction, %x, lba %lld, bufflen %d, data_len %lld, pbuf %llx, cdb_len %d, op_flags %x", + ucmd, preply->queue_type, preply->data_direction, + (long long)preply->lba, preply->bufflen, (long long)preply->data_len, + reply->alloc_reply.pbuf, preply->cdb_len, preply->op_flags); cmd->queue_type = preply->queue_type; cmd->data_direction = preply->data_direction; @@ -1404,7 +1363,7 @@ static int dev_user_process_reply_parse(struct scst_user_cmd *ucmd, cmd->op_flags = preply->op_flags; out_process: - TRACE_DBG("%s", "PARSE finished"); + TRACE_DBG("PARSE finished"); scst_process_active_cmd(cmd, false); @@ -1413,7 +1372,7 @@ out_process: out_inval: PRINT_ERROR("Invalid parse_reply parameters (LUN %lld, op %s, cmd %p)", - (unsigned long long)cmd->lun, scst_get_opcode_name(cmd), cmd); + (unsigned long long)cmd->lun, scst_get_opcode_name(cmd), cmd); PRINT_BUFFER("Invalid parse_reply", reply, sizeof(*reply)); scst_set_cmd_error(cmd, SCST_LOAD_SENSE(scst_sense_hardw_error)); res = -EINVAL; @@ -1428,7 +1387,7 @@ out_abnormal: out_status: TRACE_DBG("ucmd %p returned with error from user status %x", - ucmd, preply->status); + ucmd, preply->status); if (preply->sense_len != 0) { int sense_len; @@ -1440,8 +1399,8 @@ out_status: sense_len = min_t(int, cmd->sense_buflen, preply->sense_len); rc = copy_from_user(cmd->sense, - (void __user *)(unsigned long)preply->psense_buffer, - sense_len); + (void __user *)(unsigned long)preply->psense_buffer, + sense_len); if (rc != 0) { PRINT_ERROR("Failed to copy %d sense's bytes", rc); res = -EFAULT; @@ -1464,7 +1423,7 @@ static int dev_user_process_reply_on_free(struct scst_user_cmd *ucmd) dev_user_free_sgv(ucmd); ucmd_put(ucmd); - TRACE_DBG("%s", "ON_FREE_CMD finished"); + TRACE_DBG("ON_FREE_CMD finished"); TRACE_EXIT_RES(res); return res; } @@ -1479,13 +1438,13 @@ static int dev_user_process_reply_on_cache_free(struct scst_user_cmd *ucmd) ucmd_put(ucmd); - TRACE_MEM("%s", "ON_CACHED_MEM_FREE finished"); + TRACE_MEM("ON_CACHED_MEM_FREE finished"); TRACE_EXIT_RES(res); return res; } static int dev_user_process_reply_ext_copy_remap(struct scst_user_cmd *ucmd, - struct scst_user_reply_cmd *reply) + struct scst_user_reply_cmd *reply) { int res = 0, rc, count = 0, i, len; struct scst_user_ext_copy_reply_remap *rreply = &reply->remap_reply; @@ -1496,7 +1455,7 @@ static int dev_user_process_reply_ext_copy_remap(struct scst_user_cmd *ucmd, TRACE_ENTRY(); - if (unlikely((rreply->status != 0) || (rreply->sense_len != 0))) + if (unlikely(rreply->status != 0 || rreply->sense_len != 0)) goto out_status; if (rreply->remap_descriptors_len == 0) { @@ -1505,25 +1464,23 @@ static int dev_user_process_reply_ext_copy_remap(struct scst_user_cmd *ucmd, } if (unlikely(rreply->remap_descriptors_len > PAGE_SIZE)) { - PRINT_ERROR("Too many leftover REMAP descriptors (len %d, ucmd %p, " - "cmd %p)", rreply->remap_descriptors_len, ucmd, cmd); + PRINT_ERROR("Too many leftover REMAP descriptors (len %d, ucmd %p, cmd %p)", + rreply->remap_descriptors_len, ucmd, cmd); res = -EOVERFLOW; goto out_hw_err; } buf = kzalloc(rreply->remap_descriptors_len, GFP_KERNEL); - if (unlikely(buf == NULL)) { - PRINT_ERROR("Unable to alloc leftover remap descriptors buf " - "(size %d)", rreply->remap_descriptors_len); + if (unlikely(!buf)) { + PRINT_ERROR("Unable to alloc leftover remap descriptors buf (size %d)", + rreply->remap_descriptors_len); goto out_busy; } - rc = copy_from_user(buf, - (void __user *)(unsigned long)rreply->remap_descriptors, - rreply->remap_descriptors_len); + rc = copy_from_user(buf, (void __user *)(unsigned long)rreply->remap_descriptors, + rreply->remap_descriptors_len); if (unlikely(rc != 0)) { - PRINT_ERROR("Failed to copy %d leftover remap descriptors' " - "bytes", rc); + PRINT_ERROR("Failed to copy %d leftover remap descriptors bytes", rc); res = -EFAULT; goto out_free_buf; } @@ -1531,16 +1488,16 @@ static int dev_user_process_reply_ext_copy_remap(struct scst_user_cmd *ucmd, uleft = (struct scst_user_ext_copy_data_descr *)buf; count = rreply->remap_descriptors_len / sizeof(*uleft); if (unlikely((rreply->remap_descriptors_len % sizeof(*uleft)) != 0)) { - PRINT_ERROR("Invalid leftover remap descriptors (ucmd %p, " - "cmd %p, count %d)", ucmd, cmd, count); + PRINT_ERROR("Invalid leftover remap descriptors (ucmd %p, cmd %p, count %d)", + ucmd, cmd, count); res = -EINVAL; goto out_hw_err_free_buf; } left = kmalloc_array(count, sizeof(*left), GFP_KERNEL); - if (unlikely(left == NULL)) { - PRINT_ERROR("Unable to alloc leftover remap descriptors " - "(size %zd, count %d)", sizeof(*left) * count, count); + if (unlikely(!left)) { + PRINT_ERROR("Unable to alloc leftover remap descriptors (size %zd, count %d)", + sizeof(*left) * count, count); goto out_busy_free_buf; } @@ -1549,11 +1506,11 @@ static int dev_user_process_reply_ext_copy_remap(struct scst_user_cmd *ucmd, len = 0; for (i = 0; i < count; i++) { TRACE_DBG("src_lba %lld, dst_lba %lld, data_len %d (len %d)", - (long long)uleft[i].src_lba, (long long)uleft[i].dst_lba, - uleft[i].data_len, len); + (long long)uleft[i].src_lba, (long long)uleft[i].dst_lba, + uleft[i].data_len, len); if (unlikely(uleft[i].data_len == 0)) { - PRINT_ERROR("Invalid data descr %d len %d (cmd %p)", i, - uleft[i].data_len, cmd); + PRINT_ERROR("Invalid data descr %d len %d (cmd %p)", + i, uleft[i].data_len, cmd); res = -EINVAL; goto out_hw_err_free_buf; } @@ -1565,7 +1522,7 @@ static int dev_user_process_reply_ext_copy_remap(struct scst_user_cmd *ucmd, if (unlikely(len > scst_ext_copy_get_cur_seg_data_len(cmd))) { PRINT_ERROR("Invalid data descr len %d (cmd %p, seg descr len %d)", - len, cmd, scst_ext_copy_get_cur_seg_data_len(cmd)); + len, cmd, scst_ext_copy_get_cur_seg_data_len(cmd)); res = -EINVAL; goto out_hw_err_free_buf; } @@ -1603,7 +1560,7 @@ out_busy: out_status: TRACE_DBG("Remap finished with status %d (ucmd %p, cmd %p)", - rreply->status, ucmd, cmd); + rreply->status, ucmd, cmd); if (rreply->sense_len != 0) { int sense_len; @@ -1615,8 +1572,8 @@ out_status: sense_len = min_t(int, cmd->sense_buflen, rreply->sense_len); rc = copy_from_user(cmd->sense, - (void __user *)(unsigned long)rreply->psense_buffer, - sense_len); + (void __user *)(unsigned long)rreply->psense_buffer, + sense_len); if (rc != 0) { PRINT_ERROR("Failed to copy %d sense's bytes", rc); res = -EFAULT; @@ -1629,7 +1586,7 @@ out_status: } static int dev_user_process_ws_reply(struct scst_user_cmd *ucmd, - struct scst_user_scsi_cmd_reply_exec *ereply) + struct scst_user_scsi_cmd_reply_exec *ereply) { int res = 0, rc, count, i; struct scst_cmd *cmd = ucmd->cmd; @@ -1641,16 +1598,15 @@ static int dev_user_process_ws_reply(struct scst_user_cmd *ucmd, if (unlikely(cmd->cdb[0] != WRITE_SAME) && unlikely(cmd->cdb[0] != WRITE_SAME_16)) { - PRINT_ERROR("Request to process WRITE SAME for not WRITE SAME " - "CDB (ucmd %p, cmd %p, op %s)", ucmd, cmd, - scst_get_opcode_name(cmd)); + PRINT_ERROR("Request to process WRITE SAME for not WRITE SAME CDB (ucmd %p, cmd %p, op %s)", + ucmd, cmd, scst_get_opcode_name(cmd)); res = -EINVAL; goto out_hw_err; } if (unlikely(ereply->status != 0)) { - PRINT_ERROR("Request to process WRITE SAME with not 0 status " - "(ucmd %p, cmd %p, status %d)", ucmd, cmd, ereply->status); + PRINT_ERROR("Request to process WRITE SAME with not 0 status (ucmd %p, cmd %p, status %d)", + ucmd, cmd, ereply->status); res = -EINVAL; goto out_hw_err; } @@ -1661,22 +1617,21 @@ static int dev_user_process_ws_reply(struct scst_user_cmd *ucmd, } if (unlikely(ereply->ws_descriptors_len > PAGE_SIZE)) { - PRINT_ERROR("Too many WRITE SAME descriptors (len %d, ucmd %p, " - "cmd %p)", ereply->ws_descriptors_len, ucmd, cmd); + PRINT_ERROR("Too many WRITE SAME descriptors (len %d, ucmd %p, cmd %p)", + ereply->ws_descriptors_len, ucmd, cmd); res = -EOVERFLOW; goto out_hw_err; } buf = kzalloc(ereply->ws_descriptors_len, GFP_KERNEL); - if (unlikely(buf == NULL)) { + if (unlikely(!buf)) { PRINT_ERROR("Unable to alloc WS descriptors buf (size %d)", - ereply->ws_descriptors_len); + ereply->ws_descriptors_len); goto out_busy; } - rc = copy_from_user(buf, - (void __user *)(unsigned long)ereply->ws_descriptors, - ereply->ws_descriptors_len); + rc = copy_from_user(buf, (void __user *)(unsigned long)ereply->ws_descriptors, + ereply->ws_descriptors_len); if (unlikely(rc != 0)) { PRINT_ERROR("Failed to copy %d WS descriptors' bytes", rc); res = -EFAULT; @@ -1686,17 +1641,17 @@ static int dev_user_process_ws_reply(struct scst_user_cmd *ucmd, uwhere = (struct scst_user_data_descriptor *)buf; count = ereply->ws_descriptors_len / sizeof(*uwhere); if (unlikely((ereply->ws_descriptors_len % sizeof(*uwhere)) != 0) || - unlikely(uwhere[count-1].usdd_blocks != 0)) { + unlikely(uwhere[count - 1].usdd_blocks != 0)) { PRINT_ERROR("Invalid WS descriptors (ucmd %p, cmd %p)", - ucmd, cmd); + ucmd, cmd); res = -EINVAL; goto out_free_buf; } where = kmalloc_array(count, sizeof(*where), GFP_KERNEL); - if (unlikely(where == NULL)) { + if (unlikely(!where)) { PRINT_ERROR("Unable to alloc WS descriptors where (size %zd)", - sizeof(*where) * count); + sizeof(*where) * count); goto out_busy_free_buf; } @@ -1733,7 +1688,7 @@ out_busy: } static int dev_user_process_reply_exec(struct scst_user_cmd *ucmd, - struct scst_user_reply_cmd *reply) + struct scst_user_reply_cmd *reply) { int res = 0; struct scst_user_scsi_cmd_reply_exec *ereply = @@ -1750,14 +1705,12 @@ static int dev_user_process_reply_exec(struct scst_user_cmd *ucmd, } if (unlikely(ereply->resp_data_len > cmd->bufflen)) goto out_inval; - if (unlikely((cmd->data_direction != SCST_DATA_READ) && - (ereply->resp_data_len != 0))) + if (unlikely(cmd->data_direction != SCST_DATA_READ && ereply->resp_data_len != 0)) goto out_inval; } else if (ereply->reply_type == SCST_EXEC_REPLY_BACKGROUND) { if (unlikely(ucmd->background_exec)) goto out_inval; - if (unlikely((cmd->data_direction & SCST_DATA_READ) || - (cmd->resp_data_len != 0))) + if (unlikely((cmd->data_direction & SCST_DATA_READ) || cmd->resp_data_len != 0)) goto out_inval; /* * background_exec assignment must be after ucmd get. @@ -1771,11 +1724,12 @@ static int dev_user_process_reply_exec(struct scst_user_cmd *ucmd, } else if (ereply->reply_type == SCST_EXEC_REPLY_DO_WRITE_SAME) { res = dev_user_process_ws_reply(ucmd, ereply); goto out; - } else + } else { goto out_inval; + } - TRACE_DBG("ucmd %p, status %d, resp_data_len %d", ucmd, - ereply->status, ereply->resp_data_len); + TRACE_DBG("ucmd %p, status %d, resp_data_len %d", + ucmd, ereply->status, ereply->resp_data_len); cmd->atomic = 0; @@ -1787,22 +1741,24 @@ static int dev_user_process_reply_exec(struct scst_user_cmd *ucmd, goto out_busy; if (ucmd->buff_cached) { if (unlikely((ereply->pbuf & ~PAGE_MASK) != 0)) { - PRINT_ERROR("Supplied pbuf %llx isn't " - "page aligned", ereply->pbuf); + PRINT_ERROR("Supplied pbuf %llx isn't page aligned", + ereply->pbuf); goto out_intern_fail; } pages = cmd->sg_cnt; - } else + } else { pages = calc_num_pg(ereply->pbuf, cmd->bufflen); + } rc = dev_user_map_buf(ucmd, ereply->pbuf, pages); - if ((rc != 0) || (ucmd->ubuff == 0)) + if (rc != 0 || ucmd->ubuff == 0) goto out_compl; rc = dev_user_alloc_sg(ucmd, ucmd->buff_cached); if (unlikely(rc != 0)) goto out_busy; - } else + } else { dev_user_flush_dcache(ucmd); + } cmd->may_need_dma_sync = 1; scst_set_resp_data_len(cmd, ereply->resp_data_len); } else if (cmd->resp_data_len != ereply->resp_data_len) { @@ -1814,15 +1770,15 @@ static int dev_user_process_reply_exec(struct scst_user_cmd *ucmd, WARN_ON(ereply->resp_data_len != 0); cmd->resp_data_len = 0; cmd->resid_possible = 1; - } else + } else { scst_set_resp_data_len(cmd, ereply->resp_data_len); + } } #ifdef CONFIG_SCST_EXTRACHECKS - if (unlikely((ereply->resp_data_len == 0) && (ereply->pbuf != 0))) { - PRINT_WARNING("Supplied pbuf 0x%llx ignored, because " - "resp_data_len is 0. Memory leak? (op %s)", - (unsigned long long)ereply->pbuf, scst_get_opcode_name(cmd)); + if (unlikely(ereply->resp_data_len == 0 && ereply->pbuf != 0)) { + PRINT_WARNING("Supplied pbuf 0x%llx ignored, because resp_data_len is 0. Memory leak? (op %s)", + (unsigned long long)ereply->pbuf, scst_get_opcode_name(cmd)); } #endif @@ -1837,8 +1793,8 @@ static int dev_user_process_reply_exec(struct scst_user_cmd *ucmd, sense_len = min_t(int, cmd->sense_buflen, ereply->sense_len); rc = copy_from_user(cmd->sense, - (void __user *)(unsigned long)ereply->psense_buffer, - sense_len); + (void __user *)(unsigned long)ereply->psense_buffer, + sense_len); if (rc != 0) { PRINT_ERROR("Failed to copy %d sense's bytes", rc); res = -EFAULT; @@ -1853,13 +1809,13 @@ out_compl: /* !! At this point cmd can be already freed !! */ out: - TRACE_DBG("%s", "EXEC finished"); + TRACE_DBG("EXEC finished"); TRACE_EXIT_RES(res); return res; out_inval: PRINT_ERROR("Invalid exec_reply parameters (LUN %lld, op %s, cmd %p)", - (unsigned long long)cmd->lun, scst_get_opcode_name(cmd), cmd); + (unsigned long long)cmd->lun, scst_get_opcode_name(cmd), cmd); PRINT_BUFFER("Invalid exec_reply", reply, sizeof(*reply)); out_intern_fail: @@ -1880,8 +1836,7 @@ out_busy: goto out_compl; } -static int dev_user_process_reply(struct scst_user_dev *dev, - struct scst_user_reply_cmd *reply) +static int dev_user_process_reply(struct scst_user_dev *dev, struct scst_user_reply_cmd *reply) { int res = 0; struct scst_user_cmd *ucmd; @@ -1892,7 +1847,7 @@ static int dev_user_process_reply(struct scst_user_dev *dev, spin_lock_irq(&dev->udev_cmd_threads.cmd_list_lock); ucmd = __ucmd_find_hash(dev, reply->cmd_h); - if (unlikely(ucmd == NULL)) { + if (unlikely(!ucmd)) { TRACE_MGMT_DBG("cmd_h %d not found", reply->cmd_h); res = -ESRCH; goto out_unlock; @@ -1913,13 +1868,13 @@ static int dev_user_process_reply(struct scst_user_dev *dev, if (unlikely(ucmd->this_state_unjammed)) { TRACE_MGMT_DBG("Reply on unjammed ucmd %p, ignoring", - ucmd); + ucmd); goto out_unlock_put; } if (unlikely(!ucmd->sent_to_user)) { - TRACE_MGMT_DBG("Ucmd %p isn't in the sent to user " - "state %x", ucmd, ucmd->state); + TRACE_MGMT_DBG("Ucmd %p isn't in the sent to user state %x", + ucmd, ucmd->state); res = -EINVAL; goto out_unlock_put; } @@ -1964,9 +1919,9 @@ unlock_process: case UCMD_STATE_TM_RECEIVED_EXECING: case UCMD_STATE_TM_DONE_EXECING: res = dev_user_process_reply_tm_exec(ucmd, - (state == UCMD_STATE_TM_RECEIVED_EXECING) ? - SCST_MGMT_STATUS_RECEIVED_STAGE_COMPLETED : - reply->result); + state == UCMD_STATE_TM_RECEIVED_EXECING ? + SCST_MGMT_STATUS_RECEIVED_STAGE_COMPLETED : + reply->result); break; case UCMD_STATE_ATTACH_SESS: @@ -1987,10 +1942,9 @@ out: return res; out_wrong_state: - PRINT_ERROR("Command's %p subcode %x doesn't match internal " - "command's state %x or reply->subcode (%x) != ucmd->subcode " - "(%x)", ucmd, _IOC_NR(reply->subcode), ucmd->state, - reply->subcode, ucmd->user_cmd.subcode); + PRINT_ERROR("Command's %p subcode %x doesn't match internal command's state %x or reply->subcode (%x) != ucmd->subcode (%x)", + ucmd, _IOC_NR(reply->subcode), ucmd->state, + reply->subcode, ucmd->user_cmd.subcode); res = -EINVAL; dev_user_unjam_cmd(ucmd, 0, NULL); @@ -2065,7 +2019,7 @@ static int dev_user_get_ext_cdb(struct file *file, void __user *arg) spin_lock_irq(&dev->udev_cmd_threads.cmd_list_lock); ucmd = __ucmd_find_hash(dev, get.cmd_h); - if (unlikely(ucmd == NULL)) { + if (unlikely(!ucmd)) { TRACE_MGMT_DBG("cmd_h %d not found", get.cmd_h); res = -ESRCH; goto out_unlock; @@ -2077,20 +2031,20 @@ static int dev_user_get_ext_cdb(struct file *file, void __user *arg) goto out_unlock; } - if ((ucmd->cmd != NULL) && (ucmd->state <= UCMD_STATE_EXECING) && + if (ucmd->cmd && ucmd->state <= UCMD_STATE_EXECING && (ucmd->sent_to_user || ucmd->background_exec)) { cmd = ucmd->cmd; scst_cmd_get(cmd); } else { TRACE_MGMT_DBG("Invalid ucmd state %d for cmd_h %d", - ucmd->state, get.cmd_h); + ucmd->state, get.cmd_h); res = -EINVAL; goto out_unlock; } spin_unlock_irq(&dev->udev_cmd_threads.cmd_list_lock); - if (cmd == NULL) + if (!cmd) goto out_put; BUILD_BUG_ON(sizeof(cmd->cdb_buf) != SCST_MAX_CDB_SIZE); @@ -2101,10 +2055,10 @@ static int dev_user_get_ext_cdb(struct file *file, void __user *arg) EXTRACHECKS_BUG_ON(cmd->cdb_buf == cmd->cdb_buf); TRACE_BUFFER("EXT CDB", &cmd->cdb[sizeof(cmd->cdb_buf)], - cmd->cdb_len - sizeof(cmd->cdb_buf)); + cmd->cdb_len - sizeof(cmd->cdb_buf)); rc = copy_to_user((void __user *)(unsigned long)get.ext_cdb_buffer, - &cmd->cdb[sizeof(cmd->cdb_buf)], - cmd->cdb_len - sizeof(cmd->cdb_buf)); + &cmd->cdb[sizeof(cmd->cdb_buf)], + cmd->cdb_len - sizeof(cmd->cdb_buf)); if (unlikely(rc != 0)) { PRINT_ERROR("Failed to copy to user %d bytes", rc); res = -EFAULT; @@ -2135,9 +2089,8 @@ static int dev_user_process_scst_commands(struct scst_user_dev *dev) TRACE_ENTRY(); while (!list_empty(&dev->udev_cmd_threads.active_cmd_list)) { - struct scst_cmd *cmd = list_entry( - dev->udev_cmd_threads.active_cmd_list.next, typeof(*cmd), - cmd_list_entry); + struct scst_cmd *cmd = list_entry(dev->udev_cmd_threads.active_cmd_list.next, + typeof(*cmd), cmd_list_entry); TRACE_DBG("Deleting cmd %p from active cmd list", cmd); list_del(&cmd->cmd_list_entry); spin_unlock_irq(&dev->udev_cmd_threads.cmd_list_lock); @@ -2160,15 +2113,14 @@ static struct scst_user_cmd *__dev_user_get_next_cmd(struct list_head *cmd_list) again: u = NULL; if (!list_empty(cmd_list)) { - u = list_first_entry(cmd_list, typeof(*u), - ready_cmd_list_entry); + u = list_first_entry(cmd_list, typeof(*u), ready_cmd_list_entry); TRACE_DBG("Found ready ucmd %p", u); list_del(&u->ready_cmd_list_entry); EXTRACHECKS_BUG_ON(u->this_state_unjammed); - if (u->cmd != NULL) { + if (u->cmd) { if (u->state == UCMD_STATE_EXECING) { struct scst_user_dev *dev = u->dev; int rc; @@ -2186,8 +2138,7 @@ again: * !! At this point cmd & u can be !! * !! already freed !! */ - spin_lock_irq( - &dev->udev_cmd_threads.cmd_list_lock); + spin_lock_irq(&dev->udev_cmd_threads.cmd_list_lock); goto again; } @@ -2220,8 +2171,8 @@ static inline int test_cmd_threads(struct scst_user_dev *dev, bool can_block) } /* Called under udev_cmd_threads.cmd_list_lock and IRQ off */ -static int dev_user_get_next_cmd(struct scst_user_dev *dev, - struct scst_user_cmd **ucmd, bool can_block) +static int dev_user_get_next_cmd(struct scst_user_dev *dev, struct scst_user_cmd **ucmd, + bool can_block) { int res = 0; @@ -2237,7 +2188,7 @@ static int dev_user_get_next_cmd(struct scst_user_dev *dev, dev_user_process_scst_commands(dev); *ucmd = __dev_user_get_next_cmd(&dev->ready_cmd_list); - if (*ucmd != NULL) + if (*ucmd) break; if (!can_block || !dev->blocking || dev->cleanup_done) { @@ -2252,8 +2203,7 @@ static int dev_user_get_next_cmd(struct scst_user_dev *dev, } /* No locks */ -static int dev_user_get_cmd_to_user(struct scst_user_dev *dev, - void __user *where, bool can_block) +static int dev_user_get_cmd_to_user(struct scst_user_dev *dev, void __user *where, bool can_block) { int res; struct scst_user_cmd *ucmd; @@ -2281,17 +2231,16 @@ again: len = ucmd->user_cmd_payload_len; TRACE_DBG("ucmd %p (user_cmd %p), payload_len %d (len %d)", - ucmd, &ucmd->user_cmd, ucmd->user_cmd_payload_len, len); + ucmd, &ucmd->user_cmd, ucmd->user_cmd_payload_len, len); TRACE_BUFFER("UCMD", &ucmd->user_cmd, len); rc = copy_to_user(where, &ucmd->user_cmd, len); if (unlikely(rc != 0)) { - PRINT_ERROR("Copy to user failed (%d), requeuing ucmd " - "%p back to head of ready cmd list", res, ucmd); + PRINT_ERROR("Copy to user failed (%d), requeuing ucmd %p back to head of ready cmd list", + res, ucmd); res = -EFAULT; /* Requeue ucmd back */ spin_lock_irq(&dev->udev_cmd_threads.cmd_list_lock); - list_add(&ucmd->ready_cmd_list_entry, - &dev->ready_cmd_list); + list_add(&ucmd->ready_cmd_list_entry, &dev->ready_cmd_list); spin_unlock_irq(&dev->udev_cmd_threads.cmd_list_lock); } #ifdef CONFIG_SCST_EXTRACHECKS @@ -2299,8 +2248,9 @@ again: ucmd->user_cmd_payload_len = 0; #endif ucmd_put(ucmd); - } else + } else { spin_unlock_irq(&dev->udev_cmd_threads.cmd_list_lock); + } TRACE_EXIT_RES(res); return res; @@ -2330,7 +2280,7 @@ static int dev_user_reply_get_cmd(struct file *file, } TRACE_DBG("ureply %lld (dev %s)", (unsigned long long)ureply, - dev->name); + dev->name); if (ureply != 0) { void __user *u = (void __user *)ureply; @@ -2372,18 +2322,18 @@ static int dev_user_reply_get_multi(struct file *file, res = get_user(replies_cnt, &gm->replies_cnt); if (unlikely(res < 0)) { - PRINT_ERROR("%s", "Unable to get replies_cnt"); + PRINT_ERROR("Unable to get replies_cnt"); goto out; } res = get_user(cmds_cnt, &gm->cmds_cnt); if (unlikely(res < 0)) { - PRINT_ERROR("%s", "Unable to get cmds_cnt"); + PRINT_ERROR("Unable to get cmds_cnt"); goto out; } TRACE_DBG("replies %d, space %d (dev %s)", - replies_cnt, cmds_cnt, dev->name); + replies_cnt, cmds_cnt, dev->name); if (replies_cnt == 0) goto get_cmds; @@ -2391,7 +2341,7 @@ static int dev_user_reply_get_multi(struct file *file, /* get_user() can't be used with 64-bit values on x86_32 */ rc = copy_from_user(&replies, &gm->preplies, sizeof(replies)); if (unlikely(rc != 0)) { - PRINT_ERROR("%s", "Unable to get preply"); + PRINT_ERROR("Unable to get preply"); res = -EFAULT; goto out; } @@ -2424,7 +2374,7 @@ get_cmds: for (i = 0; i < cmds_cnt; i++) { res = dev_user_get_cmd_to_user(dev, &gm->cmds[i], i == 0); if (res != 0) { - if ((res == -EAGAIN) && (i > 0)) + if ((res == -EAGAIN) && i > 0) res = 0; break; } @@ -2452,8 +2402,7 @@ out_part_replies_done: goto out; } -static long dev_user_ioctl(struct file *file, unsigned int cmd, - unsigned long arg) +static long dev_user_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { long res, rc; @@ -2461,22 +2410,22 @@ static long dev_user_ioctl(struct file *file, unsigned int cmd, switch (cmd) { case SCST_USER_REPLY_AND_GET_CMD: - TRACE_DBG("%s", "REPLY_AND_GET_CMD"); + TRACE_DBG("REPLY_AND_GET_CMD"); res = dev_user_reply_get_cmd(file, (void __user *)arg); break; case SCST_USER_REPLY_CMD: - TRACE_DBG("%s", "REPLY_CMD"); + TRACE_DBG("REPLY_CMD"); res = dev_user_reply_cmd(file, (void __user *)arg); break; case SCST_USER_REPLY_AND_GET_MULTI: - TRACE_DBG("%s", "REPLY_AND_GET_MULTI"); + TRACE_DBG("REPLY_AND_GET_MULTI"); res = dev_user_reply_get_multi(file, (void __user *)arg); break; case SCST_USER_GET_EXTENDED_CDB: - TRACE_DBG("%s", "GET_EXTENDED_CDB"); + TRACE_DBG("GET_EXTENDED_CDB"); res = dev_user_get_ext_cdb(file, (void __user *)arg); break; @@ -2484,14 +2433,13 @@ static long dev_user_ioctl(struct file *file, unsigned int cmd, { struct scst_user_dev_desc *dev_desc; - TRACE_DBG("%s", "REGISTER_DEVICE"); + TRACE_DBG("REGISTER_DEVICE"); dev_desc = kmalloc(sizeof(*dev_desc), GFP_KERNEL); - if (dev_desc == NULL) { + if (!dev_desc) { res = -ENOMEM; goto out; } - rc = copy_from_user(dev_desc, (void __user *)arg, - sizeof(*dev_desc)); + rc = copy_from_user(dev_desc, (void __user *)arg, sizeof(*dev_desc)); if (rc != 0) { PRINT_ERROR("Failed to copy %ld user's bytes", rc); res = -EFAULT; @@ -2499,20 +2447,20 @@ static long dev_user_ioctl(struct file *file, unsigned int cmd, goto out; } TRACE_BUFFER("dev_desc", dev_desc, sizeof(*dev_desc)); - dev_desc->name[sizeof(dev_desc->name)-1] = '\0'; - dev_desc->sgv_name[sizeof(dev_desc->sgv_name)-1] = '\0'; + dev_desc->name[sizeof(dev_desc->name) - 1] = '\0'; + dev_desc->sgv_name[sizeof(dev_desc->sgv_name) - 1] = '\0'; res = dev_user_register_dev(file, dev_desc); kfree(dev_desc); break; } case SCST_USER_UNREGISTER_DEVICE: - TRACE_DBG("%s", "UNREGISTER_DEVICE"); + TRACE_DBG("UNREGISTER_DEVICE"); res = dev_user_unregister_dev(file); break; case SCST_USER_FLUSH_CACHE: - TRACE_DBG("%s", "FLUSH_CACHE"); + TRACE_DBG("FLUSH_CACHE"); res = dev_user_flush_cache(file); break; @@ -2520,7 +2468,7 @@ static long dev_user_ioctl(struct file *file, unsigned int cmd, { struct scst_user_opt opt; - TRACE_DBG("%s", "SET_OPTIONS"); + TRACE_DBG("SET_OPTIONS"); rc = copy_from_user(&opt, (void __user *)arg, sizeof(opt)); if (rc != 0) { PRINT_ERROR("Failed to copy %ld user's bytes", rc); @@ -2533,17 +2481,17 @@ static long dev_user_ioctl(struct file *file, unsigned int cmd, } case SCST_USER_GET_OPTIONS: - TRACE_DBG("%s", "GET_OPTIONS"); + TRACE_DBG("GET_OPTIONS"); res = dev_user_get_opt(file, (void __user *)arg); break; case SCST_USER_DEVICE_CAPACITY_CHANGED: - TRACE_DBG("%s", "CAPACITY_CHANGED"); + TRACE_DBG("CAPACITY_CHANGED"); res = dev_user_capacity_changed(file); break; case SCST_USER_PREALLOC_BUFFER: - TRACE_DBG("%s", "PREALLOC_BUFFER"); + TRACE_DBG("PREALLOC_BUFFER"); res = dev_user_prealloc_buffer(file, (void __user *)arg); break; @@ -2604,8 +2552,7 @@ out: * Called under udev_cmd_threads.cmd_list_lock, but can drop it inside, * then reacquire. */ -static void dev_user_unjam_cmd(struct scst_user_cmd *ucmd, int busy, - unsigned long *flags) +static void dev_user_unjam_cmd(struct scst_user_cmd *ucmd, int busy, unsigned long *flags) __releases(&dev->udev_cmd_threads.cmd_list_lock) __acquires(&dev->udev_cmd_threads.cmd_list_lock) { @@ -2617,8 +2564,8 @@ static void dev_user_unjam_cmd(struct scst_user_cmd *ucmd, int busy, if (ucmd->this_state_unjammed) goto out; - TRACE_MGMT_DBG("Unjamming ucmd %p (busy %d, state %x)", ucmd, busy, - state); + TRACE_MGMT_DBG("Unjamming ucmd %p (busy %d, state %x)", + ucmd, busy, state); ucmd->jammed = 1; ucmd->this_state_unjammed = 1; @@ -2627,26 +2574,25 @@ static void dev_user_unjam_cmd(struct scst_user_cmd *ucmd, int busy, switch (state) { case UCMD_STATE_PARSING: case UCMD_STATE_BUF_ALLOCING: - if (test_bit(SCST_CMD_ABORTED, &ucmd->cmd->cmd_flags)) + if (test_bit(SCST_CMD_ABORTED, &ucmd->cmd->cmd_flags)) { ucmd->aborted = 1; - else { + } else { if (busy) scst_set_busy(ucmd->cmd); else scst_set_cmd_error(ucmd->cmd, - SCST_LOAD_SENSE(scst_sense_lun_not_supported)); + SCST_LOAD_SENSE(scst_sense_lun_not_supported)); } scst_set_cmd_abnormal_done_state(ucmd->cmd); TRACE_MGMT_DBG("Adding ucmd %p to active list", ucmd); - list_add(&ucmd->cmd->cmd_list_entry, - &ucmd->cmd->cmd_threads->active_cmd_list); + list_add(&ucmd->cmd->cmd_list_entry, &ucmd->cmd->cmd_threads->active_cmd_list); wake_up(&ucmd->cmd->cmd_threads->cmd_list_waitQ); break; case UCMD_STATE_EXECING: case UCMD_STATE_EXT_COPY_REMAPPING: - if (flags != NULL) + if (flags) spin_unlock_irqrestore(&dev->udev_cmd_threads.cmd_list_lock, *flags); else @@ -2654,26 +2600,26 @@ static void dev_user_unjam_cmd(struct scst_user_cmd *ucmd, int busy, TRACE_MGMT_DBG("EXEC: unjamming ucmd %p", ucmd); - if (test_bit(SCST_CMD_ABORTED, &ucmd->cmd->cmd_flags)) + if (test_bit(SCST_CMD_ABORTED, &ucmd->cmd->cmd_flags)) { ucmd->aborted = 1; - else { + } else { if (busy) scst_set_busy(ucmd->cmd); else scst_set_cmd_error(ucmd->cmd, - SCST_LOAD_SENSE(scst_sense_lun_not_supported)); + SCST_LOAD_SENSE(scst_sense_lun_not_supported)); } - if (state == UCMD_STATE_EXECING) + if (state == UCMD_STATE_EXECING) { ucmd->cmd->scst_cmd_done(ucmd->cmd, SCST_CMD_STATE_DEFAULT, - SCST_CONTEXT_THREAD); - else { + SCST_CONTEXT_THREAD); + } else { sBUG_ON(state != UCMD_STATE_EXT_COPY_REMAPPING); scst_ext_copy_remap_done(ucmd->cmd, NULL, 0); } /* !! At this point cmd and ucmd can be already freed !! */ - if (flags != NULL) + if (flags) spin_lock_irqsave(&dev->udev_cmd_threads.cmd_list_lock, *flags); else @@ -2686,7 +2632,7 @@ static void dev_user_unjam_cmd(struct scst_user_cmd *ucmd, int busy, case UCMD_STATE_TM_DONE_EXECING: case UCMD_STATE_ATTACH_SESS: case UCMD_STATE_DETACH_SESS: - if (flags != NULL) + if (flags) spin_unlock_irqrestore(&dev->udev_cmd_threads.cmd_list_lock, *flags); else @@ -2704,9 +2650,9 @@ static void dev_user_unjam_cmd(struct scst_user_cmd *ucmd, int busy, case UCMD_STATE_TM_RECEIVED_EXECING: case UCMD_STATE_TM_DONE_EXECING: dev_user_process_reply_tm_exec(ucmd, - (state == UCMD_STATE_TM_RECEIVED_EXECING) ? - SCST_MGMT_STATUS_RECEIVED_STAGE_COMPLETED : - SCST_MGMT_STATUS_FAILED); + state == UCMD_STATE_TM_RECEIVED_EXECING ? + SCST_MGMT_STATUS_RECEIVED_STAGE_COMPLETED : + SCST_MGMT_STATUS_FAILED); break; case UCMD_STATE_ATTACH_SESS: @@ -2715,9 +2661,8 @@ static void dev_user_unjam_cmd(struct scst_user_cmd *ucmd, int busy, break; } - if (flags != NULL) - spin_lock_irqsave(&dev->udev_cmd_threads.cmd_list_lock, - *flags); + if (flags) + spin_lock_irqsave(&dev->udev_cmd_threads.cmd_list_lock, *flags); else spin_lock_irq(&dev->udev_cmd_threads.cmd_list_lock); break; @@ -2730,7 +2675,6 @@ static void dev_user_unjam_cmd(struct scst_user_cmd *ucmd, int busy, out: TRACE_EXIT(); - return; } static int dev_user_unjam_dev(struct scst_user_dev *dev) @@ -2762,8 +2706,8 @@ repeat: if (ucmd_get_check(ucmd)) continue; - TRACE_MGMT_DBG("ucmd %p, state %x, scst_cmd %p", ucmd, - ucmd->state, ucmd->cmd); + TRACE_MGMT_DBG("ucmd %p, state %x, scst_cmd %p", + ucmd, ucmd->state, ucmd->cmd); dev_user_unjam_cmd(ucmd, 0, NULL); @@ -2784,15 +2728,14 @@ repeat: return res; } -static int dev_user_process_reply_tm_exec(struct scst_user_cmd *ucmd, - int status) +static int dev_user_process_reply_tm_exec(struct scst_user_cmd *ucmd, int status) { int res = 0; TRACE_ENTRY(); - TRACE_MGMT_DBG("TM reply (ucmd %p, fn %d, status %d)", ucmd, - ucmd->user_cmd.tm_cmd.fn, status); + TRACE_MGMT_DBG("TM reply (ucmd %p, fn %d, status %d)", + ucmd, ucmd->user_cmd.tm_cmd.fn, status); if (status == SCST_MGMT_STATUS_TASK_NOT_EXIST) { /* @@ -2823,7 +2766,7 @@ static void dev_user_abort_ready_commands(struct scst_user_dev *dev) spin_lock_irqsave(&dev->udev_cmd_threads.cmd_list_lock, flags); again: list_for_each_entry(ucmd, &dev->ready_cmd_list, ready_cmd_list_entry) { - if ((ucmd->cmd != NULL) && !ucmd->seen_by_user && + if (ucmd->cmd && !ucmd->seen_by_user && test_bit(SCST_CMD_ABORTED, &ucmd->cmd->cmd_flags)) { switch (ucmd->state) { case UCMD_STATE_PARSING: @@ -2840,12 +2783,11 @@ again: spin_unlock_irqrestore(&dev->udev_cmd_threads.cmd_list_lock, flags); TRACE_EXIT(); - return; } /* Can be called under some spinlock and IRQs off */ -static void __dev_user_task_mgmt_fn(struct scst_mgmt_cmd *mcmd, - struct scst_tgt_dev *tgt_dev, bool done) +static void __dev_user_task_mgmt_fn(struct scst_mgmt_cmd *mcmd, struct scst_tgt_dev *tgt_dev, + bool done) { struct scst_user_cmd *ucmd; struct scst_user_dev *dev = tgt_dev->dev->dh_priv; @@ -2895,10 +2837,10 @@ static void __dev_user_task_mgmt_fn(struct scst_mgmt_cmd *mcmd, dev_user_abort_ready_commands(dev); /* We can't afford missing TM command due to memory shortage */ - ucmd = dev_user_alloc_ucmd(dev, GFP_ATOMIC|__GFP_NOFAIL); - if (ucmd == NULL) { - PRINT_CRIT_ERROR("Unable to allocate TM %d message " - "(dev %s)", mcmd->fn, dev->name); + ucmd = dev_user_alloc_ucmd(dev, GFP_ATOMIC | __GFP_NOFAIL); + if (!ucmd) { + PRINT_CRIT_ERROR("Unable to allocate TM %d message (dev %s)", + mcmd->fn, dev->name); goto out; } @@ -2915,16 +2857,15 @@ static void __dev_user_task_mgmt_fn(struct scst_mgmt_cmd *mcmd, ucmd->user_cmd.tm_cmd.cmd_sn = mcmd->cmd_sn; ucmd->user_cmd.tm_cmd.cmd_sn_set = mcmd->cmd_sn_set; - if (mcmd->cmd_to_abort != NULL) { + if (mcmd->cmd_to_abort) { ucmd_to_abort = mcmd->cmd_to_abort->dh_priv; - if (ucmd_to_abort != NULL) + if (ucmd_to_abort) ucmd->user_cmd.tm_cmd.cmd_h_to_abort = ucmd_to_abort->h; } - TRACE_MGMT_DBG("Preparing TM ucmd %p (h %d, fn %d, cmd_to_abort %p, " - "ucmd_to_abort %p, cmd_h_to_abort %d, mcmd %p)", ucmd, ucmd->h, - mcmd->fn, mcmd->cmd_to_abort, ucmd_to_abort, - ucmd->user_cmd.tm_cmd.cmd_h_to_abort, mcmd); + TRACE_MGMT_DBG("Preparing TM ucmd %p (h %d, fn %d, cmd_to_abort %p, ucmd_to_abort %p, cmd_h_to_abort %d, mcmd %p)", + ucmd, ucmd->h, mcmd->fn, mcmd->cmd_to_abort, ucmd_to_abort, + ucmd->user_cmd.tm_cmd.cmd_h_to_abort, mcmd); ucmd->mcmd = mcmd; if (done) @@ -2938,25 +2879,21 @@ static void __dev_user_task_mgmt_fn(struct scst_mgmt_cmd *mcmd, out: TRACE_EXIT(); - return; } static void dev_user_task_mgmt_fn_received(struct scst_mgmt_cmd *mcmd, - struct scst_tgt_dev *tgt_dev) + struct scst_tgt_dev *tgt_dev) { TRACE_ENTRY(); __dev_user_task_mgmt_fn(mcmd, tgt_dev, false); TRACE_EXIT(); - return; } -static void dev_user_task_mgmt_fn_done(struct scst_mgmt_cmd *mcmd, - struct scst_tgt_dev *tgt_dev) +static void dev_user_task_mgmt_fn_done(struct scst_mgmt_cmd *mcmd, struct scst_tgt_dev *tgt_dev) { TRACE_ENTRY(); __dev_user_task_mgmt_fn(mcmd, tgt_dev, true); TRACE_EXIT(); - return; } static int dev_user_attach(struct scst_device *sdev) @@ -2974,7 +2911,7 @@ static int dev_user_attach(struct scst_device *sdev) } } spin_unlock(&dev_list_lock); - if (dev == NULL) { + if (!dev) { PRINT_ERROR("Device %s not found", sdev->virt_name); res = -EINVAL; goto out; @@ -3020,7 +2957,7 @@ static int dev_user_attach(struct scst_device *sdev) dev->sdev = sdev; PRINT_INFO("Attached user space virtual device \"%s\"", - dev->name); + dev->name); out: TRACE_EXIT(); @@ -3036,14 +2973,13 @@ static void dev_user_detach(struct scst_device *sdev) TRACE_DBG("virt_id %d", sdev->virt_id); PRINT_INFO("Detached user space virtual device \"%s\"", - dev->name); + dev->name); /* dev will be freed by the caller */ sdev->dh_priv = NULL; dev->sdev = NULL; TRACE_EXIT(); - return; } static int dev_user_process_reply_sess(struct scst_user_cmd *ucmd, int status) @@ -3058,14 +2994,15 @@ static int dev_user_process_reply_sess(struct scst_user_cmd *ucmd, int status) spin_lock_irqsave(&ucmd->dev->udev_cmd_threads.cmd_list_lock, flags); if (ucmd->state == UCMD_STATE_ATTACH_SESS) { - TRACE_MGMT_DBG("%s", "ATTACH_SESS finished"); + TRACE_MGMT_DBG("ATTACH_SESS finished"); ucmd->result = status; } else if (ucmd->state == UCMD_STATE_DETACH_SESS) { - TRACE_MGMT_DBG("%s", "DETACH_SESS finished"); - } else + TRACE_MGMT_DBG("DETACH_SESS finished"); + } else { sBUG(); + } - if (ucmd->cmpl != NULL) + if (ucmd->cmpl) complete_all(ucmd->cmpl); spin_unlock_irqrestore(&ucmd->dev->udev_cmd_threads.cmd_list_lock, flags); @@ -3100,7 +3037,7 @@ static int dev_user_attach_tgt(struct scst_tgt_dev *tgt_dev) tgt_dev->dh_priv = dev->pool; ucmd = dev_user_alloc_ucmd(dev, GFP_KERNEL); - if (ucmd == NULL) + if (!ucmd) goto out_nomem; ucmd->cmpl = &cmpl; @@ -3113,25 +3050,24 @@ static int dev_user_attach_tgt(struct scst_tgt_dev *tgt_dev) ucmd->user_cmd.sess.lun = (uint64_t)tgt_dev->lun; ucmd->user_cmd.sess.threads_num = tgt_dev->tgtt->threads_num; ucmd->user_cmd.sess.rd_only = tgt_dev->tgt_dev_rd_only; - if (tgtt->get_phys_transport_version != NULL) + if (tgtt->get_phys_transport_version) ucmd->user_cmd.sess.phys_transport_version = tgtt->get_phys_transport_version(tgt); - if (tgtt->get_scsi_transport_version != NULL) + if (tgtt->get_scsi_transport_version) ucmd->user_cmd.sess.scsi_transport_version = tgtt->get_scsi_transport_version(tgt); strscpy(ucmd->user_cmd.sess.initiator_name, tgt_dev->sess->initiator_name, - sizeof(ucmd->user_cmd.sess.initiator_name)-1); + sizeof(ucmd->user_cmd.sess.initiator_name) - 1); strscpy(ucmd->user_cmd.sess.target_name, tgt_dev->sess->tgt->tgt_name, - sizeof(ucmd->user_cmd.sess.target_name)-1); + sizeof(ucmd->user_cmd.sess.target_name) - 1); - TRACE_MGMT_DBG("Preparing ATTACH_SESS %p (h %d, sess_h %llx, LUN %llx, " - "threads_num %d, rd_only %d, initiator %s, target %s)", - ucmd, ucmd->h, ucmd->user_cmd.sess.sess_h, - ucmd->user_cmd.sess.lun, ucmd->user_cmd.sess.threads_num, - ucmd->user_cmd.sess.rd_only, ucmd->user_cmd.sess.initiator_name, - ucmd->user_cmd.sess.target_name); + TRACE_MGMT_DBG("Preparing ATTACH_SESS %p (h %d, sess_h %llx, LUN %llx, threads_num %d, rd_only %d, initiator %s, target %s)", + ucmd, ucmd->h, ucmd->user_cmd.sess.sess_h, + ucmd->user_cmd.sess.lun, ucmd->user_cmd.sess.threads_num, + ucmd->user_cmd.sess.rd_only, ucmd->user_cmd.sess.initiator_name, + ucmd->user_cmd.sess.target_name); ucmd->state = UCMD_STATE_ATTACH_SESS; @@ -3140,10 +3076,10 @@ static int dev_user_attach_tgt(struct scst_tgt_dev *tgt_dev) dev_user_add_to_ready(ucmd); rc = wait_for_completion_timeout(ucmd->cmpl, DEV_USER_ATTACH_TIMEOUT); - if (rc > 0) + if (rc > 0) { res = ucmd->result; - else { - PRINT_ERROR("%s", "ATTACH_SESS command timeout"); + } else { + PRINT_ERROR("ATTACH_SESS command timeout"); res = -EFAULT; } @@ -3175,15 +3111,15 @@ static void dev_user_detach_tgt(struct scst_tgt_dev *tgt_dev) * We can't miss detach command due to memory shortage, because it might * lead to a memory leak in the user space handler. */ - ucmd = dev_user_alloc_ucmd(dev, GFP_KERNEL|__GFP_NOFAIL); - if (ucmd == NULL) { - PRINT_CRIT_ERROR("Unable to allocate DETACH_SESS message " - "(dev %s)", dev->name); + ucmd = dev_user_alloc_ucmd(dev, GFP_KERNEL | __GFP_NOFAIL); + if (!ucmd) { + PRINT_CRIT_ERROR("Unable to allocate DETACH_SESS message (dev %s)", + dev->name); goto out; } - TRACE_MGMT_DBG("Preparing DETACH_SESS %p (h %d, sess_h %llx)", ucmd, - ucmd->h, ucmd->user_cmd.sess.sess_h); + TRACE_MGMT_DBG("Preparing DETACH_SESS %p (h %d, sess_h %llx)", + ucmd, ucmd->h, ucmd->user_cmd.sess.sess_h); ucmd->user_cmd_payload_len = offsetof(struct scst_user_get_cmd, sess) + sizeof(ucmd->user_cmd.sess); @@ -3197,7 +3133,6 @@ static void dev_user_detach_tgt(struct scst_tgt_dev *tgt_dev) out: TRACE_EXIT(); - return; } /* No locks are needed, but the activity must be suspended */ @@ -3248,8 +3183,8 @@ static void dev_user_setup_functions(struct scst_user_dev *dev) break; default: - PRINT_INFO("Unknown SCSI type %x, using PARSE_CALL " - "for it", dev->devtype.type); + PRINT_INFO("Unknown SCSI type %x, using PARSE_CALL for it", + dev->devtype.type); dev->parse_type = SCST_USER_PARSE_CALL; break; } @@ -3259,7 +3194,6 @@ static void dev_user_setup_functions(struct scst_user_dev *dev) } TRACE_EXIT(); - return; } static int dev_user_check_version(const struct scst_user_dev_desc *dev_desc) @@ -3267,15 +3201,13 @@ static int dev_user_check_version(const struct scst_user_dev_desc *dev_desc) char str[sizeof(DEV_USER_VERSION) > 20 ? sizeof(DEV_USER_VERSION) : 20]; int res = 0, rc; - rc = copy_from_user(str, - (void __user *)(unsigned long)dev_desc->license_str, - sizeof(str)); + rc = copy_from_user(str, (void __user *)(unsigned long)dev_desc->license_str, sizeof(str)); if (rc != 0) { - PRINT_ERROR("%s", "Unable to get license string"); + PRINT_ERROR("Unable to get license string"); res = -EFAULT; goto out; } - str[sizeof(str)-1] = '\0'; + str[sizeof(str) - 1] = '\0'; if ((strcmp(str, "GPL") != 0) && (strcmp(str, "GPL v2") != 0) && @@ -3283,28 +3215,25 @@ static int dev_user_check_version(const struct scst_user_dev_desc *dev_desc) (strcmp(str, "Dual MIT/GPL") != 0) && (strcmp(str, "Dual MPL/GPL") != 0)) { /* ->name already 0-terminated in dev_user_ioctl() */ - PRINT_ERROR("Unsupported license of user device %s (%s). " - "Ask license@scst-tgt.com for more info.", - dev_desc->name, str); + PRINT_ERROR("Unsupported license of user device %s (%s). Ask license@scst-tgt.com for more info.", + dev_desc->name, str); res = -EPERM; goto out; } - rc = copy_from_user(str, - (void __user *)(unsigned long)dev_desc->version_str, - sizeof(str)); + rc = copy_from_user(str, (void __user *)(unsigned long)dev_desc->version_str, + sizeof(str)); if (rc != 0) { - PRINT_ERROR("%s", "Unable to get version string"); + PRINT_ERROR("Unable to get version string"); res = -EFAULT; goto out; } - str[sizeof(str)-1] = '\0'; + str[sizeof(str) - 1] = '\0'; if (strcmp(str, DEV_USER_VERSION) != 0) { /* ->name already 0-terminated in dev_user_ioctl() */ - PRINT_ERROR("Incorrect version of user device %s (%s). " - "Expected: %s", dev_desc->name, str, - DEV_USER_VERSION); + PRINT_ERROR("Incorrect version of user device %s (%s). Expected: %s", + dev_desc->name, str, DEV_USER_VERSION); res = -EINVAL; goto out; } @@ -3313,8 +3242,7 @@ out: return res; } -static int dev_user_register_dev(struct file *file, - const struct scst_user_dev_desc *dev_desc) +static int dev_user_register_dev(struct file *file, const struct scst_user_dev_desc *dev_desc) { int res, i; struct scst_user_dev *dev, *d; @@ -3347,69 +3275,66 @@ static int dev_user_register_dev(struct file *file, } if (!try_module_get(THIS_MODULE)) { - PRINT_ERROR("%s", "Fail to get module"); + PRINT_ERROR("Fail to get module"); res = -ETXTBSY; goto out; } dev = kmem_cache_zalloc(user_dev_cachep, GFP_KERNEL); - if (dev == NULL) { + if (!dev) { res = -ENOMEM; goto out_put; } INIT_LIST_HEAD(&dev->ready_cmd_list); if (file->f_flags & O_NONBLOCK) { - TRACE_DBG("%s", "Non-blocking operations"); + TRACE_DBG("Non-blocking operations"); dev->blocking = 0; - } else + } else { dev->blocking = 1; + } for (i = 0; i < ARRAY_SIZE(dev->ucmd_hash); i++) INIT_LIST_HEAD(&dev->ucmd_hash[i]); scst_init_threads(&dev->udev_cmd_threads); - strscpy(dev->name, dev_desc->name, sizeof(dev->name)-1); + strscpy(dev->name, dev_desc->name, sizeof(dev->name) - 1); scst_init_mem_lim(&dev->udev_mem_lim); scnprintf(dev->devtype.name, sizeof(dev->devtype.name), "%s", - (dev_desc->sgv_name[0] == '\0') ? dev->name : - dev_desc->sgv_name); + dev_desc->sgv_name[0] == '\0' ? dev->name : dev_desc->sgv_name); dev->pool = sgv_pool_create(dev->devtype.name, sgv_no_clustering, - dev_desc->sgv_single_alloc_pages, - dev_desc->sgv_shared, - dev_desc->sgv_purge_interval * HZ); - if (dev->pool == NULL) { + dev_desc->sgv_single_alloc_pages, + dev_desc->sgv_shared, + dev_desc->sgv_purge_interval * HZ); + if (!dev->pool) { res = -ENOMEM; goto out_deinit_threads; } - sgv_pool_set_allocator(dev->pool, dev_user_alloc_pages, - dev_user_free_sg_entries); + sgv_pool_set_allocator(dev->pool, dev_user_alloc_pages, dev_user_free_sg_entries); if (!dev_desc->sgv_disable_clustered_pool) { scnprintf(dev->devtype.name, sizeof(dev->devtype.name), - "%s-clust", - (dev_desc->sgv_name[0] == '\0') ? dev->name : - dev_desc->sgv_name); + "%s-clust", + dev_desc->sgv_name[0] == '\0' ? dev->name : dev_desc->sgv_name); dev->pool_clust = sgv_pool_create(dev->devtype.name, - sgv_tail_clustering, - dev_desc->sgv_single_alloc_pages, - dev_desc->sgv_shared, - dev_desc->sgv_purge_interval * HZ); - if (dev->pool_clust == NULL) { + sgv_tail_clustering, + dev_desc->sgv_single_alloc_pages, + dev_desc->sgv_shared, + dev_desc->sgv_purge_interval * HZ); + if (!dev->pool_clust) { res = -ENOMEM; goto out_free0; } sgv_pool_set_allocator(dev->pool_clust, dev_user_alloc_pages, - dev_user_free_sg_entries); + dev_user_free_sg_entries); } else { dev->pool_clust = dev->pool; sgv_pool_get(dev->pool_clust); } - scnprintf(dev->devtype.name, sizeof(dev->devtype.name), "%s", - dev->name); + scnprintf(dev->devtype.name, sizeof(dev->devtype.name), "%s", dev->name); dev->devtype.type = dev_desc->type; dev->devtype.threads_num = -1; dev->devtype.parse_atomic = 1; @@ -3441,7 +3366,7 @@ static int dev_user_register_dev(struct file *file, list_for_each_entry(d, &dev_list, dev_list_entry) { if (strcmp(d->name, dev->name) == 0) { PRINT_ERROR("Device %s already exist", - dev->name); + dev->name); res = -EEXIST; spin_unlock(&dev_list_lock); goto out_free; @@ -3463,9 +3388,9 @@ static int dev_user_register_dev(struct file *file, } spin_lock(&dev_list_lock); - if (file->private_data != NULL) { + if (file->private_data) { spin_unlock(&dev_list_lock); - PRINT_ERROR("%s", "Device already registered"); + PRINT_ERROR("Device already registered"); res = -EINVAL; goto out_unreg_drv; } @@ -3517,8 +3442,7 @@ static int dev_user_unregister_dev(struct file *file) if (unlikely(res != 0)) goto out; - PRINT_WARNING("SCST_USER_UNREGISTER_DEVICE is obsolete and NOOP. " - "Closing fd should be used instead."); + PRINT_WARNING("SCST_USER_UNREGISTER_DEVICE is obsolete and NOOP. Closing fd should be used instead."); /* For backward compatibility unblock possibly blocked sync threads */ dev->blocking = 0; @@ -3600,14 +3524,14 @@ static int dev_user_prealloc_buffer(struct file *file, void __user *arg) } TRACE_MEM("Prealloc buffer with size %dKB for dev %s", - pre.in.bufflen / 1024, dev->name); + pre.in.bufflen / 1024, dev->name); TRACE_BUFFER("Input param", &pre.in, sizeof(pre.in)); pbuf = pre.in.pbuf; bufflen = pre.in.bufflen; ucmd = dev_user_alloc_ucmd(dev, GFP_KERNEL); - if (ucmd == NULL) { + if (!ucmd) { res = -ENOMEM; goto out; } @@ -3633,13 +3557,12 @@ static int dev_user_prealloc_buffer(struct file *file, void __user *arg) pool = dev->pool; sg = sgv_pool_alloc(pool, bufflen, GFP_KERNEL, SGV_POOL_ALLOC_GET_NEW, - &sg_cnt, &ucmd->sgv, &dev->udev_mem_lim, ucmd); - if (sg != NULL) { + &sg_cnt, &ucmd->sgv, &dev->udev_mem_lim, ucmd); + if (sg) { struct scst_user_cmd *buf_ucmd = sgv_get_priv(ucmd->sgv); - TRACE_MEM("Buf ucmd %p (sg_cnt %d, last seg len %d, " - "bufflen %d)", buf_ucmd, sg_cnt, - sg[sg_cnt-1].length, bufflen); + TRACE_MEM("Buf ucmd %p (sg_cnt %d, last seg len %d, bufflen %d)", + buf_ucmd, sg_cnt, sg[sg_cnt - 1].length, bufflen); EXTRACHECKS_BUG_ON(ucmd != buf_ucmd); @@ -3667,53 +3590,44 @@ out: return res; } -static int __dev_user_set_opt(struct scst_user_dev *dev, - const struct scst_user_opt *opt) +static int __dev_user_set_opt(struct scst_user_dev *dev, const struct scst_user_opt *opt) { int res = 0; TRACE_ENTRY(); - TRACE_DBG("dev %s, parse_type %x, on_free_cmd_type %x, " - "memory_reuse_type %x, partial_transfers_type %x, " - "partial_len %d, opt->ext_copy_remap_supported %d", - dev->name, opt->parse_type, opt->on_free_cmd_type, - opt->memory_reuse_type, opt->partial_transfers_type, - opt->partial_len, opt->ext_copy_remap_supported); + TRACE_DBG("dev %s, parse_type %x, on_free_cmd_type %x, memory_reuse_type %x, partial_transfers_type %x, partial_len %d, opt->ext_copy_remap_supported %d", + dev->name, opt->parse_type, opt->on_free_cmd_type, + opt->memory_reuse_type, opt->partial_transfers_type, + opt->partial_len, opt->ext_copy_remap_supported); if (opt->parse_type > SCST_USER_MAX_PARSE_OPT || opt->on_free_cmd_type > SCST_USER_MAX_ON_FREE_CMD_OPT || opt->memory_reuse_type > SCST_USER_MAX_MEM_REUSE_OPT || opt->partial_transfers_type > SCST_USER_MAX_PARTIAL_TRANSFERS_OPT) { - PRINT_ERROR("%s", "Invalid option"); + PRINT_ERROR("Invalid option"); res = -EINVAL; goto out; } - if (((opt->tst != SCST_TST_0_SINGLE_TASK_SET) && - (opt->tst != SCST_TST_1_SEP_TASK_SETS)) || - (opt->tmf_only > 1) || - ((opt->queue_alg != SCST_QUEUE_ALG_0_RESTRICTED_REORDER) && - (opt->queue_alg != SCST_QUEUE_ALG_1_UNRESTRICTED_REORDER)) || - ((opt->qerr == SCST_QERR_2_RESERVED) || - (opt->qerr > SCST_QERR_3_ABORT_THIS_NEXUS_ONLY)) || - (opt->swp > 1) || (opt->tas > 1) || (opt->has_own_order_mgmt > 1) || - (opt->d_sense > 1) || (opt->ext_copy_remap_supported > 1)) { - PRINT_ERROR("Invalid SCSI option (tst %x, tmf_only %x, " - "queue_alg %x, qerr %x, swp %x, tas %x, d_sense %d, " - "has_own_order_mgmt %x, ext_copy_remap_supported %d)", - opt->tst, opt->tmf_only, opt->queue_alg, opt->qerr, - opt->swp, opt->tas, opt->d_sense, opt->has_own_order_mgmt, - opt->ext_copy_remap_supported); + if ((opt->tst != SCST_TST_0_SINGLE_TASK_SET && opt->tst != SCST_TST_1_SEP_TASK_SETS) || + opt->tmf_only > 1 || + (opt->queue_alg != SCST_QUEUE_ALG_0_RESTRICTED_REORDER && + opt->queue_alg != SCST_QUEUE_ALG_1_UNRESTRICTED_REORDER) || + (opt->qerr == SCST_QERR_2_RESERVED || opt->qerr > SCST_QERR_3_ABORT_THIS_NEXUS_ONLY) || + opt->swp > 1 || opt->tas > 1 || opt->has_own_order_mgmt > 1 || opt->d_sense > 1 || + opt->ext_copy_remap_supported > 1) { + PRINT_ERROR("Invalid SCSI option (tst %x, tmf_only %x, queue_alg %x, qerr %x, swp %x, tas %x, d_sense %d, has_own_order_mgmt %x, ext_copy_remap_supported %d)", + opt->tst, opt->tmf_only, opt->queue_alg, opt->qerr, + opt->swp, opt->tas, opt->d_sense, opt->has_own_order_mgmt, + opt->ext_copy_remap_supported); res = -EINVAL; goto out; } #if 1 - if ((dev->tst != opt->tst) && (dev->sdev != NULL) && - !list_empty(&dev->sdev->dev_tgt_dev_list)) { - PRINT_ERROR("On the fly setting of TST not supported. " - "See comment in struct scst_device."); + if (dev->tst != opt->tst && dev->sdev && !list_empty(&dev->sdev->dev_tgt_dev_list)) { + PRINT_ERROR("On the fly setting of TST not supported. See comment in struct scst_device."); res = -EINVAL; goto out; } @@ -3734,7 +3648,8 @@ static int __dev_user_set_opt(struct scst_user_dev *dev, dev->d_sense = opt->d_sense; dev->has_own_order_mgmt = opt->has_own_order_mgmt; dev->ext_copy_remap_supported = opt->ext_copy_remap_supported; - if (dev->sdev != NULL) { + + if (dev->sdev) { dev->sdev->tst = opt->tst; dev->sdev->tmf_only = opt->tmf_only; dev->sdev->queue_alg = opt->queue_alg; @@ -3806,12 +3721,10 @@ static int dev_user_get_opt(struct file *file, void __user *arg) opt.has_own_order_mgmt = dev->has_own_order_mgmt; opt.ext_copy_remap_supported = dev->ext_copy_remap_supported; - TRACE_DBG("dev %s, parse_type %x, on_free_cmd_type %x, " - "memory_reuse_type %x, partial_transfers_type %x, " - "partial_len %d, ext_copy_remap_supported %d", dev->name, - opt.parse_type, opt.on_free_cmd_type, opt.memory_reuse_type, - opt.partial_transfers_type, opt.partial_len, - opt.ext_copy_remap_supported); + TRACE_DBG("dev %s, parse_type %x, on_free_cmd_type %x, memory_reuse_type %x, partial_transfers_type %x, partial_len %d, ext_copy_remap_supported %d", + dev->name, opt.parse_type, opt.on_free_cmd_type, opt.memory_reuse_type, + opt.partial_transfers_type, opt.partial_len, + opt.ext_copy_remap_supported); rc = copy_to_user(arg, &opt, sizeof(opt)); if (unlikely(rc != 0)) { @@ -3895,7 +3808,7 @@ static int dev_user_release(struct inode *inode, struct file *file) TRACE_ENTRY(); dev = file->private_data; - if (dev == NULL) + if (!dev) goto out; file->private_data = NULL; @@ -3903,9 +3816,8 @@ static int dev_user_release(struct inode *inode, struct file *file) t = kthread_run(__dev_user_release, dev, "scst_usr_released"); if (IS_ERR(t)) { - PRINT_CRIT_ERROR("kthread_run() failed (%ld), releasing device " - "%p directly. If you have several devices under load " - "it might deadlock!", PTR_ERR(t), dev); + PRINT_CRIT_ERROR("kthread_run() failed (%ld), releasing device %p directly. If you have several devices under load it might deadlock!", + PTR_ERR(t), dev); __dev_user_release(dev); } @@ -3924,8 +3836,8 @@ static void dev_user_check_lost_ucmds(struct scst_user_dev *dev) struct scst_user_cmd *ucmd2, *tmp; list_for_each_entry_safe(ucmd2, tmp, head, hash_list_entry) { - PRINT_ERROR("Lost ucmd %p (state %x, ref %d)", ucmd2, - ucmd2->state, atomic_read(&ucmd2->ucmd_ref)); + PRINT_ERROR("Lost ucmd %p (state %x, ref %d)", + ucmd2, ucmd2->state, atomic_read(&ucmd2->ucmd_ref)); ucmd_put(ucmd2); } } @@ -3952,7 +3864,7 @@ static int dev_user_process_cleanup(struct scst_user_dev *dev) TRACE_DBG("Cleanuping dev %p", dev); rc1 = dev_user_unjam_dev(dev); - if ((rc1 == 0) && (rc == -EAGAIN) && dev->cleanup_done) + if (rc1 == 0 && rc == -EAGAIN && dev->cleanup_done) break; spin_lock_irq(&dev->udev_cmd_threads.cmd_list_lock); @@ -3982,9 +3894,8 @@ out: return res; } - -static ssize_t dev_user_sysfs_commands_show(struct kobject *kobj, - struct kobj_attribute *attr, char *buf) +static ssize_t dev_user_sysfs_commands_show(struct kobject *kobj, struct kobj_attribute *attr, + char *buf) { int pos = 0, ppos, i; struct scst_device *dev; @@ -4004,15 +3915,13 @@ static ssize_t dev_user_sysfs_commands_show(struct kobject *kobj, list_for_each_entry(ucmd, head, hash_list_entry) { ppos = pos; pos += scnprintf(&buf[pos], - SCST_SYSFS_BLOCK_SIZE - pos, - "ucmd %p (state %x, ref %d), " - "sent_to_user %d, seen_by_user %d, " - "aborted %d, jammed %d, scst_cmd %p\n", - ucmd, ucmd->state, - atomic_read(&ucmd->ucmd_ref), - ucmd->sent_to_user, ucmd->seen_by_user, - ucmd->aborted, ucmd->jammed, ucmd->cmd); - if (pos >= SCST_SYSFS_BLOCK_SIZE-1) { + SCST_SYSFS_BLOCK_SIZE - pos, + "ucmd %p (state %x, ref %d), sent_to_user %d, seen_by_user %d, aborted %d, jammed %d, scst_cmd %p\n", + ucmd, ucmd->state, + atomic_read(&ucmd->ucmd_ref), + ucmd->sent_to_user, ucmd->seen_by_user, + ucmd->aborted, ucmd->jammed, ucmd->cmd); + if (pos >= SCST_SYSFS_BLOCK_SIZE - 1) { ppos += scnprintf(&buf[ppos], SCST_SYSFS_BLOCK_SIZE - ppos, "...\n"); pos = ppos; @@ -4026,11 +3935,9 @@ static ssize_t dev_user_sysfs_commands_show(struct kobject *kobj, return pos; } - static inline int test_cleanup_list(void) { - int res = !list_empty(&cleanup_list) || - unlikely(kthread_should_stop()); + int res = !list_empty(&cleanup_list) || unlikely(kthread_should_stop()); return res; } @@ -4060,8 +3967,8 @@ static int dev_user_cleanup_thread(void *arg) while (!list_empty(&cleanup_list)) { int rc; - dev = list_first_entry(&cleanup_list, - typeof(*dev), cleanup_list_entry); + dev = list_first_entry(&cleanup_list, typeof(*dev), + cleanup_list_entry); list_del(&dev->cleanup_list_entry); spin_unlock(&cleanup_lock); @@ -4069,8 +3976,7 @@ static int dev_user_cleanup_thread(void *arg) spin_lock(&cleanup_lock); if (rc != 0) - list_add_tail(&dev->cleanup_list_entry, - &cl_devs); + list_add_tail(&dev->cleanup_list_entry, &cl_devs); } if (list_empty(&cl_devs)) @@ -4081,10 +3987,8 @@ static int dev_user_cleanup_thread(void *arg) spin_lock(&cleanup_lock); while (!list_empty(&cl_devs)) { - dev = list_first_entry(&cl_devs, typeof(*dev), - cleanup_list_entry); - list_move_tail(&dev->cleanup_list_entry, - &cleanup_list); + dev = list_first_entry(&cl_devs, typeof(*dev), cleanup_list_entry); + list_move_tail(&dev->cleanup_list_entry, &cleanup_list); } } } @@ -4117,24 +4021,21 @@ static int __init init_scst_user(void) #ifndef INSIDE_KERNEL_TREE #if defined(CONFIG_HIGHMEM4G) || defined(CONFIG_HIGHMEM64G) - PRINT_ERROR("%s", "HIGHMEM kernel configurations are not supported. " - "Consider changing VMSPLIT option or use a 64-bit " - "configuration instead. See README file for details."); + PRINT_ERROR("HIGHMEM kernel configurations are not supported. Consider changing VMSPLIT option or use a 64-bit configuration instead. See README file for details."); res = -EINVAL; goto out; #endif #endif - user_dev_cachep = KMEM_CACHE(scst_user_dev, - SCST_SLAB_FLAGS|SLAB_HWCACHE_ALIGN); - if (user_dev_cachep == NULL) { + user_dev_cachep = KMEM_CACHE(scst_user_dev, SCST_SLAB_FLAGS | SLAB_HWCACHE_ALIGN); + if (!user_dev_cachep) { res = -ENOMEM; goto out; } - user_cmd_cachep = KMEM_CACHE_USERCOPY(scst_user_cmd, - SCST_SLAB_FLAGS | SLAB_HWCACHE_ALIGN, user_cmd); - if (user_cmd_cachep == NULL) { + user_cmd_cachep = KMEM_CACHE_USERCOPY(scst_user_cmd, SCST_SLAB_FLAGS | SLAB_HWCACHE_ALIGN, + user_cmd); + if (!user_cmd_cachep) { res = -ENOMEM; goto out_dev_cache; } @@ -4153,8 +4054,7 @@ static int __init init_scst_user(void) dev_user_sysfs_class = class_create(DEV_USER_NAME); #endif if (IS_ERR(dev_user_sysfs_class)) { - PRINT_ERROR("%s", "Unable create sysfs class for SCST user " - "space handler"); + PRINT_ERROR("Unable create sysfs class for SCST user space handler"); res = PTR_ERR(dev_user_sysfs_class); goto out_unreg; } @@ -4166,17 +4066,14 @@ static int __init init_scst_user(void) goto out_class; } - dev = device_create(dev_user_sysfs_class, NULL, - MKDEV(dev_user_major, 0), - NULL, - DEV_USER_NAME); + dev = device_create(dev_user_sysfs_class, NULL, MKDEV(dev_user_major, 0), NULL, + DEV_USER_NAME); if (IS_ERR(dev)) { res = PTR_ERR(dev); goto out_chrdev; } - cleanup_thread = kthread_run(dev_user_cleanup_thread, NULL, - "scst_usr_cleanupd"); + cleanup_thread = kthread_run(dev_user_cleanup_thread, NULL, "scst_usr_cleanupd"); if (IS_ERR(cleanup_thread)) { res = PTR_ERR(cleanup_thread); PRINT_ERROR("kthread_create() failed: %d", res); @@ -4196,7 +4093,6 @@ out_chrdev: out_class: class_destroy(dev_user_sysfs_class); - out_unreg: scst_unregister_dev_driver(&dev_user_devtype); @@ -4228,7 +4124,6 @@ static void __exit exit_scst_user(void) kmem_cache_destroy(user_dev_cachep); TRACE_EXIT(); - return; } module_init(init_scst_user);