Re: [PATCH v7 2/2] x86/sgx: Add an attribute for the amount of SGX memory in a NUMA node

From: Jarkko Sakkinen
Date: Mon Oct 18 2021 - 09:45:00 EST


On Fri, 2021-10-08 at 23:33 +0300, Jarkko Sakkinen wrote:
> +static void sgx_numa_exit(void)
> +{
> +       struct device *dev;
> +       int nid;
> +
> +       for (nid = 0; nid < num_possible_nodes(); nid++) {
> +               dev = &node_devices[nid]->dev;
> +               if (dev)
> +                       sysfs_remove_group(&dev->kobj, &sgx_node_attr_group);
> +       }
> +}
> +
> +static bool sgx_numa_init(void)
> +{
> +       struct sgx_numa_node *node;
> +       int nid;
> +       int ret;
> +
> +       for (nid = 0; nid < num_possible_nodes(); nid++) {
> +               if (!sgx_numa_nodes[nid].size)
> +                       continue;
> +
> +               node = &sgx_numa_nodes[nid];
> +               node->dev = &node_devices[nid]->dev;
> +
> +               ret = sysfs_create_group(&node->dev->kobj, &sgx_node_attr_group);
> +               if (ret) {
> +                       sgx_numa_exit();
> +                       return false;
> +               }
> +       }

Here's a mistake: node->dev should be only set after sysfe_create_group().
Otherwise, sysfs_remove_group() will issue a warning in sgx_numa_exit(), when
sgx_create_group() is unsuccessful, because the group does not exist.

I'll fix this, and send a new version.

/Jarkko