Skip to content

Commit 660685d

Browse files
dedekindDavid Woodhouse
authored andcommitted
mtd: merge mtdchar module with mtdcore
The MTD subsystem has historically tried to be as configurable as possible. The side-effect of this is that its configuration menu is rather large, and we are gradually shrinking it. For example, we recently merged partitions support with the mtdcore. This patch does the next step - it merges the mtdchar module to mtdcore. And in this case this is not only about eliminating too fine-grained separation and simplifying the configuration menu. This is also about eliminating seemingly useless kernel module. Indeed, mtdchar is a module that allows user-space making use of MTD devices via /dev/mtd* character devices. If users do not enable it, they simply cannot use MTD devices at all. They cannot read or write the flash contents. Is it a sane and useful setup? I believe not. And everyone just enables mtdchar. Having mtdchar separate is also a little bit harmful. People sometimes miss the fact that they need to enable an additional configuration option to have user-space MTD interfaces, and then they wonder why on earth the kernel does not allow using the flash? They spend time asking around. Thus, let's just get rid of this module and make it part of mtd core. Note, mtdchar had additional configuration option to enable OTP interfaces, which are present on some flashes. I removed that option as well - it saves a really tiny amount space. [dwmw2: Strictly speaking, you can mount file systems on MTD devices just fine without the mtdchar (or mtdblock) devices; you just can't do other manipulations directly on the underlying device. But still I agree that it makes sense to make this unconditional. And Yay! we get to kill off an instance of checking CONFIG_foo_MODULE, which is an abomination that should never happen.] Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
1 parent cb70783 commit 660685d

8 files changed

Lines changed: 19 additions & 40 deletions

File tree

‎drivers/mtd/Kconfig‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -157,19 +157,6 @@ config MTD_BCM47XX_PARTS
157157

158158
comment "User Modules And Translation Layers"
159159

160-
config MTD_CHAR
161-
tristate "Direct char device access to MTD devices"
162-
help
163-
This provides a character device for each MTD device present in
164-
the system, allowing the user to read and write directly to the
165-
memory chips, and also use ioctl() to obtain information about
166-
the device, or to erase parts of it.
167-
168-
config HAVE_MTD_OTP
169-
bool
170-
help
171-
Enable access to OTP regions using MTD_CHAR.
172-
173160
config MTD_BLKDEVS
174161
tristate "Common interface to block layer for MTD 'translation layers'"
175162
depends on BLOCK

‎drivers/mtd/Makefile‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# Core functionality.
66
obj-$(CONFIG_MTD) += mtd.o
7-
mtd-y := mtdcore.o mtdsuper.o mtdconcat.o mtdpart.o
7+
mtd-y := mtdcore.o mtdsuper.o mtdconcat.o mtdpart.o mtdchar.o
88

99
obj-$(CONFIG_MTD_OF_PARTS) += ofpart.o
1010
obj-$(CONFIG_MTD_REDBOOT_PARTS) += redboot.o
@@ -15,7 +15,6 @@ obj-$(CONFIG_MTD_BCM63XX_PARTS) += bcm63xxpart.o
1515
obj-$(CONFIG_MTD_BCM47XX_PARTS) += bcm47xxpart.o
1616

1717
# 'Users' - code which presents functionality to userspace.
18-
obj-$(CONFIG_MTD_CHAR) += mtdchar.o
1918
obj-$(CONFIG_MTD_BLKDEVS) += mtd_blkdevs.o
2019
obj-$(CONFIG_MTD_BLOCK) += mtdblock.o
2120
obj-$(CONFIG_MTD_BLOCK_RO) += mtdblock_ro.o

‎drivers/mtd/chips/Kconfig‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ config MTD_CFI_I8
146146
config MTD_OTP
147147
bool "Protection Registers aka one-time programmable (OTP) bits"
148148
depends on MTD_CFI_ADV_OPTIONS
149-
select HAVE_MTD_OTP
150149
default n
151150
help
152151
This enables support for reading, writing and locking so called

‎drivers/mtd/devices/Kconfig‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ config MTD_DATAFLASH_WRITE_VERIFY
7171
config MTD_DATAFLASH_OTP
7272
bool "DataFlash OTP support (Security Register)"
7373
depends on MTD_DATAFLASH
74-
select HAVE_MTD_OTP
7574
help
7675
Newer DataFlash chips (revisions C and D) support 128 bytes of
7776
one-time-programmable (OTP) data. The first half may be written

‎drivers/mtd/mtdchar.c‎

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838

3939
#include <asm/uaccess.h>
4040

41+
#include "mtdcore.h"
42+
4143
static DEFINE_MUTEX(mtd_mutex);
4244

4345
/*
@@ -365,7 +367,6 @@ static void mtdchar_erase_callback (struct erase_info *instr)
365367
wake_up((wait_queue_head_t *)instr->priv);
366368
}
367369

368-
#ifdef CONFIG_HAVE_MTD_OTP
369370
static int otp_select_filemode(struct mtd_file_info *mfi, int mode)
370371
{
371372
struct mtd_info *mtd = mfi->mtd;
@@ -395,9 +396,6 @@ static int otp_select_filemode(struct mtd_file_info *mfi, int mode)
395396

396397
return 0;
397398
}
398-
#else
399-
# define otp_select_filemode(f,m) -EOPNOTSUPP
400-
#endif
401399

402400
static int mtdchar_writeoob(struct file *file, struct mtd_info *mtd,
403401
uint64_t start, uint32_t length, void __user *ptr,
@@ -890,7 +888,6 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg)
890888
break;
891889
}
892890

893-
#ifdef CONFIG_HAVE_MTD_OTP
894891
case OTPSELECT:
895892
{
896893
int mode;
@@ -946,7 +943,6 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg)
946943
ret = mtd_lock_user_prot_reg(mtd, oinfo.start, oinfo.length);
947944
break;
948945
}
949-
#endif
950946

951947
/* This ioctl is being deprecated - it truncates the ECC layout */
952948
case ECCGETLAYOUT:
@@ -1242,7 +1238,7 @@ static struct file_system_type mtd_inodefs_type = {
12421238
};
12431239
MODULE_ALIAS_FS("mtd_inodefs");
12441240

1245-
static int __init init_mtdchar(void)
1241+
int __init init_mtdchar(void)
12461242
{
12471243
int ret;
12481244

@@ -1268,18 +1264,10 @@ static int __init init_mtdchar(void)
12681264
return ret;
12691265
}
12701266

1271-
static void __exit cleanup_mtdchar(void)
1267+
void __exit cleanup_mtdchar(void)
12721268
{
12731269
unregister_filesystem(&mtd_inodefs_type);
12741270
__unregister_chrdev(MTD_CHAR_MAJOR, 0, 1 << MINORBITS, "mtd");
12751271
}
12761272

1277-
module_init(init_mtdchar);
1278-
module_exit(cleanup_mtdchar);
1279-
1280-
MODULE_ALIAS_CHARDEV_MAJOR(MTD_CHAR_MAJOR);
1281-
1282-
MODULE_LICENSE("GPL");
1283-
MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
1284-
MODULE_DESCRIPTION("Direct character-device access to MTD devices");
12851273
MODULE_ALIAS_CHARDEV_MAJOR(MTD_CHAR_MAJOR);

‎drivers/mtd/mtdcore.c‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <linux/mtd/partitions.h>
4242

4343
#include "mtdcore.h"
44+
4445
/*
4546
* backing device capabilities for non-mappable devices (such as NAND flash)
4647
* - permits private mappings, copies are taken of the data
@@ -96,11 +97,7 @@ EXPORT_SYMBOL_GPL(__mtd_next_device);
9697
static LIST_HEAD(mtd_notifiers);
9798

9899

99-
#if defined(CONFIG_MTD_CHAR) || defined(CONFIG_MTD_CHAR_MODULE)
100100
#define MTD_DEVT(index) MKDEV(MTD_CHAR_MAJOR, (index)*2)
101-
#else
102-
#define MTD_DEVT(index) 0
103-
#endif
104101

105102
/* REVISIT once MTD uses the driver model better, whoever allocates
106103
* the mtd_info will probably want to use the release() hook...
@@ -1185,8 +1182,15 @@ static int __init init_mtd(void)
11851182

11861183
proc_mtd = proc_create("mtd", 0, NULL, &mtd_proc_ops);
11871184

1185+
ret = init_mtdchar();
1186+
if (ret)
1187+
goto out_procfs;
1188+
11881189
return 0;
11891190

1191+
out_procfs:
1192+
if (proc_mtd)
1193+
remove_proc_entry("mtd", NULL);
11901194
err_bdi3:
11911195
bdi_destroy(&mtd_bdi_ro_mappable);
11921196
err_bdi2:
@@ -1200,6 +1204,7 @@ static int __init init_mtd(void)
12001204

12011205
static void __exit cleanup_mtd(void)
12021206
{
1207+
cleanup_mtdchar();
12031208
if (proc_mtd)
12041209
remove_proc_entry("mtd", NULL);
12051210
class_unregister(&mtd_class);

‎drivers/mtd/mtdcore.h‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* These are exported solely for the purpose of mtd_blkdevs.c. You
3-
* should not use them for _anything_ else.
2+
* These are exported solely for the purpose of mtd_blkdevs.c and mtdchar.c.
3+
* You should not use them for _anything_ else.
44
*/
55

66
extern struct mutex mtd_table_mutex;
@@ -14,6 +14,9 @@ int parse_mtd_partitions(struct mtd_info *master, const char * const *types,
1414
struct mtd_partition **pparts,
1515
struct mtd_part_parser_data *data);
1616

17+
int __init init_mtdchar(void);
18+
void __exit cleanup_mtdchar(void);
19+
1720
#define mtd_for_each_device(mtd) \
1821
for ((mtd) = __mtd_next_device(0); \
1922
(mtd) != NULL; \

‎drivers/mtd/onenand/Kconfig‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ config MTD_ONENAND_SAMSUNG
4040

4141
config MTD_ONENAND_OTP
4242
bool "OneNAND OTP Support"
43-
select HAVE_MTD_OTP
4443
help
4544
One Block of the NAND Flash Array memory is reserved as
4645
a One-Time Programmable Block memory area.

0 commit comments

Comments
 (0)