Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

memstick/ms_block: Add check for alloc_ordered_workqueue

As the alloc_ordered_workqueue may return NULL pointer, it should be better
to add check for the return value. Moreover, the msb->io_queue should be
freed if error occurs later.

Fixes: 0ab30494bc4f ("memstick: add support for legacy memorysticks")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Link: https://lore.kernel.org/r/20221126012558.34374-1-jiasheng@iscas.ac.cn
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>

authored by

Jiasheng Jiang and committed by
Ulf Hansson
4f431a04 5c5301a1

+8 -1
+8 -1
drivers/memstick/core/ms_block.c
··· 2116 2116 dbg("Set total disk size to %lu sectors", capacity); 2117 2117 2118 2118 msb->io_queue = alloc_ordered_workqueue("ms_block", WQ_MEM_RECLAIM); 2119 + if (!msb->io_queue) { 2120 + rc = -ENOMEM; 2121 + goto out_cleanup_disk; 2122 + } 2123 + 2119 2124 INIT_WORK(&msb->io_work, msb_io_work); 2120 2125 sg_init_table(msb->prealloc_sg, MS_BLOCK_MAX_SEGS+1); 2121 2126 ··· 2130 2125 msb_start(card); 2131 2126 rc = device_add_disk(&card->dev, msb->disk, NULL); 2132 2127 if (rc) 2133 - goto out_cleanup_disk; 2128 + goto out_destroy_workqueue; 2134 2129 dbg("Disk added"); 2135 2130 return 0; 2136 2131 2132 + out_destroy_workqueue: 2133 + destroy_workqueue(msb->io_queue); 2137 2134 out_cleanup_disk: 2138 2135 put_disk(msb->disk); 2139 2136 out_free_tag_set: