From 13db17bd1fcd68b5e5618fcd051ff4137f1ea413 Mon Sep 17 00:00:00 2001 From: Mike Lovell Date: Wed, 18 May 2016 12:23:13 -0600 Subject: Use dev_t for devnm2devid and devid2devnm Commit 4dd2df0966ec added a trip through makedev(), major(), and minor() for device major and minor numbers. This would cause mdadm to fail in operating on a device with a minor number bigger than (2^19)-1 due to it changing from dev_t to a signed int and back. Where this was found as a problem was when a array was created with a device specified as a name like /dev/md/raidname and there were already 128 arrays on the system. In this case, mdadm would chose 1048575 ((2^20)-1) for the array and minor number. This would cause the major and minor number to become negative when generated from devnm2devid() and passed to major() and minor() in open_dev_excl(). open_dev_excl() would then call dev_open() which would detect the negative minor number and call open() on the *char containing the major:minor pair which isn't a valid file. Signed-off-by: Mike Lovell Signed-off-by: Jes Sorensen --- mdopen.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'mdopen.c') diff --git a/mdopen.c b/mdopen.c index 28410f46..e71d7586 100644 --- a/mdopen.c +++ b/mdopen.c @@ -348,7 +348,7 @@ int create_mddev(char *dev, char *name, int autof, int trustworthy, if (lstat(devname, &stb) == 0) { /* Must be the correct device, else error */ if ((stb.st_mode&S_IFMT) != S_IFBLK || - stb.st_rdev != (dev_t)devnm2devid(devnm)) { + stb.st_rdev != devnm2devid(devnm)) { pr_err("%s exists but looks wrong, please fix\n", devname); return -1; @@ -452,7 +452,7 @@ char *find_free_devnm(int use_partitions) if (!use_udev()) { /* make sure it is new to /dev too, at least as a * non-standard */ - int devid = devnm2devid(devnm); + dev_t devid = devnm2devid(devnm); if (devid) { char *dn = map_dev(major(devid), minor(devid), 0); -- cgit v1.2.3