diff options
author | Artem Bityutskiy <Artem.Bityutskiy@nokia.com> | 2007-12-17 08:48:49 -0500 |
---|---|---|
committer | Artem Bityutskiy <Artem.Bityutskiy@nokia.com> | 2007-12-26 12:15:15 -0500 |
commit | db6e5770ef0ab351a403ac26e1ab1309e58f15d7 (patch) | |
tree | 29048da47919be2b8f54bf408fe900c042c9868a | |
parent | 35ad5fb76cc0a08e14068408b064103439feee36 (diff) |
UBI: simplify error handling
If we fail halfway through sysfs file creation, we may just call
sysfs remove function and it will delete all the files we created.
For non-existing files it will also be OK - the remove functions
just return -ENOENT.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
-rw-r--r-- | drivers/mtd/ubi/build.c | 52 |
1 files changed, 12 insertions, 40 deletions
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c index 61225f493f6d..6ad291b33a1e 100644 --- a/drivers/mtd/ubi/build.c +++ b/drivers/mtd/ubi/build.c | |||
@@ -159,64 +159,36 @@ static int ubi_sysfs_init(struct ubi_device *ubi) | |||
159 | sprintf(&ubi->dev.bus_id[0], UBI_NAME_STR"%d", ubi->ubi_num); | 159 | sprintf(&ubi->dev.bus_id[0], UBI_NAME_STR"%d", ubi->ubi_num); |
160 | err = device_register(&ubi->dev); | 160 | err = device_register(&ubi->dev); |
161 | if (err) | 161 | if (err) |
162 | goto out; | 162 | return err; |
163 | 163 | ||
164 | err = device_create_file(&ubi->dev, &dev_eraseblock_size); | 164 | err = device_create_file(&ubi->dev, &dev_eraseblock_size); |
165 | if (err) | 165 | if (err) |
166 | goto out_unregister; | 166 | return err; |
167 | err = device_create_file(&ubi->dev, &dev_avail_eraseblocks); | 167 | err = device_create_file(&ubi->dev, &dev_avail_eraseblocks); |
168 | if (err) | 168 | if (err) |
169 | goto out_eraseblock_size; | 169 | return err; |
170 | err = device_create_file(&ubi->dev, &dev_total_eraseblocks); | 170 | err = device_create_file(&ubi->dev, &dev_total_eraseblocks); |
171 | if (err) | 171 | if (err) |
172 | goto out_avail_eraseblocks; | 172 | return err; |
173 | err = device_create_file(&ubi->dev, &dev_volumes_count); | 173 | err = device_create_file(&ubi->dev, &dev_volumes_count); |
174 | if (err) | 174 | if (err) |
175 | goto out_total_eraseblocks; | 175 | return err; |
176 | err = device_create_file(&ubi->dev, &dev_max_ec); | 176 | err = device_create_file(&ubi->dev, &dev_max_ec); |
177 | if (err) | 177 | if (err) |
178 | goto out_volumes_count; | 178 | return err; |
179 | err = device_create_file(&ubi->dev, &dev_reserved_for_bad); | 179 | err = device_create_file(&ubi->dev, &dev_reserved_for_bad); |
180 | if (err) | 180 | if (err) |
181 | goto out_volumes_max_ec; | 181 | return err; |
182 | err = device_create_file(&ubi->dev, &dev_bad_peb_count); | 182 | err = device_create_file(&ubi->dev, &dev_bad_peb_count); |
183 | if (err) | 183 | if (err) |
184 | goto out_reserved_for_bad; | 184 | return err; |
185 | err = device_create_file(&ubi->dev, &dev_max_vol_count); | 185 | err = device_create_file(&ubi->dev, &dev_max_vol_count); |
186 | if (err) | 186 | if (err) |
187 | goto out_bad_peb_count; | 187 | return err; |
188 | err = device_create_file(&ubi->dev, &dev_min_io_size); | 188 | err = device_create_file(&ubi->dev, &dev_min_io_size); |
189 | if (err) | 189 | if (err) |
190 | goto out_max_vol_count; | 190 | return err; |
191 | err = device_create_file(&ubi->dev, &dev_bgt_enabled); | 191 | err = device_create_file(&ubi->dev, &dev_bgt_enabled); |
192 | if (err) | ||
193 | goto out_min_io_size; | ||
194 | |||
195 | return 0; | ||
196 | |||
197 | out_min_io_size: | ||
198 | device_remove_file(&ubi->dev, &dev_min_io_size); | ||
199 | out_max_vol_count: | ||
200 | device_remove_file(&ubi->dev, &dev_max_vol_count); | ||
201 | out_bad_peb_count: | ||
202 | device_remove_file(&ubi->dev, &dev_bad_peb_count); | ||
203 | out_reserved_for_bad: | ||
204 | device_remove_file(&ubi->dev, &dev_reserved_for_bad); | ||
205 | out_volumes_max_ec: | ||
206 | device_remove_file(&ubi->dev, &dev_max_ec); | ||
207 | out_volumes_count: | ||
208 | device_remove_file(&ubi->dev, &dev_volumes_count); | ||
209 | out_total_eraseblocks: | ||
210 | device_remove_file(&ubi->dev, &dev_total_eraseblocks); | ||
211 | out_avail_eraseblocks: | ||
212 | device_remove_file(&ubi->dev, &dev_avail_eraseblocks); | ||
213 | out_eraseblock_size: | ||
214 | device_remove_file(&ubi->dev, &dev_eraseblock_size); | ||
215 | out_unregister: | ||
216 | device_unregister(&ubi->dev); | ||
217 | out: | ||
218 | ubi_err("failed to initialize sysfs for %s, error %d", | ||
219 | ubi->ubi_name, err); | ||
220 | return err; | 192 | return err; |
221 | } | 193 | } |
222 | 194 | ||
@@ -296,7 +268,7 @@ static int uif_init(struct ubi_device *ubi) | |||
296 | 268 | ||
297 | err = ubi_sysfs_init(ubi); | 269 | err = ubi_sysfs_init(ubi); |
298 | if (err) | 270 | if (err) |
299 | goto out_cdev; | 271 | goto out_sysfs; |
300 | 272 | ||
301 | for (i = 0; i < ubi->vtbl_slots; i++) | 273 | for (i = 0; i < ubi->vtbl_slots; i++) |
302 | if (ubi->volumes[i]) { | 274 | if (ubi->volumes[i]) { |
@@ -311,8 +283,8 @@ static int uif_init(struct ubi_device *ubi) | |||
311 | 283 | ||
312 | out_volumes: | 284 | out_volumes: |
313 | kill_volumes(ubi); | 285 | kill_volumes(ubi); |
286 | out_sysfs: | ||
314 | ubi_sysfs_close(ubi); | 287 | ubi_sysfs_close(ubi); |
315 | out_cdev: | ||
316 | cdev_del(&ubi->cdev); | 288 | cdev_del(&ubi->cdev); |
317 | out_unreg: | 289 | out_unreg: |
318 | unregister_chrdev_region(ubi->cdev.dev, ubi->vtbl_slots + 1); | 290 | unregister_chrdev_region(ubi->cdev.dev, ubi->vtbl_slots + 1); |