block: Change to use DEFINE_SHOW_ATTRIBUTE macro
PATCH 1/1 block: Change to use DEFINE_SHOW_ATTRIBUTE macro
Use DEFINE_SHOW_ATTRIBUTE macro to simplify the code.
--- drivers/block/aoe/aoeblk.c | 16 +++----------- drivers/block/drbd/drbd_debugfs.c | 13 +----------- drivers/block/nbd.c | 28 ++++--------------------- drivers/block/pktcdvd.c | 26 +++++------------------ drivers/block/rsxx/core.c | 35 ++++++------------------------- 5 files changed, 19 insertions(+), 99 deletions(-)
drivers/block/aoe/aoeblk.c +3 -13
@@ -110,7 +110,7 @@ static ssize_t aoedisk_show_payload(struct device *dev,return snprintf (page,PAGE_SIZE ,"%lu\n" , d->maxbcnt); } -static int aoedisk_debugfs_show (struct seq_file *s,void *ignored) +static int aoe_show (struct seq_file *s,void *ignored) {struct aoedev *d;struct aoetgt **t, **te;
@@ -154,11 +154,6 @@ static int aoedisk_debugfs_show(struct seq_file *s, void *ignored)return 0 ; } -static int aoe_debugfs_open (struct inode *inode,struct file *file) -{ -return single_open (file, aoedisk_debugfs_show, inode->i_private); -} - static DEVICE_ATTR(state, 0444, aoedisk_show_state, NULL); static DEVICE_ATTR(mac, 0444, aoedisk_show_mac, NULL); static DEVICE_ATTR(netif, 0444, aoedisk_show_netif, NULL);
@@ -186,12 +181,7 @@ static const struct attribute_group *aoe_attr_groups[] = { NULL, }; -static const struct file_operations aoe_debugfs_fops = { - .open = aoe_debugfs_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; +DEFINE_SHOW_ATTRIBUTE (aoe);static void aoedisk_add_debugfs (struct aoedev *d)
@@ -208,7 +198,7 @@ aoedisk_add_debugfs(struct aoedev *d) p++;BUG_ON (*p =='\0' ); entry =debugfs_create_file (p,0444 , aoe_debugfs_dir, d, - &aoe_debugfs_fops); + &aoe_fops);if (IS_ERR_OR_NULL (entry)) {pr_info ("aoe: cannot create debugfs file for %s\n" , d->gd->disk_name);
drivers/block/drbd/drbd_debugfs.c +1 -12
@@ -892,18 +892,7 @@ static int drbd_version_show(struct seq_file *m, void *ignored)return 0 ; } -static int drbd_version_open (struct inode *inode,struct file *file) -{ -return single_open (file, drbd_version_show,NULL ); -} - -static const struct file_operations drbd_version_fops = { - .owner =THIS_MODULE , - .open = drbd_version_open, - .llseek = seq_lseek, - .read = seq_read, - .release = single_release, -}; +DEFINE_SHOW_ATTRIBUTE (drbd_version);/* not __exit, may be indirectly called * from the module-load-failure path as well. */
drivers/block/nbd.c +4 -24
@@ -1399,17 +1399,7 @@ static int nbd_dbg_tasks_show(struct seq_file *s, void *unused)return 0 ; } -static int nbd_dbg_tasks_open (struct inode *inode,struct file *file) -{ -return single_open (file, nbd_dbg_tasks_show, inode->i_private); -} - -static const struct file_operations nbd_dbg_tasks_ops = { - .open = nbd_dbg_tasks_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; +DEFINE_SHOW_ATTRIBUTE (nbd_dbg_tasks);static int nbd_dbg_flags_show (struct seq_file *s,void *unused) {
@@ -1434,17 +1424,7 @@ static int nbd_dbg_flags_show(struct seq_file *s, void *unused)return 0 ; } -static int nbd_dbg_flags_open (struct inode *inode,struct file *file) -{ -return single_open (file, nbd_dbg_flags_show, inode->i_private); -} - -static const struct file_operations nbd_dbg_flags_ops = { - .open = nbd_dbg_flags_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; +DEFINE_SHOW_ATTRIBUTE (nbd_dbg_flags);static int nbd_dev_dbg_init (struct nbd_device *nbd) {
@@ -1462,11 +1442,11 @@ static int nbd_dev_dbg_init(struct nbd_device *nbd) } config->dbg_dir = dir; -debugfs_create_file ("tasks" ,0444 , dir, nbd, &nbd_dbg_tasks_ops); +debugfs_create_file ("tasks" ,0444 , dir, nbd, &nbd_dbg_tasks_fops);debugfs_create_u64 ("size_bytes" ,0444 , dir, &config->bytesize);debugfs_create_u32 ("timeout" ,0444 , dir, &nbd->tag_set.timeout);debugfs_create_u64 ("blocksize" ,0444 , dir, &config->blksize); -debugfs_create_file ("flags" ,0444 , dir, nbd, &nbd_dbg_flags_ops); +debugfs_create_file ("flags" ,0444 , dir, nbd, &nbd_dbg_flags_fops);return 0 ; }
drivers/block/pktcdvd.c +5 -21
@@ -106,7 +106,7 @@ static struct dentry *pkt_debugfs_root = NULL; /* /sys/kernel/debug/pktcdvd *//* forward declaration */ static int pkt_setup_dev (dev_t dev,dev_t * pkt_dev);static int pkt_remove_dev (dev_t pkt_dev); -static int pkt_seq_show (struct seq_file *m,void *p); +static int pkt_show (struct seq_file *m,void *p);static sector_t get_zone (sector_t sector,struct pktcdvd_device *pd) {
@@ -452,23 +452,7 @@ static void pkt_sysfs_cleanup(void)*******************************************************************/ -static int pkt_debugfs_seq_show (struct seq_file *m,void *p) -{ -return pkt_seq_show (m, p); -} - -static int pkt_debugfs_fops_open (struct inode *inode,struct file *file) -{ -return single_open (file, pkt_debugfs_seq_show, inode->i_private); -} - -static const struct file_operations debug_fops = { - .open = pkt_debugfs_fops_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, - .owner =THIS_MODULE , -}; +DEFINE_SHOW_ATTRIBUTE (pkt);static void pkt_debugfs_dev_new (struct pktcdvd_device *pd) {
@@ -479,7 +463,7 @@ static void pkt_debugfs_dev_new(struct pktcdvd_device *pd)return ; pd->dfs_f_info =debugfs_create_file ("info" ,0444 , - pd->dfs_d_root, pd, &debug_fops); + pd->dfs_d_root, pd, &pkt_fops); }static void pkt_debugfs_dev_remove (struct pktcdvd_device *pd)
@@ -2501,7 +2485,7 @@ static void pkt_init_queue(struct pktcdvd_device *pd) q->queuedata = pd; } -static int pkt_seq_show (struct seq_file *m,void *p) +static int pkt_show (struct seq_file *m,void *p) {struct pktcdvd_device *pd = m->private;char *msg;
@@ -2617,7 +2601,7 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev) goto out_mem; } -proc_create_single_data (pd->name,0 , pkt_proc, pkt_seq_show, pd); +proc_create_single_data (pd->name,0 , pkt_proc, pkt_show, pd);pkt_dbg (1 , pd,"writer mapped to %s\n" ,bdevname (bdev, b));return 0 ;
drivers/block/rsxx/core.c +6 -29
@@ -61,7 +61,7 @@ static DEFINE_IDA(rsxx_disk_ida);/* --------------------Debugfs Setup ------------------- */ -static int rsxx_attr_pci_regs_show (struct seq_file *m,void *p) +static int pci_regs_show (struct seq_file *m,void *p) {struct rsxx_cardinfo *card = m->private;
@@ -123,7 +123,7 @@ static int rsxx_attr_pci_regs_show(struct seq_file *m, void *p)return 0 ; } -static int rsxx_attr_stats_show (struct seq_file *m,void *p) +static int stats_show (struct seq_file *m,void *p) {struct rsxx_cardinfo *card = m->private;int i;
@@ -164,16 +164,6 @@ static int rsxx_attr_stats_show(struct seq_file *m, void *p)return 0 ; } -static int rsxx_attr_stats_open (struct inode *inode,struct file *file) -{ -return single_open (file, rsxx_attr_stats_show, inode->i_private); -} - -static int rsxx_attr_pci_regs_open (struct inode *inode,struct file *file) -{ -return single_open (file, rsxx_attr_pci_regs_show, inode->i_private); -} -static ssize_t rsxx_cram_read (struct file *fp,char __user *ubuf,size_t cnt,loff_t *ppos) {
@@ -220,21 +210,8 @@ static const struct file_operations debugfs_cram_fops = { .write = rsxx_cram_write, }; -static const struct file_operations debugfs_stats_fops = { - .owner =THIS_MODULE , - .open = rsxx_attr_stats_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - -static const struct file_operations debugfs_pci_regs_fops = { - .owner =THIS_MODULE , - .open = rsxx_attr_pci_regs_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; +DEFINE_SHOW_ATTRIBUTE (stats); +DEFINE_SHOW_ATTRIBUTE (pci_regs);static void rsxx_debugfs_dev_new (struct rsxx_cardinfo *card) {
@@ -248,13 +225,13 @@ static void rsxx_debugfs_dev_new(struct rsxx_cardinfo *card) debugfs_stats =debugfs_create_file ("stats" ,0444 , card->debugfs_dir, card, - &debugfs_stats_fops); + &stats_fops);if (IS_ERR_OR_NULL (debugfs_stats)) goto failed_debugfs_stats; debugfs_pci_regs =debugfs_create_file ("pci_regs" ,0444 , card->debugfs_dir, card, - &debugfs_pci_regs_fops); + &pci_regs_fops);if (IS_ERR_OR_NULL (debugfs_pci_regs)) goto failed_debugfs_pci_regs;
Signature · 1 line
2.17.0
kbuild test robot
build botThank you for the patch! Yet something to improve:
Hi Yangtao,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on block/for-next]
[also build test ERROR on v4.20-rc4 next-20181130]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Yangtao-Li/block-Change-to-use-DEFINE_SHOW_ATTRIBUTE-macro/20181201-211704 base: https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git for-next config: i386-randconfig-x075-201847 (attached as .config) compiler: gcc-7 (Debian 7.3.0-1) 7.3.0 reproduce: # save the attached .config to linux build tree make ARCH=i386
All errors (new ones prefixed by >>):
>> drivers//block/pktcdvd.c:2244:12: error: conflicting types for 'pkt_open'
static int pkt_open(struct block_device *bdev, fmode_t mode)
^~~~~~~~
In file included from include/linux/cgroup.h:18:0,
from include/linux/kthread.h:7,
from drivers//block/pktcdvd.c:54:
drivers//block/pktcdvd.c:455:23: note: previous definition of 'pkt_open' was here
DEFINE_SHOW_ATTRIBUTE(pkt);
^
include/linux/seq_file.h:149:12: note: in definition of macro 'DEFINE_SHOW_ATTRIBUTE'
static int __name ## _open(struct inode *inode, struct file *file) \
^~~~~~vim +/pkt_open +2244 drivers//block/pktcdvd.c
^1da177e Linus Torvalds 2005-04-16 2243
5e5e007c Al Viro 2008-03-02 @2244 static int pkt_open(struct block_device *bdev, fmode_t mode)
^1da177e Linus Torvalds 2005-04-16 2245 {
^1da177e Linus Torvalds 2005-04-16 2246 struct pktcdvd_device *pd = NULL;
^1da177e Linus Torvalds 2005-04-16 2247 int ret;
^1da177e Linus Torvalds 2005-04-16 2248
2a48fc0a Arnd Bergmann 2010-06-02 2249 mutex_lock(&pktcdvd_mutex);
1657f824 Jes Sorensen 2006-03-23 2250 mutex_lock(&ctl_mutex);
5e5e007c Al Viro 2008-03-02 2251 pd = pkt_find_dev_from_minor(MINOR(bdev->bd_dev));
^1da177e Linus Torvalds 2005-04-16 2252 if (!pd) {
^1da177e Linus Torvalds 2005-04-16 2253 ret = -ENODEV;
^1da177e Linus Torvalds 2005-04-16 2254 goto out;
^1da177e Linus Torvalds 2005-04-16 2255 }
^1da177e Linus Torvalds 2005-04-16 2256 BUG_ON(pd->refcnt < 0);
^1da177e Linus Torvalds 2005-04-16 2257
^1da177e Linus Torvalds 2005-04-16 2258 pd->refcnt++;
46f4e1b7 Peter Osterlund 2005-05-20 2259 if (pd->refcnt > 1) {
5e5e007c Al Viro 2008-03-02 2260 if ((mode & FMODE_WRITE) &&
46f4e1b7 Peter Osterlund 2005-05-20 2261 !test_bit(PACKET_WRITABLE, &pd->flags)) {
46f4e1b7 Peter Osterlund 2005-05-20 2262 ret = -EBUSY;
46f4e1b7 Peter Osterlund 2005-05-20 2263 goto out_dec;
46f4e1b7 Peter Osterlund 2005-05-20 2264 }
46f4e1b7 Peter Osterlund 2005-05-20 2265 } else {
5e5e007c Al Viro 2008-03-02 2266 ret = pkt_open_dev(pd, mode & FMODE_WRITE);
01fd9fda Peter Osterlund 2006-02-14 2267 if (ret)
^1da177e Linus Torvalds 2005-04-16 2268 goto out_dec;
^1da177e Linus Torvalds 2005-04-16 2269 /*
^1da177e Linus Torvalds 2005-04-16 2270 * needed here as well, since ext2 (among others) may change
^1da177e Linus Torvalds 2005-04-16 2271 * the blocksize at mount time
^1da177e Linus Torvalds 2005-04-16 2272 */
5e5e007c Al Viro 2008-03-02 2273 set_blocksize(bdev, CD_FRAMESIZE);
^1da177e Linus Torvalds 2005-04-16 2274 }
^1da177e Linus Torvalds 2005-04-16 2275
1657f824 Jes Sorensen 2006-03-23 2276 mutex_unlock(&ctl_mutex);
2a48fc0a Arnd Bergmann 2010-06-02 2277 mutex_unlock(&pktcdvd_mutex);
^1da177e Linus Torvalds 2005-04-16 2278 return 0;
^1da177e Linus Torvalds 2005-04-16 2279
^1da177e Linus Torvalds 2005-04-16 2280 out_dec:
^1da177e Linus Torvalds 2005-04-16 2281 pd->refcnt--;
^1da177e Linus Torvalds 2005-04-16 2282 out:
1657f824 Jes Sorensen 2006-03-23 2283 mutex_unlock(&ctl_mutex);
2a48fc0a Arnd Bergmann 2010-06-02 2284 mutex_unlock(&pktcdvd_mutex);
^1da177e Linus Torvalds 2005-04-16 2285 return ret;
^1da177e Linus Torvalds 2005-04-16 2286 }
^1da177e Linus Torvalds 2005-04-16 2287 :::::: The code at line 2244 was first introduced by commit :::::: 5e5e007c25009c304af693b7fc49bab8d1d25801 [PATCH] switch pktdvdcd
:::::: TO: Al Viro <[email protected]>
:::::: CC: Al Viro <[email protected]>
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Already sent the second edition.
Thanks,
Yangtao