linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: broonie@opensource.wolfsonmicro.com (Mark Brown)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v4 2/2] Regulator: Add Anatop regulator driver
Date: Thu, 9 Feb 2012 11:24:39 +0000	[thread overview]
Message-ID: <20120209112439.GC3058@opensource.wolfsonmicro.com> (raw)
In-Reply-To: <1328734286-30091-2-git-send-email-paul.liu@linaro.org>

On Thu, Feb 09, 2012 at 04:51:26AM +0800, Ying-Chun Liu (PaulLiu) wrote:

Overall this is looking pretty good, a few issues but relatively minor.

> +	if (uv < anatop_reg->rdata->min_voltage
> +	    || uv > anatop_reg->rdata->max_voltage) {
> +		if (max_uV > anatop_reg->rdata->min_voltage)
> +			uv = anatop_reg->rdata->min_voltage;
> +		else
> +			return -EINVAL;
> +	}

This looks buggy (and is quite hard to follow).  The check for the
voltage being above the minimum voltage is fine but surely if the
voltage is too high then the first if statement will be true and max_uV
will be greater than the minimum voltage so the second if will be true.
This will cause us to choose the minimum voltage that the regulator can
do which is less than the minimum voltage requested.

You probably shouldn't be checking for the upper end of the range at all
here...

> +	if (anatop_reg->rdata->control_reg) {
> +		sel = (uv - anatop_reg->rdata->min_voltage) / 25000;
> +		val = anatop_reg->rdata->min_bit_val + sel;
> +		*selector = sel;
> +		pr_debug("%s: calculated val %d\n", __func__, val);

...instead check that selector is in range here.

> +		anatop_reg->rdata->mfd->write(anatop_reg->rdata->mfd,
> +					      anatop_reg->rdata->control_reg,
> +					      anatop_reg->rdata->vol_bit_shift,
> +					      anatop_reg->rdata->vol_bit_size,
> +					      val);

Just have a write() function in the MFD.

> +	memset(rdesc, 0, sizeof(struct regulator_desc));
> +	rdesc->name = kstrdup(of_get_property(np, "regulator-name", NULL),
> +			      GFP_KERNEL);

You should add binding documentation for the device since it's OF based.

> +	sreg->rdata->name = kstrdup(rdesc->name, GFP_KERNEL);

Can't you just point to rdesc->name?

> +	if (IS_ERR(rdev)) {
> +		dev_err(&pdev->dev, "failed to register %s\n",
> +			rdesc->name);
> +		return PTR_ERR(rdev);
> +	}

All your kstrdup()s need to be unwound in error and free cases.

> +int anatop_regulator_init(void)
> +{
> +	return platform_driver_register(&anatop_regulator);
> +}
> +
> +void anatop_regulator_exit(void)
> +{
> +	platform_driver_unregister(&anatop_regulator);
> +}
> +
> +postcore_initcall(anatop_regulator_init);
> +module_exit(anatop_regulator_exit);

These should be adjacent to the functions.

> +MODULE_AUTHOR("Freescale Semiconductor, Inc.");

Either omit this or put one or more humans as the author.

> +struct anatop_regulator {
> +       struct regulator_desc *regulator;
> +       struct regulator_init_data *initdata;
> +       struct anatop_regulator_data *rdata;
> +};

May as well just merge the regulator data in here - it's not ever used
except with a 1:1 relationship between them.  Could also directly
embed the desc and init_data, then you just have one allocation for the
data rather than a series to error check.

> +int anatop_register_regulator(
> +		struct anatop_regulator *reg_data, int reg,
> +		      struct regulator_init_data *initdata);

This looks like it's not defined any more so could be removed and since
you only appear to support OF the entire header could be merged into the
driver.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20120209/06f638d6/attachment.sig>

  reply	other threads:[~2012-02-09 11:24 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1324980994-18462-1-git-send-email-paul.liu@linaro.org>
2012-02-08 20:51 ` [PATCH v4 1/2] mfd: Add anatop mfd driver Ying-Chun Liu (PaulLiu)
2012-02-08 20:51   ` [PATCH v4 2/2] Regulator: Add Anatop regulator driver Ying-Chun Liu (PaulLiu)
2012-02-09 11:24     ` Mark Brown [this message]
2012-02-11  6:36     ` Shawn Guo
2012-02-11 13:17       ` Mark Brown
2012-02-11  6:05   ` [PATCH v4 1/2] mfd: Add anatop mfd driver Shawn Guo
2012-02-21 11:17   ` Samuel Ortiz
2012-03-01  9:19     ` Ying-Chun Liu (PaulLiu)
2012-03-01  9:10   ` [PATCH v5 " Ying-Chun Liu (PaulLiu)
2012-03-01  9:10     ` [PATCH v5 2/2] Regulator: Add Anatop regulator driver Ying-Chun Liu (PaulLiu)
2012-03-01 11:17       ` Mark Brown
2012-03-01 11:30     ` [PATCH v5 1/2] mfd: Add anatop mfd driver Mark Brown
2012-03-02  7:00     ` [PATCH v6 " Ying-Chun Liu (PaulLiu)
2012-03-02  7:00       ` [PATCH v6 2/2] Regulator: Add Anatop regulator driver Ying-Chun Liu (PaulLiu)
2012-03-04  6:51         ` Shawn Guo
2012-03-04 13:29           ` Mark Brown
2012-03-02  7:07       ` [PATCH v6 1/2] mfd: Add anatop mfd driver Venu Byravarasu
2012-03-02  7:51         ` Ying-Chun Liu (PaulLiu)
2012-03-02  8:02           ` Venu Byravarasu
2012-03-02 14:00       ` Peter Korsgaard
2012-03-03 17:39       ` [PATCH v7 " Ying-Chun Liu (PaulLiu)
2012-03-03 17:58         ` Mark Brown
2012-03-04  5:25         ` Shawn Guo
2012-03-04  5:42         ` Shawn Guo
2012-03-04  5:55         ` Shawn Guo

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=20120209112439.GC3058@opensource.wolfsonmicro.com \
    --to=broonie@opensource.wolfsonmicro.com \
    --cc=linux-arm-kernel@lists.infradead.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).