All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Dmitry Baryshkov <dbaryshkov@gmail.com>
Cc: linux-kernel@vger.kernel.org, gregkh@suse.de, dbaryshkov@gmail.com
Subject: Re: [PATCH] platform: add new device registration helper
Date: Thu, 4 Sep 2008 17:20:50 -0700	[thread overview]
Message-ID: <20080904172050.cbde3013.akpm@linux-foundation.org> (raw)
In-Reply-To: <1220563816-8106-1-git-send-email-dbaryshkov@gmail.com>

On Fri,  5 Sep 2008 01:30:16 +0400
Dmitry Baryshkov <dbaryshkov@gmail.com> wrote:

> Add a helper that registers simple platform_device
> w/o resources but with parent and device data.
> 
> This is usefull to cleanup platform code from code that
> registers such simple devices as leds-gpio, generic-bl,
> etc.
> 

nits:

>  include/linux/platform_device.h |    2 +
>  2 files changed, 49 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> index 3f94039..fcd9f97 100644
> --- a/drivers/base/platform.c
> +++ b/drivers/base/platform.c
> @@ -391,6 +391,53 @@ error:
>  }
>  EXPORT_SYMBOL_GPL(platform_device_register_simple);
>  
> +/**
> + * platform_device_register_data
> + * @parent: parent device for the device we're adding
> + * @name: base name of the device we're adding
> + * @id: instance id
> + * @data: platform specific data for this platform device
> + * @size: size of platform specific data
> + *
> + * This function creates a simple platform device that requires minimal
> + * resource and memory management. Canned release function freeing memory
> + * allocated for the device allows drivers using such devices to be
> + * unloaded without waiting for the last reference to the device to be
> + * dropped.

Should document the return value (tested with IS_ERR)

> + */
> +struct platform_device *platform_device_register_data(
> +		struct device *parent,
> +		const char *name, int id,
> +		const void *data, size_t size)

Something like

struct platform_device *platform_device_register_data(struct device *parent,
			const char *name, int id, const void *data, size_t size)

would be more typical.  

> +{
> +	struct platform_device *pdev;
> +	int retval;
> +
> +	pdev = platform_device_alloc(name, id);
> +	if (!pdev) {
> +		retval = -ENOMEM;
> +		goto error;
> +	}
> +
> +	pdev->dev.parent = parent;
> +
> +	if (size) {
> +		retval = platform_device_add_data(pdev, data, size);
> +		if (retval)
> +			goto error;
> +	}
> +
> +	retval = platform_device_add(pdev);
> +	if (retval)
> +		goto error;
> +
> +	return pdev;
> +
> +error:
> +	platform_device_put(pdev);

Are you sure this can't trigger a !kobj->state_initialized warning in
kobject_put()?

> +	return ERR_PTR(retval);
> +}
> +
>
> ...
>
> +extern struct platform_device *platform_device_register_data(struct device *,
> +		const char *, int, const void *, size_t);

It's nice (IMO) to include the names of the args, for documentation
purposes.  Obviously the surrounding code didn't agree.


  reply	other threads:[~2008-09-05  0:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-04 21:30 [PATCH] platform: add new device registration helper Dmitry Baryshkov
2008-09-05  0:20 ` Andrew Morton [this message]
2008-09-05 10:33   ` Dmitry Baryshkov
2008-09-05 18:09     ` Andrew Morton
2008-09-05  0:23 ` Andrew Morton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080904172050.cbde3013.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=dbaryshkov@gmail.com \
    --cc=gregkh@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.