diff options
author | mjacob <mjacob@FreeBSD.org> | 2006-04-18 21:53:39 +0000 |
---|---|---|
committer | mjacob <mjacob@FreeBSD.org> | 2006-04-18 21:53:39 +0000 |
commit | 95a4830dbc9a89e2734021716e83a9012f2f55bf (patch) | |
tree | 964060dcf107ec18c7c874591ddae4e755351e9f /sys/cam/cam.c | |
parent | 620eff6c1c7757283220b4adf082fcbf4dfb9c24 (diff) | |
download | FreeBSD-src-95a4830dbc9a89e2734021716e83a9012f2f55bf.zip FreeBSD-src-95a4830dbc9a89e2734021716e83a9012f2f55bf.tar.gz |
Do more guarding against zero divide traps for the geom subroutine.
Diffstat (limited to 'sys/cam/cam.c')
-rw-r--r-- | sys/cam/cam.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/sys/cam/cam.c b/sys/cam/cam.c index 9fbdac7..cc438bf 100644 --- a/sys/cam/cam.c +++ b/sys/cam/cam.c @@ -373,7 +373,16 @@ cam_calc_geometry(struct ccb_calc_geometry *ccg, int extended) { uint32_t size_mb, secs_per_cylinder; - size_mb = ccg->volume_size / ((1024L * 1024L) / ccg->block_size); + if (ccg->block_size == 0) { + ccg->ccb_h.status = CAM_REQ_CMP_ERR; + return; + } + size_mb = (1024L * 1024L) / ccg->block_size; + if (size_mb == 0) { + ccg->ccb_h.status = CAM_REQ_CMP_ERR; + return; + } + size_mb = ccg->volume_size / size_mb; if (size_mb > 1024 && extended) { ccg->heads = 255; ccg->secs_per_track = 63; @@ -382,6 +391,10 @@ cam_calc_geometry(struct ccb_calc_geometry *ccg, int extended) ccg->secs_per_track = 32; } secs_per_cylinder = ccg->heads * ccg->secs_per_track; + if (secs_per_cylinder == 0) { + ccg->ccb_h.status = CAM_REQ_CMP_ERR; + return; + } ccg->cylinders = ccg->volume_size / secs_per_cylinder; ccg->ccb_h.status = CAM_REQ_CMP; } |