Jonathan Cameron wrote: [..] > > > > diff --git a/drivers/pci/tsm.c b/drivers/pci/tsm.c > > > > new file mode 100644 > > > > index 000000000000..0784cc436dd3 > > > > --- /dev/null > > > > +++ b/drivers/pci/tsm.c > > > > @@ -0,0 +1,554 @@ > > > > +// SPDX-License-Identifier: GPL-2.0 > > > > +/* > > > > + * TEE Security Manager for the TEE Device Interface Security Protocol > > > > + * (TDISP, PCIe r6.1 sec 11) > > > > + * > > > > + * Copyright(c) 2024 Intel Corporation. All rights reserved. > > > > + */ > > > > > > > +static void tsm_remove(struct pci_tsm *tsm) > > > > +{ > > > > + struct pci_dev *pdev; > > > > + > > > > + if (!tsm) > > > > > > You protect against this in the DEFINE_FREE() so probably safe > > > to assume it is always set if we get here. > > > > It is safe, but I would rather not require reading other code to > > understand the expectation that some callers may unconditionally call > > this routine. > > I think a function like remove being called on 'nothing' should > pretty much always be a bug, but meh, up to you. I should have noted earlier that tsm_probe() on subfunctions might fail without failing the 'connect' operation and unwinding the subfunctions that did probe successfully. tsm_probe() should rarely fail, it is just subject to kmalloc(GFP_KERNEL) failure in most cases. So at shutdown time tsm_remove() will opportunistically cleanup just the subfunctions that probed.