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

From: Greg Kroah-Hartman
Date: Thu Dec 19 2019 - 12:17:11 EST


On Thu, Nov 28, 2019 at 01:50:50PM +0100, patrick.rudolph@xxxxxxxxxxxxx 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