Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mtd: mtdcore: add debugfs nodes for querying the flash name and id

Currently, we don't have vfs nodes for querying the underlying flash name
and flash id. This information is important especially when we want to
know the flash detail of the defective system. In order to support the
query, we add mtd_debugfs_populate() to create two debugfs nodes
(ie. partname and partid). The upper driver can assign the pointer to
partname and partid before calling mtd_device_register().

Signed-off-by: Zhuohao Lee <zhuohao@chromium.org>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>

authored by

Zhuohao Lee and committed by
Tudor Ambarus
1018c94b 7ae2227b

+80 -9
+77 -9
drivers/mtd/mtdcore.c
··· 335 335 .release = mtd_release, 336 336 }; 337 337 338 + static int mtd_partid_show(struct seq_file *s, void *p) 339 + { 340 + struct mtd_info *mtd = s->private; 341 + 342 + seq_printf(s, "%s\n", mtd->dbg.partid); 343 + 344 + return 0; 345 + } 346 + 347 + static int mtd_partid_debugfs_open(struct inode *inode, struct file *file) 348 + { 349 + return single_open(file, mtd_partid_show, inode->i_private); 350 + } 351 + 352 + static const struct file_operations mtd_partid_debug_fops = { 353 + .open = mtd_partid_debugfs_open, 354 + .read = seq_read, 355 + .llseek = seq_lseek, 356 + .release = single_release, 357 + }; 358 + 359 + static int mtd_partname_show(struct seq_file *s, void *p) 360 + { 361 + struct mtd_info *mtd = s->private; 362 + 363 + seq_printf(s, "%s\n", mtd->dbg.partname); 364 + 365 + return 0; 366 + } 367 + 368 + static int mtd_partname_debugfs_open(struct inode *inode, struct file *file) 369 + { 370 + return single_open(file, mtd_partname_show, inode->i_private); 371 + } 372 + 373 + static const struct file_operations mtd_partname_debug_fops = { 374 + .open = mtd_partname_debugfs_open, 375 + .read = seq_read, 376 + .llseek = seq_lseek, 377 + .release = single_release, 378 + }; 379 + 380 + static struct dentry *dfs_dir_mtd; 381 + 382 + static void mtd_debugfs_populate(struct mtd_info *mtd) 383 + { 384 + struct device *dev = &mtd->dev; 385 + struct dentry *root, *dent; 386 + 387 + if (IS_ERR_OR_NULL(dfs_dir_mtd)) 388 + return; 389 + 390 + root = debugfs_create_dir(dev_name(dev), dfs_dir_mtd); 391 + if (IS_ERR_OR_NULL(root)) { 392 + dev_dbg(dev, "won't show data in debugfs\n"); 393 + return; 394 + } 395 + 396 + mtd->dbg.dfs_dir = root; 397 + 398 + if (mtd->dbg.partid) { 399 + dent = debugfs_create_file("partid", 0400, root, mtd, 400 + &mtd_partid_debug_fops); 401 + if (IS_ERR_OR_NULL(dent)) 402 + dev_err(dev, "can't create debugfs entry for partid\n"); 403 + } 404 + 405 + if (mtd->dbg.partname) { 406 + dent = debugfs_create_file("partname", 0400, root, mtd, 407 + &mtd_partname_debug_fops); 408 + if (IS_ERR_OR_NULL(dent)) 409 + dev_err(dev, 410 + "can't create debugfs entry for partname\n"); 411 + } 412 + } 413 + 338 414 #ifndef CONFIG_MMU 339 415 unsigned mtd_mmap_capabilities(struct mtd_info *mtd) 340 416 { ··· 588 512 return 0; 589 513 } 590 514 591 - static struct dentry *dfs_dir_mtd; 592 - 593 515 /** 594 516 * add_mtd_device - register an MTD device 595 517 * @mtd: pointer to new MTD device info structure ··· 681 607 if (error) 682 608 goto fail_nvmem_add; 683 609 684 - if (!IS_ERR_OR_NULL(dfs_dir_mtd)) { 685 - mtd->dbg.dfs_dir = debugfs_create_dir(dev_name(&mtd->dev), dfs_dir_mtd); 686 - if (IS_ERR_OR_NULL(mtd->dbg.dfs_dir)) { 687 - pr_debug("mtd device %s won't show data in debugfs\n", 688 - dev_name(&mtd->dev)); 689 - } 690 - } 610 + mtd_debugfs_populate(mtd); 691 611 692 612 device_create(&mtd_class, mtd->dev.parent, MTD_DEVT(i) + 1, NULL, 693 613 "mtd%dro", i);
+3
include/linux/mtd/mtd.h
··· 189 189 */ 190 190 struct mtd_debug_info { 191 191 struct dentry *dfs_dir; 192 + 193 + const char *partname; 194 + const char *partid; 192 195 }; 193 196 194 197 struct mtd_info {