diff --git a/sys/bus/cam/scsi/scsi_da.c b/sys/bus/cam/scsi/scsi_da.c --- a/sys/bus/cam/scsi/scsi_da.c +++ b/sys/bus/cam/scsi/scsi_da.c @@ -1346,6 +1346,15 @@ int c = min(count, 0xffff); int off = ranges * 8; + if (ranges >= softc->trim_max_ranges) { + /* + * The TRIM data buffer is full. + * Stop filling to avoid + * overflowing req->data[]. + */ + break; + } + req->data[off + 0] = lba & 0xff; req->data[off + 1] = (lba >> 8) & 0xff; req->data[off + 2] = (lba >> 16) & 0xff;