Skip to content

Commit d5686b4

Browse files
author
Al Viro
committed
[PATCH] switch mtd and dm-table to lookup_bdev()
No need to open-code it... Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent a95164d commit d5686b4

3 files changed

Lines changed: 18 additions & 45 deletions

File tree

‎drivers/md/dm-table.c‎

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -316,29 +316,12 @@ static inline int check_space(struct dm_table *t)
316316
*/
317317
static int lookup_device(const char *path, dev_t *dev)
318318
{
319-
int r;
320-
struct nameidata nd;
321-
struct inode *inode;
322-
323-
if ((r = path_lookup(path, LOOKUP_FOLLOW, &nd)))
324-
return r;
325-
326-
inode = nd.path.dentry->d_inode;
327-
if (!inode) {
328-
r = -ENOENT;
329-
goto out;
330-
}
331-
332-
if (!S_ISBLK(inode->i_mode)) {
333-
r = -ENOTBLK;
334-
goto out;
335-
}
336-
337-
*dev = inode->i_rdev;
338-
339-
out:
340-
path_put(&nd.path);
341-
return r;
319+
struct block_device *bdev = lookup_bdev(path);
320+
if (IS_ERR(bdev))
321+
return PTR_ERR(bdev);
322+
*dev = bdev->bd_dev;
323+
bdput(bdev);
324+
return 0;
342325
}
343326

344327
/*

‎drivers/mtd/mtdsuper.c‎

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ int get_sb_mtd(struct file_system_type *fs_type, int flags,
125125
int (*fill_super)(struct super_block *, void *, int),
126126
struct vfsmount *mnt)
127127
{
128-
struct nameidata nd;
128+
struct block_device *bdev;
129129
int mtdnr, ret;
130130

131131
if (!dev_name)
@@ -181,29 +181,20 @@ int get_sb_mtd(struct file_system_type *fs_type, int flags,
181181
/* try the old way - the hack where we allowed users to mount
182182
* /dev/mtdblock$(n) but didn't actually _use_ the blockdev
183183
*/
184-
ret = path_lookup(dev_name, LOOKUP_FOLLOW, &nd);
185-
186-
DEBUG(1, "MTDSB: path_lookup() returned %d, inode %p\n",
187-
ret, nd.path.dentry ? nd.path.dentry->d_inode : NULL);
188-
189-
if (ret)
184+
bdev = lookup_bdev(dev_name);
185+
if (IS_ERR(bdev)) {
186+
ret = PTR_ERR(bdev);
187+
DEBUG(1, "MTDSB: lookup_bdev() returned %d\n", ret);
190188
return ret;
191-
192-
ret = -EINVAL;
193-
194-
if (!S_ISBLK(nd.path.dentry->d_inode->i_mode))
195-
goto out;
196-
197-
if (nd.path.mnt->mnt_flags & MNT_NODEV) {
198-
ret = -EACCES;
199-
goto out;
200189
}
190+
DEBUG(1, "MTDSB: lookup_bdev() returned 0\n");
201191

202-
if (imajor(nd.path.dentry->d_inode) != MTD_BLOCK_MAJOR)
192+
ret = -EINVAL;
193+
if (MAJOR(bdev->bd_dev) != MTD_BLOCK_MAJOR)
203194
goto not_an_MTD_device;
204195

205-
mtdnr = iminor(nd.path.dentry->d_inode);
206-
path_put(&nd.path);
196+
mtdnr = MINOR(bdev->bd_dev);
197+
bdput(bdev);
207198

208199
return get_sb_mtd_nr(fs_type, flags, dev_name, data, mtdnr, fill_super,
209200
mnt);
@@ -213,10 +204,8 @@ int get_sb_mtd(struct file_system_type *fs_type, int flags,
213204
printk(KERN_NOTICE
214205
"MTD: Attempt to mount non-MTD device \"%s\"\n",
215206
dev_name);
216-
out:
217-
path_put(&nd.path);
207+
bdput(bdev);
218208
return ret;
219-
220209
}
221210

222211
EXPORT_SYMBOL_GPL(get_sb_mtd);

‎fs/block_dev.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,6 +1236,7 @@ struct block_device *lookup_bdev(const char *path)
12361236
bdev = ERR_PTR(error);
12371237
goto out;
12381238
}
1239+
EXPORT_SYMBOL(lookup_bdev);
12391240

12401241
/**
12411242
* open_bdev_excl - open a block device by name and set it up for use

0 commit comments

Comments
 (0)