.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * Copyright (c) International Business Machines Corp., 2006 |
---|
3 | | - * |
---|
4 | | - * This program is free software; you can redistribute it and/or modify |
---|
5 | | - * it under the terms of the GNU General Public License as published by |
---|
6 | | - * the Free Software Foundation; either version 2 of the License, or |
---|
7 | | - * (at your option) any later version. |
---|
8 | | - * |
---|
9 | | - * This program is distributed in the hope that it will be useful, |
---|
10 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
---|
12 | | - * the GNU General Public License for more details. |
---|
13 | | - * |
---|
14 | | - * You should have received a copy of the GNU General Public License |
---|
15 | | - * along with this program; if not, write to the Free Software |
---|
16 | | - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
17 | 4 | * |
---|
18 | 5 | * Author: Artem Bityutskiy (Битюцкий Артём) |
---|
19 | 6 | */ |
---|
.. | .. |
---|
69 | 56 | { |
---|
70 | 57 | int ret; |
---|
71 | 58 | struct ubi_volume *vol = container_of(dev, struct ubi_volume, dev); |
---|
72 | | - struct ubi_device *ubi; |
---|
73 | | - |
---|
74 | | - ubi = ubi_get_device(vol->ubi->ubi_num); |
---|
75 | | - if (!ubi) |
---|
76 | | - return -ENODEV; |
---|
| 59 | + struct ubi_device *ubi = vol->ubi; |
---|
77 | 60 | |
---|
78 | 61 | spin_lock(&ubi->volumes_lock); |
---|
79 | 62 | if (!ubi->volumes[vol->vol_id]) { |
---|
80 | 63 | spin_unlock(&ubi->volumes_lock); |
---|
81 | | - ubi_put_device(ubi); |
---|
82 | 64 | return -ENODEV; |
---|
83 | 65 | } |
---|
84 | 66 | /* Take a reference to prevent volume removal */ |
---|
.. | .. |
---|
116 | 98 | vol->ref_count -= 1; |
---|
117 | 99 | ubi_assert(vol->ref_count >= 0); |
---|
118 | 100 | spin_unlock(&ubi->volumes_lock); |
---|
119 | | - ubi_put_device(ubi); |
---|
120 | 101 | return ret; |
---|
121 | 102 | } |
---|
122 | 103 | |
---|
.. | .. |
---|
328 | 309 | ubi->volumes[vol_id] = NULL; |
---|
329 | 310 | ubi->vol_count -= 1; |
---|
330 | 311 | spin_unlock(&ubi->volumes_lock); |
---|
331 | | - ubi_eba_destroy_table(eba_tbl); |
---|
332 | 312 | out_acc: |
---|
333 | 313 | spin_lock(&ubi->volumes_lock); |
---|
334 | 314 | ubi->rsvd_pebs -= vol->reserved_pebs; |
---|
.. | .. |
---|
484 | 464 | for (i = 0; i < -pebs; i++) { |
---|
485 | 465 | err = ubi_eba_unmap_leb(ubi, vol, reserved_pebs + i); |
---|
486 | 466 | if (err) |
---|
487 | | - goto out_acc; |
---|
| 467 | + goto out_free; |
---|
488 | 468 | } |
---|
489 | 469 | spin_lock(&ubi->volumes_lock); |
---|
490 | 470 | ubi->rsvd_pebs += pebs; |
---|
.. | .. |
---|
532 | 512 | ubi->avail_pebs += pebs; |
---|
533 | 513 | spin_unlock(&ubi->volumes_lock); |
---|
534 | 514 | } |
---|
| 515 | + return err; |
---|
| 516 | + |
---|
535 | 517 | out_free: |
---|
536 | | - kfree(new_eba_tbl); |
---|
| 518 | + ubi_eba_destroy_table(new_eba_tbl); |
---|
537 | 519 | return err; |
---|
538 | 520 | } |
---|
539 | 521 | |
---|
.. | .. |
---|
600 | 582 | if (err) { |
---|
601 | 583 | ubi_err(ubi, "cannot add character device for volume %d, error %d", |
---|
602 | 584 | vol_id, err); |
---|
| 585 | + vol_release(&vol->dev); |
---|
603 | 586 | return err; |
---|
604 | 587 | } |
---|
605 | 588 | |
---|
.. | .. |
---|
610 | 593 | vol->dev.groups = volume_dev_groups; |
---|
611 | 594 | dev_set_name(&vol->dev, "%s_%d", ubi->ubi_name, vol->vol_id); |
---|
612 | 595 | err = device_register(&vol->dev); |
---|
613 | | - if (err) |
---|
614 | | - goto out_cdev; |
---|
| 596 | + if (err) { |
---|
| 597 | + cdev_del(&vol->cdev); |
---|
| 598 | + put_device(&vol->dev); |
---|
| 599 | + return err; |
---|
| 600 | + } |
---|
615 | 601 | |
---|
616 | 602 | self_check_volumes(ubi); |
---|
617 | | - return err; |
---|
618 | | - |
---|
619 | | -out_cdev: |
---|
620 | | - cdev_del(&vol->cdev); |
---|
621 | 603 | return err; |
---|
622 | 604 | } |
---|
623 | 605 | |
---|