devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Lunn <andrew-g2DYL2Zd6BY@public.gmane.org>
To: Jamie Lentin <jm-Pj/HzkgeCk7QXOPxS62xeg@public.gmane.org>
Cc: Andrew Lunn <andrew-g2DYL2Zd6BY@public.gmane.org>,
	Jason Cooper <jason-NLaQJdtUoK4Be96aLqz0jA@public.gmane.org>,
	devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org,
	Rob Herring <rob.herring-bsGFqQB8/DxBDgjK7y7TUQ@public.gmane.org>,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
	Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>,
	Guenter Roeck <linux-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
Subject: Re: [PATCH 1/2] hwmon: Add devicetree bindings to gpio-fan
Date: Sat, 8 Sep 2012 09:32:23 +0200	[thread overview]
Message-ID: <20120908073223.GB14466@lunn.ch> (raw)
In-Reply-To: <1347035675-23907-2-git-send-email-jm-Pj/HzkgeCk7QXOPxS62xeg@public.gmane.org>

Hi Jamie

> +static int gpio_fan_get_of_pdata(struct device *dev,
> +			    struct gpio_fan_platform_data *pdata)
> +{
> +	struct device_node *node;
> +	struct gpio_fan_speed  *speed;
> +	unsigned *ctrl;
> +	unsigned i;
> +	u32 u;
> +	struct property *prop;
> +	const __be32 *p;
> +
> +	node = dev->of_node;
> +
> +	/* Fill GPIO pin array */
> +	pdata->num_ctrl = of_gpio_count(node);
> +	ctrl = devm_kzalloc(dev, pdata->num_ctrl * sizeof(unsigned),
> +				GFP_KERNEL);
> +	if (!ctrl)
> +		return -ENOMEM;
> +	for (i = 0; i < of_gpio_count(node); i++) {


It seems unlikely the number of gpio pins is going to change while
inside this loop. So just use pdata->num_ctrl instead of counting them
every iteration.

> +		int val;
> +
> +		val = of_get_gpio(node, i);
> +		if (val >= 0)
> +			ctrl[i] = val;
> +		else
> +			return -EINVAL;
> +	}
> +	pdata->ctrl = ctrl;
> +
> +	/* Get speed map array size */
> +	i = 0;
> +	of_property_for_each_u32(node, "gpio-fan,speed-map", prop, p, u)
> +		i++;
> +	if (i & 1) {
> +		dev_err(dev, "gpio-fan,speed-map contains odd number of entries");
> +		return -ENODEV;
> +	}

This is not so clear on the first reading. i is the number of numbers
in the speed-map, and each entry needs two numbers, hence the (i & 1).
Maybe a comment to explain this? Or see if there is an of_ function
which returns records instead of individual properties?

> +static const struct of_device_id of_gpio_fan_match[] = {
> +	{ .compatible = "gpio-fan", },
> +	{},
> +};

This should probably have an __devinitdata attribute.

     Andrew

  parent reply	other threads:[~2012-09-08  7:32 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-07 16:34 [PATCH 0/2] hwmon: kirkwood: Add DT bindings to gpio-fan for DNS-32[05] Jamie Lentin
2012-09-07 16:34 ` [PATCH 1/2] hwmon: Add devicetree bindings to gpio-fan Jamie Lentin
2012-09-07 18:36   ` Guenter Roeck
     [not found]   ` <1347035675-23907-2-git-send-email-jm-Pj/HzkgeCk7QXOPxS62xeg@public.gmane.org>
2012-09-08  7:32     ` Andrew Lunn [this message]
2012-09-07 16:34 ` [PATCH 2/2] ARM: kirkwood: Use devicetree to define DNS-32[05] fan Jamie Lentin
     [not found]   ` <1347035675-23907-3-git-send-email-jm-Pj/HzkgeCk7QXOPxS62xeg@public.gmane.org>
2012-09-07 21:23     ` Andrew Lunn
     [not found] ` <1347035675-23907-1-git-send-email-jm-Pj/HzkgeCk7QXOPxS62xeg@public.gmane.org>
2012-09-10 13:51   ` [PATCH V2 0/2] hwmon: kirkwood: Add DT bindings to gpio-fan for DNS-32[05] Jamie Lentin
     [not found]     ` <1347285112-13542-1-git-send-email-jm-Pj/HzkgeCk7QXOPxS62xeg@public.gmane.org>
2012-09-10 13:51       ` [PATCH V2 1/2] hwmon: Add devicetree bindings to gpio-fan Jamie Lentin
     [not found]         ` <1347285112-13542-2-git-send-email-jm-Pj/HzkgeCk7QXOPxS62xeg@public.gmane.org>
2012-09-10 15:28           ` Andrew Lunn
     [not found]             ` <20120910152814.GA6050-g2DYL2Zd6BY@public.gmane.org>
2012-09-10 16:04               ` Jamie Lentin
     [not found]                 ` <alpine.DEB.2.00.1209101656120.10589-5X291BYdrx55rAo4AelP/Ydd74u8MsAO@public.gmane.org>
2012-09-10 18:15                   ` Jason Cooper
2012-09-10 18:49         ` Guenter Roeck
     [not found]           ` <20120910184919.GA30872-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
2012-09-14 16:07             ` [PATCH V3 " Jamie Lentin
2012-09-15  2:28               ` Guenter Roeck
     [not found]                 ` <20120915022833.GA20375-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
2012-09-15  3:16                   ` Jason Cooper
2012-09-10 13:51       ` [PATCH V2 2/2] ARM: kirkwood: Use devicetree to define DNS-32[05] fan Jamie Lentin

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=20120908073223.GB14466@lunn.ch \
    --to=andrew-g2dyl2zd6by@public.gmane.org \
    --cc=devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org \
    --cc=jason-NLaQJdtUoK4Be96aLqz0jA@public.gmane.org \
    --cc=jm-Pj/HzkgeCk7QXOPxS62xeg@public.gmane.org \
    --cc=khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org \
    --cc=linux-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org \
    --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=rob.herring-bsGFqQB8/DxBDgjK7y7TUQ@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).