diff --git a/target/linux/generic/files/drivers/net/phy/rtl8366rb.c b/target/linux/generic/files/drivers/net/phy/rtl8366rb.c
index a0a7df794cc1d42684d88071c970c349d65047d1..ec196f941be079cbc96b719a12c3d46242797972 100644
--- a/target/linux/generic/files/drivers/net/phy/rtl8366rb.c
+++ b/target/linux/generic/files/drivers/net/phy/rtl8366rb.c
@@ -554,7 +554,12 @@ static int rtl8366rb_set_mc_index(struct rtl8366_smi *smi, int port, int index)
 
 static int rtl8366rb_is_vlan_valid(struct rtl8366_smi *smi, unsigned vlan)
 {
-	if (vlan == 0 || vlan >= RTL8366RB_NUM_VLANS)
+	unsigned max = RTL8366RB_NUM_VLANS;
+
+	if (smi->vlan4k_enabled)
+		max = RTL8366RB_NUM_VIDS - 1;
+
+	if (vlan == 0 || vlan >= max)
 		return 0;
 
 	return 1;
@@ -882,7 +887,7 @@ static int rtl8366rb_switch_init(struct rtl8366_smi *smi)
 	dev->name = "RTL8366RB";
 	dev->cpu_port = RTL8366RB_PORT_NUM_CPU;
 	dev->ports = RTL8366RB_NUM_PORTS;
-	dev->vlans = RTL8366RB_NUM_VLANS;
+	dev->vlans = RTL8366RB_NUM_VIDS;
 	dev->ops = &rtl8366_ops;
 	dev->devname = dev_name(smi->parent);
 
diff --git a/target/linux/generic/files/drivers/net/phy/rtl8366s.c b/target/linux/generic/files/drivers/net/phy/rtl8366s.c
index 896333c93ca95e7830cfb9f96d6017ab94986197..66dc2db0df087db53684cc19945a0121f0481e5f 100644
--- a/target/linux/generic/files/drivers/net/phy/rtl8366s.c
+++ b/target/linux/generic/files/drivers/net/phy/rtl8366s.c
@@ -593,7 +593,12 @@ static int rtl8366s_enable_vlan4k(struct rtl8366_smi *smi, int enable)
 
 static int rtl8366s_is_vlan_valid(struct rtl8366_smi *smi, unsigned vlan)
 {
-	if (vlan == 0 || vlan >= RTL8366S_NUM_VLANS)
+	unsigned max = RTL8366S_NUM_VLANS;
+
+	if (smi->vlan4k_enabled)
+		max = RTL8366S_NUM_VIDS - 1;
+
+	if (vlan == 0 || vlan >= max)
 		return 0;
 
 	return 1;
@@ -909,7 +914,7 @@ static int rtl8366s_switch_init(struct rtl8366_smi *smi)
 	dev->name = "RTL8366S";
 	dev->cpu_port = RTL8366S_PORT_NUM_CPU;
 	dev->ports = RTL8366S_NUM_PORTS;
-	dev->vlans = RTL8366S_NUM_VLANS;
+	dev->vlans = RTL8366S_NUM_VIDS;
 	dev->ops = &rtl8366_ops;
 	dev->devname = dev_name(smi->parent);