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

mtd: docg3: dereferencing an ERR_PTR() in docg3_probe()

If doc_probe_device() returned an ERR_PTR, then we accidentally saved
that to docg3_floors[floor] = mtd; which gets derefenced in the error
handling when we call doc_release_device().

I've reworked the error handling to take care of that and hopefully
make it a little simpler.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Robert Jarzmik <robert.jarzmik@free.fr>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@linux.intel.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>

authored by

Dan Carpenter and committed by
David Woodhouse
b49e345e 5d3667ee

+12 -9
+12 -9
drivers/mtd/devices/docg3.c
··· 2027 2027 if (!docg3_bch) 2028 2028 goto nomem2; 2029 2029 2030 - ret = 0; 2031 2030 for (floor = 0; floor < DOC_MAX_NBFLOORS; floor++) { 2032 2031 mtd = doc_probe_device(base, floor, dev); 2033 - if (floor == 0 && !mtd) 2034 - goto notfound; 2035 - if (!IS_ERR_OR_NULL(mtd)) 2036 - ret = mtd_device_parse_register(mtd, part_probes, 2037 - NULL, NULL, 0); 2038 - else 2032 + if (IS_ERR(mtd)) { 2039 2033 ret = PTR_ERR(mtd); 2034 + goto err_probe; 2035 + } 2036 + if (!mtd) { 2037 + if (floor == 0) 2038 + goto notfound; 2039 + else 2040 + continue; 2041 + } 2040 2042 docg3_floors[floor] = mtd; 2043 + ret = mtd_device_parse_register(mtd, part_probes, NULL, NULL, 2044 + 0); 2041 2045 if (ret) 2042 2046 goto err_probe; 2043 - if (mtd) 2044 - found++; 2047 + found++; 2045 2048 } 2046 2049 2047 2050 ret = doc_register_sysfs(pdev, docg3_floors);