aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/ubi
diff options
context:
space:
mode:
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2010-01-05 10:25:59 -0500
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2010-01-12 06:19:15 -0500
commitb531b55a7bde8aa2bdf7023b3afc6df1bf3dcb67 (patch)
treed6045d623d645f6481ae5b1cab5e8288d293f345 /drivers/mtd/ubi
parentff998793288b49a3b22d929bf8e56362320905ff (diff)
UBI: add more checks to chdev open
When opening UBI volumes by their character device names, make sure we are opening character devices, not block devices or any other inode type. Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Diffstat (limited to 'drivers/mtd/ubi')
-rw-r--r--drivers/mtd/ubi/kapi.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/drivers/mtd/ubi/kapi.c b/drivers/mtd/ubi/kapi.c
index 277786ebaa2c..1361574e2b00 100644
--- a/drivers/mtd/ubi/kapi.c
+++ b/drivers/mtd/ubi/kapi.c
@@ -291,8 +291,7 @@ EXPORT_SYMBOL_GPL(ubi_open_volume_nm);
291 */ 291 */
292struct ubi_volume_desc *ubi_open_volume_path(const char *pathname, int mode) 292struct ubi_volume_desc *ubi_open_volume_path(const char *pathname, int mode)
293{ 293{
294 int error, ubi_num, vol_id; 294 int error, ubi_num, vol_id, mod;
295 struct ubi_volume_desc *ret;
296 struct inode *inode; 295 struct inode *inode;
297 struct path path; 296 struct path path;
298 297
@@ -306,16 +305,16 @@ struct ubi_volume_desc *ubi_open_volume_path(const char *pathname, int mode)
306 return ERR_PTR(error); 305 return ERR_PTR(error);
307 306
308 inode = path.dentry->d_inode; 307 inode = path.dentry->d_inode;
308 mod = inode->i_mode;
309 ubi_num = ubi_major2num(imajor(inode)); 309 ubi_num = ubi_major2num(imajor(inode));
310 vol_id = iminor(inode) - 1; 310 vol_id = iminor(inode) - 1;
311 path_put(&path);
311 312
313 if (!S_ISCHR(mod))
314 return ERR_PTR(-EINVAL);
312 if (vol_id >= 0 && ubi_num >= 0) 315 if (vol_id >= 0 && ubi_num >= 0)
313 ret = ubi_open_volume(ubi_num, vol_id, mode); 316 return ubi_open_volume(ubi_num, vol_id, mode);
314 else 317 return ERR_PTR(-ENODEV);
315 ret = ERR_PTR(-ENODEV);
316
317 path_put(&path);
318 return ret;
319} 318}
320EXPORT_SYMBOL_GPL(ubi_open_volume_path); 319EXPORT_SYMBOL_GPL(ubi_open_volume_path);
321 320