Re: [PATCH v3 1/2] firmware: google: Expose CBMEM over sysfs

Greg Kroah-Hartman
2019-12-19T17:17:11Z

On Thu, Nov 28, 2019 at 01:50:50PM +0100, patrick.rudolph@9elements.com wrote:
> +static int cbmem_probe(struct coreboot_device *cdev)
> +{
> + struct device *dev = &cdev->dev;
> + struct cb_priv *priv;
> + int err;
> +
> + priv = kzalloc(sizeof(*priv), GFP_KERNEL);
> + if (!priv)
> + return -ENOMEM;
> +
> + memcpy(&priv->entry, &cdev->cbmem_entry, sizeof(priv->entry));
> +
> + priv->remap = memremap(priv->entry.address,
> + priv->entry.entry_size, MEMREMAP_WB);
> + if (!priv->remap) {
> + err = -ENOMEM;
> + goto failure;
> + }
> +
> + err = sysfs_create_group(&dev->kobj, &cb_mem_attr_group);

You just raced with userspace and lost :(

Set the driver's default attribute group up to point at
cb_mem_attr_group and the driver core will handle creating and removing
the group automatically for you correctly.

thanks,

greg k-h