da(4): defend against calling sysctl_ctx_free on unininitalized
sysctl_ctx
Nate Lawson
nate at root.org
Tue Oct 7 11:38:37 PDT 2003
On Tue, 7 Oct 2003, Thomas Quinot wrote:
> The following change resolves a recently observed panic on probe of
> various USB mass storage devices. It is similar to the one I committed
> in scsi_cd.c rev 1.86. Please review!
>
> Thanks,
> Thomas.
>
> Index: scsi_da.c
> ===================================================================
> RCS file: /home/ncvs/src/sys/cam/scsi/scsi_da.c,v
> retrieving revision 1.159
> diff -u -r1.159 scsi_da.c
> --- scsi_da.c 4 Sep 2003 01:01:20 -0000 1.159
> +++ scsi_da.c 7 Oct 2003 14:48:26 -0000
> @@ -89,7 +89,8 @@
> DA_FLAG_NEED_OTAG = 0x020,
> DA_FLAG_WENT_IDLE = 0x040,
> DA_FLAG_RETRY_UA = 0x080,
> - DA_FLAG_OPEN = 0x100
> + DA_FLAG_OPEN = 0x100,
> + DA_FLAG_SCTX_INIT = 0x200
> } da_flags;
>
> typedef enum {
> @@ -838,7 +839,8 @@
> /*
> * If we can't free the sysctl tree, oh well...
> */
> - if (sysctl_ctx_free(&softc->sysctl_ctx) != 0) {
> + if ((softc->flags & DA_FLAG_SCTX_INIT) != 0
> + && sysctl_ctx_free(&softc->sysctl_ctx) != 0) {
> xpt_print_path(periph->path);
> printf("can't remove sysctl context\n");
> }
> @@ -925,6 +927,7 @@
>
> mtx_lock(&Giant);
> sysctl_ctx_init(&softc->sysctl_ctx);
> + softc->flags |= DA_FLAG_SCTX_INIT;
> softc->sysctl_tree = SYSCTL_ADD_NODE(&softc->sysctl_ctx,
> SYSCTL_STATIC_CHILDREN(_kern_cam_da), OID_AUTO, tmpstr2,
> CTLFLAG_RD, 0, tmpstr);
I'm ok with committing this, thanks for running it by me. Perhaps there's
a better way to signal whether the sysctl has been initialized though.
Perhaps a check for SYSCTL_CHILDREN != NULL or something? I've fought
with sysctl already this week and I'm not sure how to do that.
-Nate
More information about the freebsd-scsi
mailing list