struct virt_dma_desc vdesc;
        bool cyclic;
        u32 num_sgs;
-       struct stm32_dma_sg_req sg_req[];
+       struct stm32_dma_sg_req sg_req[] __counted_by(num_sgs);
 };
 
 /**
        desc = kzalloc(struct_size(desc, sg_req, sg_len), GFP_NOWAIT);
        if (!desc)
                return NULL;
+       desc->num_sgs = sg_len;
 
        /* Set peripheral flow controller */
        if (chan->dma_sconfig.device_fc)
                        desc->sg_req[i].chan_reg.dma_sm1ar += sg_dma_len(sg);
                desc->sg_req[i].chan_reg.dma_sndtr = nb_data_items;
        }
-
-       desc->num_sgs = sg_len;
        desc->cyclic = false;
 
        return vchan_tx_prep(&chan->vchan, &desc->vdesc, flags);
        desc = kzalloc(struct_size(desc, sg_req, num_periods), GFP_NOWAIT);
        if (!desc)
                return NULL;
+       desc->num_sgs = num_periods;
 
        for (i = 0; i < num_periods; i++) {
                desc->sg_req[i].len = period_len;
                if (!chan->trig_mdma)
                        buf_addr += period_len;
        }
-
-       desc->num_sgs = num_periods;
        desc->cyclic = true;
 
        return vchan_tx_prep(&chan->vchan, &desc->vdesc, flags);
        desc = kzalloc(struct_size(desc, sg_req, num_sgs), GFP_NOWAIT);
        if (!desc)
                return NULL;
+       desc->num_sgs = num_sgs;
 
        threshold = chan->threshold;
 
                desc->sg_req[i].chan_reg.dma_sndtr = xfer_count;
                desc->sg_req[i].len = xfer_count;
        }
-
-       desc->num_sgs = num_sgs;
        desc->cyclic = false;
 
        return vchan_tx_prep(&chan->vchan, &desc->vdesc, flags);