cam_xpt: Properly fail if a sim uses an unsupported transport.

The default xport ops for a new bus is xport_default, not NULL, so
check for that when determining if a bus failed to find a suitable
transport.  In addition, the path needs to be freed with xpt_free_path
instead of a plain free so that the path's reference on the sim is
dropped; otherwise, cam_sim_free in the caller after xpt_bus_register
returns failure will hang forever.

Note that we have to exempt the xpt bus from this check as it uses
xport_default on purpose.

Reviewed by:	mav, imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D40617
This commit is contained in:
John Baldwin 2023-06-26 20:33:25 -07:00
parent 9c2203a691
commit e932f0d2a3

View file

@ -4018,7 +4018,14 @@ xpt_bus_register(struct cam_sim *sim, device_t parent, uint32_t bus)
xpt_path_inq(&cpi, path);
if (cam_ccb_success((union ccb *)&cpi)) {
/*
* Use the results of PATH_INQ to pick a transport. Note that
* the xpt bus (which uses XPORT_UNSPECIFIED) always uses
* xport_default instead of a transport from
* cam_xpt_port_set.
*/
if (cam_ccb_success((union ccb *)&cpi) &&
cpi.transport != XPORT_UNSPECIFIED) {
struct xpt_xport **xpt;
SET_FOREACH(xpt, cam_xpt_xport_set) {
@ -4027,11 +4034,11 @@ xpt_bus_register(struct cam_sim *sim, device_t parent, uint32_t bus)
break;
}
}
if (new_bus->xport == NULL) {
if (new_bus->xport == &xport_default) {
xpt_print(path,
"No transport found for %d\n", cpi.transport);
xpt_release_bus(new_bus);
free(path, M_CAMXPT);
xpt_free_path(path);
return (EINVAL);
}
}