All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anton Vorontsov <anton-9xeibp6oKSgdnm+yROfE0A@public.gmane.org>
To: Rhyland Klein <rklein-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
Cc: Grant Likely
	<grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>,
	David Woodhouse <dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>,
	devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [REPOST Patch v1 3/3] power: power_supply_core: Add support for supplied_from
Date: Sat, 30 Mar 2013 15:41:17 -0700	[thread overview]
Message-ID: <20130330224117.GA24610@lizard> (raw)
In-Reply-To: <1364264690-2124-4-git-send-email-rklein-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>

On Mon, Mar 25, 2013 at 10:24:50PM -0400, Rhyland Klein wrote:
[...]
> +int power_supply_find_supply_from_node(struct device_node *supply_node)
> +{
> +	int error;
> +	struct device *dev;
> +	struct class_dev_iter iter;
> +
> +	/* Use iterator to see if any other device is registered.
> +	 * This is required since class_for_each_device returns 0
> +	 * if there are no devices registered.
> +	 */

Minor nit: can you please adhere to the canonical style for the multiline
comments?

> +	class_dev_iter_init(&iter, power_supply_class, NULL, NULL);
> +	dev = class_dev_iter_next(&iter);
> +
> +	if (!dev)
> +		return -EPROBE_DEFER;
> +
> +	/* we have to treat the return value as inverted, because if
> +	 * we return error on not found, then it won't continue looking.
> +	 * So we trick it by returning error on success to stop looking
> +	 * once the matching device is found.
> +	 */

Ditto.

> +	error = class_for_each_device(power_supply_class, NULL, supply_node,
> +				       __power_supply_find_supply_from_node);
> +
> +	return error ? 0 : -EPROBE_DEFER;
> +}
> +
> +int power_supply_check_supplies(struct power_supply *psy)
> +{
> +	struct device_node *np;
> +	int cnt = 0;
> +	int ret = 0;
> +
> +	/* If there is already a list honor it */
> +	if (psy->supplied_from && psy->num_supplies > 0)
> +		return 0;
> +
> +	/* No device node found, nothing to do */
> +	if (!psy->of_node)
> +		return 0;
> +
> +	do {

You can move 'int ret;' here (without initializer).

> +		np = of_parse_phandle(psy->of_node, "power-supplies", cnt++);
> +		if (!np)
> +			continue;
> +
> +		ret = power_supply_find_supply_from_node(np);
> +		if (ret) {
> +			dev_dbg(psy->dev, "Failed to find supply, defer!\n");
> +			return -EPROBE_DEFER;
> +		}
> +	} while (np);
> +
> +	/* All supplies found, allocate char ** array for filling */
> +	psy->supplied_from = devm_kzalloc(psy->dev, sizeof(psy->supplied_from),
> +					  GFP_KERNEL);
> +	if (!psy->supplied_from) {
> +		dev_err(psy->dev, "Couldn't allocate memory for supply list\n");
> +		return -ENOMEM;
> +	}
> +
> +	*psy->supplied_from = devm_kzalloc(psy->dev, sizeof(char *) * cnt,
> +					   GFP_KERNEL);
> +	if (!*psy->supplied_from) {
> +		dev_err(psy->dev, "Couldn't allocate memory for supply list\n");
> +		return -ENOMEM;
> +	}
> +
> +	ret = power_supply_populate_supplied_from(psy);
> +
> +	return ret;

can be just 'return power_supply_populate_supplied_from(psy);'

> +}
> +#endif
> +
>  static int __power_supply_am_i_supplied(struct device *dev, void *data)
>  {
>  	union power_supply_propval ret = {0,};
> @@ -359,6 +486,14 @@ int power_supply_register(struct device *parent, struct power_supply *psy)
>  
>  	INIT_WORK(&psy->changed_work, power_supply_changed_work);
>  
> +#ifdef CONFIG_OF
> +	rc = power_supply_check_supplies(psy);
> +	if (rc) {
> +		dev_info(dev, "Not all required supplies found, defer probe\n");
> +		goto check_supplies_failed;
> +	}
> +#endif
[...]
> +#ifdef CONFIG_OF
> +check_supplies_failed:
> +#endif

Can you make an empty, static inline stub for
power_supply_check_supplies() for !CONFIG_OF case, so that we won't need
#ifdefs inside this function?

Otherwise it looks great, thanks a lot!

Anton

WARNING: multiple messages have this Message-ID (diff)
From: Anton Vorontsov <anton@enomsg.org>
To: Rhyland Klein <rklein@nvidia.com>
Cc: Grant Likely <grant.likely@secretlab.ca>,
	David Woodhouse <dwmw2@infradead.org>,
	devicetree-discuss@lists.ozlabs.org,
	linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org
Subject: Re: [REPOST Patch v1 3/3] power: power_supply_core: Add support for supplied_from
Date: Sat, 30 Mar 2013 15:41:17 -0700	[thread overview]
Message-ID: <20130330224117.GA24610@lizard> (raw)
In-Reply-To: <1364264690-2124-4-git-send-email-rklein@nvidia.com>

On Mon, Mar 25, 2013 at 10:24:50PM -0400, Rhyland Klein wrote:
[...]
> +int power_supply_find_supply_from_node(struct device_node *supply_node)
> +{
> +	int error;
> +	struct device *dev;
> +	struct class_dev_iter iter;
> +
> +	/* Use iterator to see if any other device is registered.
> +	 * This is required since class_for_each_device returns 0
> +	 * if there are no devices registered.
> +	 */

Minor nit: can you please adhere to the canonical style for the multiline
comments?

> +	class_dev_iter_init(&iter, power_supply_class, NULL, NULL);
> +	dev = class_dev_iter_next(&iter);
> +
> +	if (!dev)
> +		return -EPROBE_DEFER;
> +
> +	/* we have to treat the return value as inverted, because if
> +	 * we return error on not found, then it won't continue looking.
> +	 * So we trick it by returning error on success to stop looking
> +	 * once the matching device is found.
> +	 */

Ditto.

> +	error = class_for_each_device(power_supply_class, NULL, supply_node,
> +				       __power_supply_find_supply_from_node);
> +
> +	return error ? 0 : -EPROBE_DEFER;
> +}
> +
> +int power_supply_check_supplies(struct power_supply *psy)
> +{
> +	struct device_node *np;
> +	int cnt = 0;
> +	int ret = 0;
> +
> +	/* If there is already a list honor it */
> +	if (psy->supplied_from && psy->num_supplies > 0)
> +		return 0;
> +
> +	/* No device node found, nothing to do */
> +	if (!psy->of_node)
> +		return 0;
> +
> +	do {

You can move 'int ret;' here (without initializer).

> +		np = of_parse_phandle(psy->of_node, "power-supplies", cnt++);
> +		if (!np)
> +			continue;
> +
> +		ret = power_supply_find_supply_from_node(np);
> +		if (ret) {
> +			dev_dbg(psy->dev, "Failed to find supply, defer!\n");
> +			return -EPROBE_DEFER;
> +		}
> +	} while (np);
> +
> +	/* All supplies found, allocate char ** array for filling */
> +	psy->supplied_from = devm_kzalloc(psy->dev, sizeof(psy->supplied_from),
> +					  GFP_KERNEL);
> +	if (!psy->supplied_from) {
> +		dev_err(psy->dev, "Couldn't allocate memory for supply list\n");
> +		return -ENOMEM;
> +	}
> +
> +	*psy->supplied_from = devm_kzalloc(psy->dev, sizeof(char *) * cnt,
> +					   GFP_KERNEL);
> +	if (!*psy->supplied_from) {
> +		dev_err(psy->dev, "Couldn't allocate memory for supply list\n");
> +		return -ENOMEM;
> +	}
> +
> +	ret = power_supply_populate_supplied_from(psy);
> +
> +	return ret;

can be just 'return power_supply_populate_supplied_from(psy);'

> +}
> +#endif
> +
>  static int __power_supply_am_i_supplied(struct device *dev, void *data)
>  {
>  	union power_supply_propval ret = {0,};
> @@ -359,6 +486,14 @@ int power_supply_register(struct device *parent, struct power_supply *psy)
>  
>  	INIT_WORK(&psy->changed_work, power_supply_changed_work);
>  
> +#ifdef CONFIG_OF
> +	rc = power_supply_check_supplies(psy);
> +	if (rc) {
> +		dev_info(dev, "Not all required supplies found, defer probe\n");
> +		goto check_supplies_failed;
> +	}
> +#endif
[...]
> +#ifdef CONFIG_OF
> +check_supplies_failed:
> +#endif

Can you make an empty, static inline stub for
power_supply_check_supplies() for !CONFIG_OF case, so that we won't need
#ifdefs inside this function?

Otherwise it looks great, thanks a lot!

Anton

  parent reply	other threads:[~2013-03-30 22:41 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-26  2:24 [REPOST Patch v1 0/3] Add DT Binding for Power-Supply power-supplies property Rhyland Klein
2013-03-26  2:24 ` Rhyland Klein
     [not found] ` <1364264690-2124-1-git-send-email-rklein-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2013-03-26  2:24   ` [REPOST Patch v1 1/3] power_supply: Define Binding for power-supplies Rhyland Klein
2013-03-26  2:24     ` Rhyland Klein
2013-03-26  2:24   ` [REPOST Patch v1 2/3] power: power_supply: Add core support for supplied_from Rhyland Klein
2013-03-26  2:24     ` Rhyland Klein
     [not found]     ` <1364264690-2124-3-git-send-email-rklein-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2013-03-27 16:30       ` Stephen Warren
2013-03-27 16:30         ` Stephen Warren
     [not found]         ` <51531E92.9070805-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2013-03-27 21:12           ` Rhyland Klein
2013-03-27 21:12             ` Rhyland Klein
2013-03-26  2:24 ` [REPOST Patch v1 3/3] power: power_supply_core: Add " Rhyland Klein
2013-03-26  2:24   ` Rhyland Klein
     [not found]   ` <1364264690-2124-4-git-send-email-rklein-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2013-03-30 22:41     ` Anton Vorontsov [this message]
2013-03-30 22:41       ` Anton Vorontsov

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=20130330224117.GA24610@lizard \
    --to=anton-9xeibp6oksgdnm+yrofe0a@public.gmane.org \
    --cc=devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org \
    --cc=dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org \
    --cc=grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=rklein-DDmLM1+adcrQT0dZR+AlfA@public.gmane.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.