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

mtd: use DEFINE_SHOW_ATTRIBUTE() instead of open-coding it

DEFINE_SHOW_ATTRIBUTE macro can help us simplify the code, so change
to it. And change the DEBUGFS_RO_ATTR macro defined in some file to a
standard macro.

Signed-off-by: Yangtao Li <tiny.windzz@gmail.com>
Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com>

authored by

Yangtao Li and committed by
Boris Brezillon
c78f59d7 bafae538

+12 -45
+8 -8
drivers/mtd/devices/docg3.c
··· 1603 1603 /* 1604 1604 * Debug sysfs entries 1605 1605 */ 1606 - static int dbg_flashctrl_show(struct seq_file *s, void *p) 1606 + static int flashcontrol_show(struct seq_file *s, void *p) 1607 1607 { 1608 1608 struct docg3 *docg3 = (struct docg3 *)s->private; 1609 1609 ··· 1623 1623 1624 1624 return 0; 1625 1625 } 1626 - DEBUGFS_RO_ATTR(flashcontrol, dbg_flashctrl_show); 1626 + DEFINE_SHOW_ATTRIBUTE(flashcontrol); 1627 1627 1628 - static int dbg_asicmode_show(struct seq_file *s, void *p) 1628 + static int asic_mode_show(struct seq_file *s, void *p) 1629 1629 { 1630 1630 struct docg3 *docg3 = (struct docg3 *)s->private; 1631 1631 ··· 1660 1660 seq_puts(s, ")\n"); 1661 1661 return 0; 1662 1662 } 1663 - DEBUGFS_RO_ATTR(asic_mode, dbg_asicmode_show); 1663 + DEFINE_SHOW_ATTRIBUTE(asic_mode); 1664 1664 1665 - static int dbg_device_id_show(struct seq_file *s, void *p) 1665 + static int device_id_show(struct seq_file *s, void *p) 1666 1666 { 1667 1667 struct docg3 *docg3 = (struct docg3 *)s->private; 1668 1668 int id; ··· 1674 1674 seq_printf(s, "DeviceId = %d\n", id); 1675 1675 return 0; 1676 1676 } 1677 - DEBUGFS_RO_ATTR(device_id, dbg_device_id_show); 1677 + DEFINE_SHOW_ATTRIBUTE(device_id); 1678 1678 1679 - static int dbg_protection_show(struct seq_file *s, void *p) 1679 + static int protection_show(struct seq_file *s, void *p) 1680 1680 { 1681 1681 struct docg3 *docg3 = (struct docg3 *)s->private; 1682 1682 int protect, dps0, dps0_low, dps0_high, dps1, dps1_low, dps1_high; ··· 1726 1726 !!(dps1 & DOC_DPS_KEY_OK)); 1727 1727 return 0; 1728 1728 } 1729 - DEBUGFS_RO_ATTR(protection, dbg_protection_show); 1729 + DEFINE_SHOW_ATTRIBUTE(protection); 1730 1730 1731 1731 static void __init doc_dbg_register(struct mtd_info *floor) 1732 1732 {
-11
drivers/mtd/devices/docg3.h
··· 317 317 #define doc_info(fmt, arg...) dev_info(docg3->dev, (fmt), ## arg) 318 318 #define doc_dbg(fmt, arg...) dev_dbg(docg3->dev, (fmt), ## arg) 319 319 #define doc_vdbg(fmt, arg...) dev_vdbg(docg3->dev, (fmt), ## arg) 320 - 321 - #define DEBUGFS_RO_ATTR(name, show_fct) \ 322 - static int name##_open(struct inode *inode, struct file *file) \ 323 - { return single_open(file, show_fct, inode->i_private); } \ 324 - static const struct file_operations name##_fops = { \ 325 - .owner = THIS_MODULE, \ 326 - .open = name##_open, \ 327 - .llseek = seq_lseek, \ 328 - .read = seq_read, \ 329 - .release = single_release \ 330 - }; 331 320 #endif 332 321 333 322 /*
+1 -12
drivers/mtd/mtdswap.c
··· 1265 1265 1266 1266 return 0; 1267 1267 } 1268 - 1269 - static int mtdswap_open(struct inode *inode, struct file *file) 1270 - { 1271 - return single_open(file, mtdswap_show, inode->i_private); 1272 - } 1273 - 1274 - static const struct file_operations mtdswap_fops = { 1275 - .open = mtdswap_open, 1276 - .read = seq_read, 1277 - .llseek = seq_lseek, 1278 - .release = single_release, 1279 - }; 1268 + DEFINE_SHOW_ATTRIBUTE(mtdswap); 1280 1269 1281 1270 static int mtdswap_add_debugfs(struct mtdswap_dev *d) 1282 1271 {
+3 -14
drivers/mtd/nand/raw/nandsim.c
··· 443 443 /* MTD structure for NAND controller */ 444 444 static struct mtd_info *nsmtd; 445 445 446 - static int nandsim_debugfs_show(struct seq_file *m, void *private) 446 + static int nandsim_show(struct seq_file *m, void *private) 447 447 { 448 448 unsigned long wmin = -1, wmax = 0, avg; 449 449 unsigned long deciles[10], decile_max[10], tot = 0; ··· 494 494 495 495 return 0; 496 496 } 497 - 498 - static int nandsim_debugfs_open(struct inode *inode, struct file *file) 499 - { 500 - return single_open(file, nandsim_debugfs_show, inode->i_private); 501 - } 502 - 503 - static const struct file_operations dfs_fops = { 504 - .open = nandsim_debugfs_open, 505 - .read = seq_read, 506 - .llseek = seq_lseek, 507 - .release = single_release, 508 - }; 497 + DEFINE_SHOW_ATTRIBUTE(nandsim); 509 498 510 499 /** 511 500 * nandsim_debugfs_create - initialize debugfs ··· 520 531 } 521 532 522 533 dent = debugfs_create_file("nandsim_wear_report", S_IRUSR, 523 - root, dev, &dfs_fops); 534 + root, dev, &nandsim_fops); 524 535 if (IS_ERR_OR_NULL(dent)) { 525 536 NS_ERR("cannot create \"nandsim_wear_report\" debugfs entry\n"); 526 537 return -1;