git: 2c19cd6aeac0 - stable/14 - camcontrol: Don't close the CAM device in nvme_get_data()
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 16 Nov 2026 21:01:14 UTC
The branch stable/14 has been updated by ken:
URL: https://cgit.FreeBSD.org/src/commit/?id=2c19cd6aeac0c4883ee3335897c2613eea4da4f5
commit 2c19cd6aeac0c4883ee3335897c2613eea4da4f5
Author: Kenneth D. Merry <ken@FreeBSD.org>
AuthorDate: 2026-11-09 18:47:01 +0000
Commit: Kenneth D. Merry <ken@FreeBSD.org>
CommitDate: 2026-11-16 21:00:07 +0000
camcontrol: Don't close the CAM device in nvme_get_data()
nvme_get_data() closed the supplied CAM device on every error
path, but its callers either pass the device that main() opened
and closes, or close the device themselves, so an error resulted
in a double cam_close_device() and a double free. Move the error
path close into print_dev_nvme(), the one caller that opens its
own device, and leave the device alone in nvme_get_data().
This predates the recent camcontrol NVMe additions, but they added
more callers.
Reported by: llm-postcr
Fixes: 6ee13c54dad0
MFC after: 1 week
Sponsored by: Spectra Logic
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
(cherry picked from commit f7c24ef1e9a47b889eaaae8514c61e95d9738cf8)
---
sbin/camcontrol/camcontrol.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/sbin/camcontrol/camcontrol.c b/sbin/camcontrol/camcontrol.c
index 9b012b7df7ef..936df8d36994 100644
--- a/sbin/camcontrol/camcontrol.c
+++ b/sbin/camcontrol/camcontrol.c
@@ -810,7 +810,6 @@ nvme_get_data(struct cam_device *dev, int nvme_data_type, void *data,
ccb = cam_getccb(dev);
if (ccb == NULL) {
warnx("couldn't allocate CCB");
- cam_close_device(dev);
return (1);
}
@@ -837,7 +836,6 @@ nvme_get_data(struct cam_device *dev, int nvme_data_type, void *data,
return 0;
bailout_error:
- cam_close_device(dev);
return (1);
}
@@ -855,8 +853,10 @@ print_dev_nvme(struct device_match_result *dev_result, char *tmpstr)
return (1);
}
- if (nvme_get_data(dev, CDAI_TYPE_NVME_CNTRL, &cdata, sizeof(cdata)))
+ if (nvme_get_data(dev, CDAI_TYPE_NVME_CNTRL, &cdata, sizeof(cdata))) {
+ cam_close_device(dev);
return (1);
+ }
cam_strvis(vendor, cdata.mn, sizeof(cdata.mn), sizeof(vendor));
cam_strvis(product, cdata.fr, sizeof(cdata.fr), sizeof(product));