diff --git a/hw/qxl.c b/hw/qxl.c
index 4c68769..458b9fc 100644
--- a/hw/qxl.c
+++ b/hw/qxl.c
@@ -322,7 +322,7 @@ static void init_qxl_rom(PCIQXLDevice *d)
     rom->slots_end     = NUM_MEMSLOTS - 1;
     rom->n_surfaces    = cpu_to_le32(NUM_SURFACES);
 
-    for (i = 0; i < modes->n_modes; i++) {
+    for (i = 0; i < ARRAY_SIZE(qxl_modes); i++) {
         fb = qxl_modes[i].y_res * qxl_modes[i].stride;
         if (fb <= d->vgamem_size) {
             n_modes++;
