hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/mtd/ubi/vmt.c
....@@ -1,19 +1,6 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * 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
174 *
185 * Author: Artem Bityutskiy (Битюцкий Артём)
196 */
....@@ -69,16 +56,11 @@
6956 {
7057 int ret;
7158 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;
7760
7861 spin_lock(&ubi->volumes_lock);
7962 if (!ubi->volumes[vol->vol_id]) {
8063 spin_unlock(&ubi->volumes_lock);
81
- ubi_put_device(ubi);
8264 return -ENODEV;
8365 }
8466 /* Take a reference to prevent volume removal */
....@@ -116,7 +98,6 @@
11698 vol->ref_count -= 1;
11799 ubi_assert(vol->ref_count >= 0);
118100 spin_unlock(&ubi->volumes_lock);
119
- ubi_put_device(ubi);
120101 return ret;
121102 }
122103
....@@ -328,7 +309,6 @@
328309 ubi->volumes[vol_id] = NULL;
329310 ubi->vol_count -= 1;
330311 spin_unlock(&ubi->volumes_lock);
331
- ubi_eba_destroy_table(eba_tbl);
332312 out_acc:
333313 spin_lock(&ubi->volumes_lock);
334314 ubi->rsvd_pebs -= vol->reserved_pebs;
....@@ -484,7 +464,7 @@
484464 for (i = 0; i < -pebs; i++) {
485465 err = ubi_eba_unmap_leb(ubi, vol, reserved_pebs + i);
486466 if (err)
487
- goto out_acc;
467
+ goto out_free;
488468 }
489469 spin_lock(&ubi->volumes_lock);
490470 ubi->rsvd_pebs += pebs;
....@@ -532,8 +512,10 @@
532512 ubi->avail_pebs += pebs;
533513 spin_unlock(&ubi->volumes_lock);
534514 }
515
+ return err;
516
+
535517 out_free:
536
- kfree(new_eba_tbl);
518
+ ubi_eba_destroy_table(new_eba_tbl);
537519 return err;
538520 }
539521
....@@ -600,6 +582,7 @@
600582 if (err) {
601583 ubi_err(ubi, "cannot add character device for volume %d, error %d",
602584 vol_id, err);
585
+ vol_release(&vol->dev);
603586 return err;
604587 }
605588
....@@ -610,14 +593,13 @@
610593 vol->dev.groups = volume_dev_groups;
611594 dev_set_name(&vol->dev, "%s_%d", ubi->ubi_name, vol->vol_id);
612595 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
+ }
615601
616602 self_check_volumes(ubi);
617
- return err;
618
-
619
-out_cdev:
620
- cdev_del(&vol->cdev);
621603 return err;
622604 }
623605