The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=5102c5f1134281aadea878a61cfe4967cab0eb9e
commit 5102c5f1134281aadea878a61cfe4967cab0eb9e Author: Warner Losh <i...@freebsd.org> AuthorDate: 2025-07-07 20:05:10 +0000 Commit: Warner Losh <i...@freebsd.org> CommitDate: 2025-07-07 23:17:00 +0000 cam: Create free_scan_info helper function We free the scsi bug scan info in 4 places. 1 was wrong until I fixed a bug there in a recent commit. Introduce a helper function that will free the cpi always (it must always be valid since we set it right after allocation). Sponsored by: Netflix Reviewed by: jhb Differential Revision: https://reviews.freebsd.org/D51170 --- sys/cam/scsi/scsi_xpt.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/sys/cam/scsi/scsi_xpt.c b/sys/cam/scsi/scsi_xpt.c index 2506a9fba799..1dd149b00a87 100644 --- a/sys/cam/scsi/scsi_xpt.c +++ b/sys/cam/scsi/scsi_xpt.c @@ -1915,6 +1915,15 @@ typedef struct { int lunindex[0]; } scsi_scan_bus_info; +static void +free_scan_info(scsi_scan_bus_info *scan_info) +{ + KASSERT(scan_info->cpi != NULL, + ("scan_info (%p) missing its ccb_pathinq CCB\n", scan_info)); + xpt_free_ccb((union ccb *)scan_info->cpi); + free(scan_info, M_CAMXPT); +} + /* * To start a scan, request_ccb is an XPT_SCAN_BUS ccb. * As the scan progresses, scsi_scan_bus is used as the @@ -2034,16 +2043,14 @@ scsi_scan_bus(struct cam_periph *periph, union ccb *request_ccb) printf( "scsi_scan_bus: xpt_create_path failed with status %#x, bus scan halted\n", status); - xpt_free_ccb((union ccb *)scan_info->cpi); - free(scan_info, M_CAMXPT); + free_scan_info(scan_info); request_ccb->ccb_h.status = status; xpt_done(request_ccb); break; } work_ccb = xpt_alloc_ccb_nowait(); if (work_ccb == NULL) { - xpt_free_ccb((union ccb *)scan_info->cpi); - free(scan_info, M_CAMXPT); + free_scan_info(scan_info); xpt_free_path(path); request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL; xpt_done(request_ccb); @@ -2205,12 +2212,11 @@ scsi_scan_bus(struct cam_periph *periph, union ccb *request_ccb) if (done) { mtx_unlock(mtx); xpt_free_ccb(request_ccb); - xpt_free_ccb((union ccb *)scan_info->cpi); request_ccb = scan_info->request_ccb; CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("SCAN done for %p\n", scan_info)); - free(scan_info, M_CAMXPT); + free_scan_info(scan_info); request_ccb->ccb_h.status = CAM_REQ_CMP; xpt_done(request_ccb); break; @@ -2230,9 +2236,8 @@ scsi_scan_bus(struct cam_periph *periph, union ccb *request_ccb) "scsi_scan_bus: xpt_create_path failed with status %#x, bus scan halted\n", status); xpt_free_ccb(request_ccb); - xpt_free_ccb((union ccb *)scan_info->cpi); request_ccb = scan_info->request_ccb; - free(scan_info, M_CAMXPT); + free_scan_info(scan_info); request_ccb->ccb_h.status = status; xpt_done(request_ccb); break;