Re: [PATCH v8 08/18] nitro_enclaves: Add logic for creating an enclave VM

From: Greg KH
Date: Mon Sep 07 2020 - 04:57:08 EST


On Fri, Sep 04, 2020 at 08:37:08PM +0300, Andra Paraschiv wrote:
> +static long ne_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
> +{
> + switch (cmd) {
> + case NE_CREATE_VM: {
> + int enclave_fd = -1;
> + struct file *enclave_file = NULL;
> + struct ne_pci_dev *ne_pci_dev = NULL;
> + struct pci_dev *pdev = to_pci_dev(ne_misc_dev.parent);

That call is really "risky". You "know" that the misc device's parent
is a specific PCI device, that just happens to be your pci device,
right?

But why not just have your misc device hold the pointer to the structure
you really want, so you don't have to mess with the device tree in any
way, and you always "know" you have the correct pointer? It should save
you this two-step lookup all the time, right?

thanks,

greg k-h