Subject: Re: [PATCH 3/5] ibmebus: Add device creation and bus probing based on of_device

From: Arnd Bergmann <[email-masked]>
Date: Tue, 25 Sep 2007 16:39:05 +0200

On Tuesday 25 September 2007, Joachim Fenkes wrote:
> The devtree root is now searched for devices matching a built-in whitelist
> during boot, so these devices appear on the bus from the beginning. It is
> still possible to manually add/remove devices to/from the bus by using the
> probe/remove sysfs interface. Also, when a device driver registers itself,
> the devtree is matched against its matchlist.
> 
> Signed-off-by: Joachim Fenkes <[email-masked]>
> ---
>  arch/powerpc/kernel/ibmebus.c |   97 ++++++++++++++++++++++++++++++++++-------
>  1 files changed, 81 insertions(+), 16 deletions(-)
> 
> diff --git a/arch/powerpc/kernel/ibmebus.c b/arch/powerpc/kernel/ibmebus.c
> index cc80f84..c506e0d 100644
> --- a/arch/powerpc/kernel/ibmebus.c
> +++ b/arch/powerpc/kernel/ibmebus.c
> @@ -51,6 +51,15 @@ static struct device ibmebus_bus_device = { /* fake "parent" device */
>  
>  struct bus_type ibmebus_bus_type;
>  
> +/* These devices will automatically be added to the bus during init */
> +static struct of_device_id builtin_matches[] = {
> +	{ .name = "lhca" },
> +	{ .compatible = "IBM,lhca" },
> +	{ .name = "lhea" },
> +	{ .compatible = "IBM,lhea" },
> +	{},
> +};
> +

Hmm, do you have devices that only have the matching name property
but not the compatible property? If not, I'd suggest only looking
for compatible, so you have less chance of false positives.

> +static int ibmebus_create_device(struct device_node *dn)
> +{
> +	struct of_device *dev;
> +	int ret;
> +
> +	dev = of_device_alloc(dn, NULL, &ibmebus_bus_device);
> +	if (!dev)
> +		return -ENOMEM;
> +
> +	dev->dev.bus = &ibmebus_bus_type;
> +	dev->dev.archdata.dma_ops = &ibmebus_dma_ops;
> +
> +	ret = of_device_register(dev);
> +	if (ret) {
> +		of_device_free(dev);
> +		return ret;
> +	}
> +
> +	return 0;
> +}

nice!

> @@ -219,9 +276,9 @@ static ssize_t ibmebus_store_probe(struct bus_type *bus,
>  	}
>  
>  	if ((dn = of_find_node_by_path(path))) {
> -/*		dev = ibmebus_register_device_node(dn); */
> +		rc = ibmebus_create_device(dn);
>  		of_node_put(dn);
> -		rc = IS_ERR(dev) ? PTR_ERR(dev) : count;
> +		rc = rc ? rc : count;

the last line looks a bit silly. Maybe instead do

		rc = ibmebus_create_device(dn);
  		of_node_put(dn);
	}

	kfree(path);
	if (rc)
		return rc;
	return count;
}