]> git.ipfire.org Git - thirdparty/openwrt.git/commitdiff
rtl8367b: fix RTL8367S-VB vlan mc memory handling 23970/head
authorMieczyslaw Nalewaj <namiltd@yahoo.com>
Sat, 27 Jun 2026 15:13:09 +0000 (17:13 +0200)
committerJonas Jelonek <jelonek.jonas@gmail.com>
Sun, 28 Jun 2026 20:25:30 +0000 (22:25 +0200)
The RTL8367S-VB (Family D) uses a software-emulated VLAN MC table
(emu_vlanmc) since it lacks hardware support for the VLAN MC registers
used by earlier chips.

- Add missing NULL check after kzalloc() in rtl8367b_init_regs() to
  prevent NULL pointer dereference on allocation failure.
- Add missing kfree(smi->emu_vlanmc) in rtl8367b_remove() to prevent
  memory leak on driver unload.

Signed-off-by: Mieczyslaw Nalewaj <namiltd@yahoo.com>
Link: https://github.com/openwrt/openwrt/pull/23970
Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
target/linux/generic/files/drivers/net/phy/rtl8367b.c

index d3dc6af39a2ac6837d856b041bb703d1eb5712bb..850392cc7cc790906d18f6ec36bf29df05b6247b 100644 (file)
@@ -565,7 +565,11 @@ static int rtl8367b_init_regs(struct rtl8366_smi *smi)
                count = ARRAY_SIZE(rtl8367c_initvals);
                if ((smi->rtl8367b_chip == RTL8367B_CHIP_RTL8367S_VB) && (smi->emu_vlanmc == NULL)) {
                        smi->emu_vlanmc = kzalloc(sizeof(struct rtl8366_vlan_mc) * smi->num_vlan_mc, GFP_KERNEL);
-                       dev_info(smi->parent, "alloc vlan mc emulator");
+                       if (!smi->emu_vlanmc) {
+                               dev_err(smi->parent, "failed to allocate vlan mc emulator\n");
+                               return -ENOMEM;
+                       }
+                       dev_info(smi->parent, "alloc vlan mc emulator\n");
                }
                break;
        default:
@@ -1586,6 +1590,7 @@ static void rtl8367b_remove(struct platform_device *pdev)
                rtl8367b_switch_cleanup(smi);
                platform_set_drvdata(pdev, NULL);
                rtl8366_smi_cleanup(smi);
+               kfree(smi->emu_vlanmc);
                kfree(smi);
        }
 }