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

Configure Feed

Select the types of activity you want to include in your feed.

block: null_blk: Cleanup device creation and deletion

Introduce the null_create_dev() and null_destroy_dev() helper functions
to respectivel create nullb devices on modprobe and destroy them on
rmmod. The null_destroy_dev() helper avoids duplicated code in the
null_init() and null_exit() functions for deleting devices.

Signed-off-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Link: https://lore.kernel.org/r/20220420005718.3780004-3-damien.lemoal@opensource.wdc.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Damien Le Moal and committed by
Jens Axboe
b3a0a73e 525323d2

+30 -18
+30 -18
drivers/block/null_blk/main.c
··· 2086 2086 return rv; 2087 2087 } 2088 2088 2089 + static int null_create_dev(void) 2090 + { 2091 + struct nullb_device *dev; 2092 + int ret; 2093 + 2094 + dev = null_alloc_dev(); 2095 + if (!dev) 2096 + return -ENOMEM; 2097 + 2098 + ret = null_add_dev(dev); 2099 + if (ret) { 2100 + null_free_dev(dev); 2101 + return ret; 2102 + } 2103 + 2104 + return 0; 2105 + } 2106 + 2107 + static void null_destroy_dev(struct nullb *nullb) 2108 + { 2109 + struct nullb_device *dev = nullb->dev; 2110 + 2111 + null_del_dev(nullb); 2112 + null_free_dev(dev); 2113 + } 2114 + 2089 2115 static int __init null_init(void) 2090 2116 { 2091 2117 int ret = 0; 2092 2118 unsigned int i; 2093 2119 struct nullb *nullb; 2094 - struct nullb_device *dev; 2095 2120 2096 2121 if (g_bs > PAGE_SIZE) { 2097 2122 pr_warn("invalid block size\n"); ··· 2174 2149 } 2175 2150 2176 2151 for (i = 0; i < nr_devices; i++) { 2177 - dev = null_alloc_dev(); 2178 - if (!dev) { 2179 - ret = -ENOMEM; 2152 + ret = null_create_dev(); 2153 + if (ret) 2180 2154 goto err_dev; 2181 - } 2182 - ret = null_add_dev(dev); 2183 - if (ret) { 2184 - null_free_dev(dev); 2185 - goto err_dev; 2186 - } 2187 2155 } 2188 2156 2189 2157 pr_info("module loaded\n"); ··· 2185 2167 err_dev: 2186 2168 while (!list_empty(&nullb_list)) { 2187 2169 nullb = list_entry(nullb_list.next, struct nullb, list); 2188 - dev = nullb->dev; 2189 - null_del_dev(nullb); 2190 - null_free_dev(dev); 2170 + null_destroy_dev(nullb); 2191 2171 } 2192 2172 unregister_blkdev(null_major, "nullb"); 2193 2173 err_conf: ··· 2206 2190 2207 2191 mutex_lock(&lock); 2208 2192 while (!list_empty(&nullb_list)) { 2209 - struct nullb_device *dev; 2210 - 2211 2193 nullb = list_entry(nullb_list.next, struct nullb, list); 2212 - dev = nullb->dev; 2213 - null_del_dev(nullb); 2214 - null_free_dev(dev); 2194 + null_destroy_dev(nullb); 2215 2195 } 2216 2196 mutex_unlock(&lock); 2217 2197