[bug report] memstick/ms_block: Add check for alloc_ordered_workqueue

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello Jiasheng Jiang,

The patch cb713d1f69ae: "memstick/ms_block: Add check for
alloc_ordered_workqueue" from Nov 22, 2022, leads to the following
Smatch static checker warnings:

    drivers/memstick/core/ms_block.c:2143 msb_init_disk()
    warn: 'msb->io_queue' from alloc_workqueue() not released on lines: 2143.

    drivers/memstick/core/ms_block.c:2120 msb_init_disk()
    warn: missing error code here? 'alloc_workqueue()' failed. 'rc' = '0'

drivers/memstick/core/ms_block.c
    2078 static int msb_init_disk(struct memstick_dev *card)
    2079 {
    2080         struct msb_data *msb = memstick_get_drvdata(card);
    2081         int rc;
    2082         unsigned long capacity;
    2083 
    2084         mutex_lock(&msb_disk_lock);
    2085         msb->disk_id = idr_alloc(&msb_disk_idr, card, 0, 256, GFP_KERNEL);
    2086         mutex_unlock(&msb_disk_lock);
    2087 
    2088         if (msb->disk_id  < 0)
    2089                 return msb->disk_id;
    2090 
    2091         rc = blk_mq_alloc_sq_tag_set(&msb->tag_set, &msb_mq_ops, 2,
    2092                                      BLK_MQ_F_SHOULD_MERGE);
    2093         if (rc)
    2094                 goto out_release_id;
    2095 
    2096         msb->disk = blk_mq_alloc_disk(&msb->tag_set, card);
    2097         if (IS_ERR(msb->disk)) {
    2098                 rc = PTR_ERR(msb->disk);
    2099                 goto out_free_tag_set;
    2100         }
    2101         msb->queue = msb->disk->queue;
    2102 
    2103         blk_queue_max_hw_sectors(msb->queue, MS_BLOCK_MAX_PAGES);
    2104         blk_queue_max_segments(msb->queue, MS_BLOCK_MAX_SEGS);
    2105         blk_queue_max_segment_size(msb->queue,
    2106                                    MS_BLOCK_MAX_PAGES * msb->page_size);
    2107         blk_queue_logical_block_size(msb->queue, msb->page_size);
    2108 
    2109         sprintf(msb->disk->disk_name, "msblk%d", msb->disk_id);
    2110         msb->disk->fops = &msb_bdops;
    2111         msb->disk->private_data = msb;
    2112 
    2113         capacity = msb->pages_in_block * msb->logical_block_count;
    2114         capacity *= (msb->page_size / 512);
    2115         set_capacity(msb->disk, capacity);
    2116         dbg("Set total disk size to %lu sectors", capacity);
    2117 
    2118         msb->io_queue = alloc_ordered_workqueue("ms_block", WQ_MEM_RECLAIM);
    2119         if (!msb->io_queue)
--> 2120                 goto out_cleanup_disk;

Set error code.  Also this ->io_queue doesn't seem to be freed when we
unload the driver.

    2121 
    2122         INIT_WORK(&msb->io_work, msb_io_work);
    2123         sg_init_table(msb->prealloc_sg, MS_BLOCK_MAX_SEGS+1);
    2124 
    2125         if (msb->read_only)
    2126                 set_disk_ro(msb->disk, 1);
    2127 
    2128         msb_start(card);
    2129         rc = device_add_disk(&card->dev, msb->disk, NULL);
    2130         if (rc)
    2131                 goto out_cleanup_disk;

Needs to free msb->io_queue.

    2132         dbg("Disk added");
    2133         return 0;
    2134 
    2135 out_cleanup_disk:
    2136         put_disk(msb->disk);
    2137 out_free_tag_set:
    2138         blk_mq_free_tag_set(&msb->tag_set);
    2139 out_release_id:
    2140         mutex_lock(&msb_disk_lock);
    2141         idr_remove(&msb_disk_idr, msb->disk_id);
    2142         mutex_unlock(&msb_disk_lock);
    2143         return rc;
    2144 }

regards,
dan carpenter



[Index of Archives]     [Linux Memonry Technology]     [Linux USB Devel]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux