Skip to content

Commit 3f75bff

Browse files
committed
Merge tag 'mtd/fixes-for-6.16-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux
Pull mtd fixes from Miquel Raynal: "The main fix that really needs to get in is the revert of the patch adding the new mtd_master class, because it entirely fails the partitioning if a specific Kconfig option is set. We need to think how to handle that differently, so let's revert it as we need to get back to the pen and paper situation again. Otherwise the definition of some Winbond SPI NAND chips are receiving some fixes (geometry and maximum frequency, mostly). And finally a small memory leak gets also fixed" * tag 'mtd/fixes-for-6.16-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux: mtd: spinand: fix memory leak of ECC engine conf mtd: spinand: winbond: Prevent unsupported frequencies on dual/quad I/O variants mtd: spinand: winbond: Increase maximum frequency on an octal operation mtd: spinand: winbond: Fix W35N number of planes/LUN Revert "mtd: core: always create master device"
2 parents a765b9e + 6463cbe commit 3f75bff

File tree

8 files changed

+63
-132
lines changed

8 files changed

+63
-132
lines changed

drivers/mtd/mtdchar.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ static int mtdchar_blkpg_ioctl(struct mtd_info *mtd,
559559
/* Sanitize user input */
560560
p.devname[BLKPG_DEVNAMELTH - 1] = '\0';
561561

562-
return mtd_add_partition(mtd, p.devname, p.start, p.length, NULL);
562+
return mtd_add_partition(mtd, p.devname, p.start, p.length);
563563

564564
case BLKPG_DEL_PARTITION:
565565

drivers/mtd/mtdcore.c

Lines changed: 40 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,7 @@ static struct class mtd_class = {
6868
.pm = MTD_CLS_PM_OPS,
6969
};
7070

71-
static struct class mtd_master_class = {
72-
.name = "mtd_master",
73-
.pm = MTD_CLS_PM_OPS,
74-
};
75-
7671
static DEFINE_IDR(mtd_idr);
77-
static DEFINE_IDR(mtd_master_idr);
7872

7973
/* These are exported solely for the purpose of mtd_blkdevs.c. You
8074
should not use them for _anything_ else */
@@ -89,9 +83,8 @@ EXPORT_SYMBOL_GPL(__mtd_next_device);
8983

9084
static LIST_HEAD(mtd_notifiers);
9185

92-
#define MTD_MASTER_DEVS 255
86+
9387
#define MTD_DEVT(index) MKDEV(MTD_CHAR_MAJOR, (index)*2)
94-
static dev_t mtd_master_devt;
9588

9689
/* REVISIT once MTD uses the driver model better, whoever allocates
9790
* the mtd_info will probably want to use the release() hook...
@@ -111,17 +104,6 @@ static void mtd_release(struct device *dev)
111104
device_destroy(&mtd_class, index + 1);
112105
}
113106

114-
static void mtd_master_release(struct device *dev)
115-
{
116-
struct mtd_info *mtd = dev_get_drvdata(dev);
117-
118-
idr_remove(&mtd_master_idr, mtd->index);
119-
of_node_put(mtd_get_of_node(mtd));
120-
121-
if (mtd_is_partition(mtd))
122-
release_mtd_partition(mtd);
123-
}
124-
125107
static void mtd_device_release(struct kref *kref)
126108
{
127109
struct mtd_info *mtd = container_of(kref, struct mtd_info, refcnt);
@@ -385,11 +367,6 @@ static const struct device_type mtd_devtype = {
385367
.release = mtd_release,
386368
};
387369

388-
static const struct device_type mtd_master_devtype = {
389-
.name = "mtd_master",
390-
.release = mtd_master_release,
391-
};
392-
393370
static bool mtd_expert_analysis_mode;
394371

395372
#ifdef CONFIG_DEBUG_FS
@@ -657,13 +634,13 @@ static void mtd_check_of_node(struct mtd_info *mtd)
657634
/**
658635
* add_mtd_device - register an MTD device
659636
* @mtd: pointer to new MTD device info structure
660-
* @partitioned: create partitioned device
661637
*
662638
* Add a device to the list of MTD devices present in the system, and
663639
* notify each currently active MTD 'user' of its arrival. Returns
664640
* zero on success or non-zero on failure.
665641
*/
666-
int add_mtd_device(struct mtd_info *mtd, bool partitioned)
642+
643+
int add_mtd_device(struct mtd_info *mtd)
667644
{
668645
struct device_node *np = mtd_get_of_node(mtd);
669646
struct mtd_info *master = mtd_get_master(mtd);
@@ -710,17 +687,10 @@ int add_mtd_device(struct mtd_info *mtd, bool partitioned)
710687
ofidx = -1;
711688
if (np)
712689
ofidx = of_alias_get_id(np, "mtd");
713-
if (partitioned) {
714-
if (ofidx >= 0)
715-
i = idr_alloc(&mtd_idr, mtd, ofidx, ofidx + 1, GFP_KERNEL);
716-
else
717-
i = idr_alloc(&mtd_idr, mtd, 0, 0, GFP_KERNEL);
718-
} else {
719-
if (ofidx >= 0)
720-
i = idr_alloc(&mtd_master_idr, mtd, ofidx, ofidx + 1, GFP_KERNEL);
721-
else
722-
i = idr_alloc(&mtd_master_idr, mtd, 0, 0, GFP_KERNEL);
723-
}
690+
if (ofidx >= 0)
691+
i = idr_alloc(&mtd_idr, mtd, ofidx, ofidx + 1, GFP_KERNEL);
692+
else
693+
i = idr_alloc(&mtd_idr, mtd, 0, 0, GFP_KERNEL);
724694
if (i < 0) {
725695
error = i;
726696
goto fail_locked;
@@ -768,26 +738,17 @@ int add_mtd_device(struct mtd_info *mtd, bool partitioned)
768738
/* Caller should have set dev.parent to match the
769739
* physical device, if appropriate.
770740
*/
771-
if (partitioned) {
772-
mtd->dev.type = &mtd_devtype;
773-
mtd->dev.class = &mtd_class;
774-
mtd->dev.devt = MTD_DEVT(i);
775-
dev_set_name(&mtd->dev, "mtd%d", i);
776-
error = dev_set_name(&mtd->dev, "mtd%d", i);
777-
} else {
778-
mtd->dev.type = &mtd_master_devtype;
779-
mtd->dev.class = &mtd_master_class;
780-
mtd->dev.devt = MKDEV(MAJOR(mtd_master_devt), i);
781-
error = dev_set_name(&mtd->dev, "mtd_master%d", i);
782-
}
741+
mtd->dev.type = &mtd_devtype;
742+
mtd->dev.class = &mtd_class;
743+
mtd->dev.devt = MTD_DEVT(i);
744+
error = dev_set_name(&mtd->dev, "mtd%d", i);
783745
if (error)
784746
goto fail_devname;
785747
dev_set_drvdata(&mtd->dev, mtd);
786748
mtd_check_of_node(mtd);
787749
of_node_get(mtd_get_of_node(mtd));
788750
error = device_register(&mtd->dev);
789751
if (error) {
790-
pr_err("mtd: %s device_register fail %d\n", mtd->name, error);
791752
put_device(&mtd->dev);
792753
goto fail_added;
793754
}
@@ -799,30 +760,24 @@ int add_mtd_device(struct mtd_info *mtd, bool partitioned)
799760

800761
mtd_debugfs_populate(mtd);
801762

802-
if (partitioned) {
803-
device_create(&mtd_class, mtd->dev.parent, MTD_DEVT(i) + 1, NULL,
804-
"mtd%dro", i);
805-
}
763+
device_create(&mtd_class, mtd->dev.parent, MTD_DEVT(i) + 1, NULL,
764+
"mtd%dro", i);
806765

807-
pr_debug("mtd: Giving out %spartitioned device %d to %s\n",
808-
partitioned ? "" : "un-", i, mtd->name);
766+
pr_debug("mtd: Giving out device %d to %s\n", i, mtd->name);
809767
/* No need to get a refcount on the module containing
810768
the notifier, since we hold the mtd_table_mutex */
811769
list_for_each_entry(not, &mtd_notifiers, list)
812770
not->add(mtd);
813771

814772
mutex_unlock(&mtd_table_mutex);
815773

816-
if (partitioned) {
817-
if (of_property_read_bool(mtd_get_of_node(mtd), "linux,rootfs")) {
818-
if (IS_BUILTIN(CONFIG_MTD)) {
819-
pr_info("mtd: setting mtd%d (%s) as root device\n",
820-
mtd->index, mtd->name);
821-
ROOT_DEV = MKDEV(MTD_BLOCK_MAJOR, mtd->index);
822-
} else {
823-
pr_warn("mtd: can't set mtd%d (%s) as root device - mtd must be builtin\n",
824-
mtd->index, mtd->name);
825-
}
774+
if (of_property_read_bool(mtd_get_of_node(mtd), "linux,rootfs")) {
775+
if (IS_BUILTIN(CONFIG_MTD)) {
776+
pr_info("mtd: setting mtd%d (%s) as root device\n", mtd->index, mtd->name);
777+
ROOT_DEV = MKDEV(MTD_BLOCK_MAJOR, mtd->index);
778+
} else {
779+
pr_warn("mtd: can't set mtd%d (%s) as root device - mtd must be builtin\n",
780+
mtd->index, mtd->name);
826781
}
827782
}
828783

@@ -838,10 +793,7 @@ int add_mtd_device(struct mtd_info *mtd, bool partitioned)
838793
fail_added:
839794
of_node_put(mtd_get_of_node(mtd));
840795
fail_devname:
841-
if (partitioned)
842-
idr_remove(&mtd_idr, i);
843-
else
844-
idr_remove(&mtd_master_idr, i);
796+
idr_remove(&mtd_idr, i);
845797
fail_locked:
846798
mutex_unlock(&mtd_table_mutex);
847799
return error;
@@ -859,14 +811,12 @@ int add_mtd_device(struct mtd_info *mtd, bool partitioned)
859811

860812
int del_mtd_device(struct mtd_info *mtd)
861813
{
862-
struct mtd_notifier *not;
863-
struct idr *idr;
864814
int ret;
815+
struct mtd_notifier *not;
865816

866817
mutex_lock(&mtd_table_mutex);
867818

868-
idr = mtd->dev.class == &mtd_class ? &mtd_idr : &mtd_master_idr;
869-
if (idr_find(idr, mtd->index) != mtd) {
819+
if (idr_find(&mtd_idr, mtd->index) != mtd) {
870820
ret = -ENODEV;
871821
goto out_error;
872822
}
@@ -1106,7 +1056,6 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
11061056
const struct mtd_partition *parts,
11071057
int nr_parts)
11081058
{
1109-
struct mtd_info *parent;
11101059
int ret, err;
11111060

11121061
mtd_set_dev_defaults(mtd);
@@ -1115,30 +1064,25 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
11151064
if (ret)
11161065
goto out;
11171066

1118-
ret = add_mtd_device(mtd, false);
1119-
if (ret)
1120-
goto out;
1121-
11221067
if (IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER)) {
1123-
ret = mtd_add_partition(mtd, mtd->name, 0, MTDPART_SIZ_FULL, &parent);
1068+
ret = add_mtd_device(mtd);
11241069
if (ret)
11251070
goto out;
1126-
1127-
} else {
1128-
parent = mtd;
11291071
}
11301072

11311073
/* Prefer parsed partitions over driver-provided fallback */
1132-
ret = parse_mtd_partitions(parent, types, parser_data);
1074+
ret = parse_mtd_partitions(mtd, types, parser_data);
11331075
if (ret == -EPROBE_DEFER)
11341076
goto out;
11351077

11361078
if (ret > 0)
11371079
ret = 0;
11381080
else if (nr_parts)
1139-
ret = add_mtd_partitions(parent, parts, nr_parts);
1140-
else if (!IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER))
1141-
ret = mtd_add_partition(parent, mtd->name, 0, MTDPART_SIZ_FULL, NULL);
1081+
ret = add_mtd_partitions(mtd, parts, nr_parts);
1082+
else if (!device_is_registered(&mtd->dev))
1083+
ret = add_mtd_device(mtd);
1084+
else
1085+
ret = 0;
11421086

11431087
if (ret)
11441088
goto out;
@@ -1158,14 +1102,13 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
11581102
register_reboot_notifier(&mtd->reboot_notifier);
11591103
}
11601104

1161-
return 0;
11621105
out:
1163-
nvmem_unregister(mtd->otp_user_nvmem);
1164-
nvmem_unregister(mtd->otp_factory_nvmem);
1165-
1166-
del_mtd_partitions(mtd);
1106+
if (ret) {
1107+
nvmem_unregister(mtd->otp_user_nvmem);
1108+
nvmem_unregister(mtd->otp_factory_nvmem);
1109+
}
11671110

1168-
if (device_is_registered(&mtd->dev)) {
1111+
if (ret && device_is_registered(&mtd->dev)) {
11691112
err = del_mtd_device(mtd);
11701113
if (err)
11711114
pr_err("Error when deleting MTD device (%d)\n", err);
@@ -1324,7 +1267,8 @@ int __get_mtd_device(struct mtd_info *mtd)
13241267
mtd = mtd->parent;
13251268
}
13261269

1327-
kref_get(&master->refcnt);
1270+
if (IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER))
1271+
kref_get(&master->refcnt);
13281272

13291273
return 0;
13301274
}
@@ -1418,7 +1362,8 @@ void __put_mtd_device(struct mtd_info *mtd)
14181362
mtd = parent;
14191363
}
14201364

1421-
kref_put(&master->refcnt, mtd_device_release);
1365+
if (IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER))
1366+
kref_put(&master->refcnt, mtd_device_release);
14221367

14231368
module_put(master->owner);
14241369

@@ -2585,16 +2530,6 @@ static int __init init_mtd(void)
25852530
if (ret)
25862531
goto err_reg;
25872532

2588-
ret = class_register(&mtd_master_class);
2589-
if (ret)
2590-
goto err_reg2;
2591-
2592-
ret = alloc_chrdev_region(&mtd_master_devt, 0, MTD_MASTER_DEVS, "mtd_master");
2593-
if (ret < 0) {
2594-
pr_err("unable to allocate char dev region\n");
2595-
goto err_chrdev;
2596-
}
2597-
25982533
mtd_bdi = mtd_bdi_init("mtd");
25992534
if (IS_ERR(mtd_bdi)) {
26002535
ret = PTR_ERR(mtd_bdi);
@@ -2619,10 +2554,6 @@ static int __init init_mtd(void)
26192554
bdi_unregister(mtd_bdi);
26202555
bdi_put(mtd_bdi);
26212556
err_bdi:
2622-
unregister_chrdev_region(mtd_master_devt, MTD_MASTER_DEVS);
2623-
err_chrdev:
2624-
class_unregister(&mtd_master_class);
2625-
err_reg2:
26262557
class_unregister(&mtd_class);
26272558
err_reg:
26282559
pr_err("Error registering mtd class or bdi: %d\n", ret);
@@ -2636,12 +2567,9 @@ static void __exit cleanup_mtd(void)
26362567
if (proc_mtd)
26372568
remove_proc_entry("mtd", NULL);
26382569
class_unregister(&mtd_class);
2639-
class_unregister(&mtd_master_class);
2640-
unregister_chrdev_region(mtd_master_devt, MTD_MASTER_DEVS);
26412570
bdi_unregister(mtd_bdi);
26422571
bdi_put(mtd_bdi);
26432572
idr_destroy(&mtd_idr);
2644-
idr_destroy(&mtd_master_idr);
26452573
}
26462574

26472575
module_init(init_mtd);

drivers/mtd/mtdcore.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ extern struct mutex mtd_table_mutex;
88
extern struct backing_dev_info *mtd_bdi;
99

1010
struct mtd_info *__mtd_next_device(int i);
11-
int __must_check add_mtd_device(struct mtd_info *mtd, bool partitioned);
11+
int __must_check add_mtd_device(struct mtd_info *mtd);
1212
int del_mtd_device(struct mtd_info *mtd);
1313
int add_mtd_partitions(struct mtd_info *, const struct mtd_partition *, int);
1414
int del_mtd_partitions(struct mtd_info *);

0 commit comments

Comments
 (0)