generic: platform/mikrotik: release mtd device after use
[openwrt/openwrt.git] / target / linux / generic / files / drivers / platform / mikrotik / rb_hardconfig.c
index e5257b921265ec63b9c8db28ef2fae3526ba4021..01cf46b668bfefde93087b3abad9ac6e14ab007e 100644 (file)
@@ -1,4 +1,4 @@
-// SPDX-License-Identifier: GPL-2.0
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * Driver for MikroTik RouterBoot hard config.
  *
@@ -495,7 +495,7 @@ static int hc_wlan_data_unpack_lzor(const u8 *inbuf, size_t inlen,
        /* Temporary buffer same size as the outbuf */
        templen = *outlen;
        tempbuf = kmalloc(templen, GFP_KERNEL);
-       if (!outbuf)
+       if (!tempbuf)
                return -ENOMEM;
 
        /* Concatenate into the outbuf */
@@ -682,10 +682,13 @@ int __init rb_hardconfig_init(struct kobject *rb_kobj)
 
        hc_buflen = mtd->size;
        hc_buf = kmalloc(hc_buflen, GFP_KERNEL);
-       if (!hc_buf)
+       if (!hc_buf) {
                return -ENOMEM;
+               put_mtd_device(mtd);
+       }
 
        ret = mtd_read(mtd, 0, hc_buflen, &bytes_read, hc_buf);
+       put_mtd_device(mtd);
 
        if (bytes_read != hc_buflen) {
                ret = -EIO;