From: Jonathan Cameron <jic23-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
To: Tomas Novotny <tomas-P46umIhNmdHrBKCeMvbIDA@public.gmane.org>,
devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: Hartmut Knaack <knaack.h-Mmb7MZpHnFY@public.gmane.org>,
Lars-Peter Clausen <lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>,
Peter Meerwald <pmeerw-jW+XmwGofnusTnJN9+BGXg@public.gmane.org>,
Rob Herring <robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
Mark Rutland <mark.rutland-5wv7dgnIgG8@public.gmane.org>,
Akinobu Mita
<akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
Yong Li <sdliyong-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
linux-iio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH v2 4/4] iio: dac: mcp4725: add devicetree support
Date: Sat, 15 Oct 2016 15:14:19 +0100 [thread overview]
Message-ID: <a710bc16-24e9-8b30-5db0-8eff371a012b@kernel.org> (raw)
In-Reply-To: <1476194263-12015-5-git-send-email-tomas-P46umIhNmdHrBKCeMvbIDA@public.gmane.org>
On 11/10/16 14:57, Tomas Novotny wrote:
> Signed-off-by: Tomas Novotny <tomas-P46umIhNmdHrBKCeMvbIDA@public.gmane.org>
Few small bits inline.
Jonathan
> ---
> drivers/iio/dac/mcp4725.c | 46 +++++++++++++++++++++++++++++++++++++++++-----
> 1 file changed, 41 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/iio/dac/mcp4725.c b/drivers/iio/dac/mcp4725.c
> index 29cf85d..b8954f2 100644
> --- a/drivers/iio/dac/mcp4725.c
> +++ b/drivers/iio/dac/mcp4725.c
> @@ -19,6 +19,7 @@
> #include <linux/err.h>
> #include <linux/delay.h>
> #include <linux/regulator/consumer.h>
> +#include <linux/of.h>
>
> #include <linux/iio/iio.h>
> #include <linux/iio/sysfs.h>
> @@ -364,6 +365,30 @@ static const struct iio_info mcp4725_info = {
> .driver_module = THIS_MODULE,
> };
>
> +#ifdef CONFIG_OF
> +static int mcp4725_probe_dt(struct device *dev,
> + struct mcp4725_platform_data *pdata)
> +{
> + struct device_node *np = dev->of_node;
> +
> + if (!np)
> + return -ENODEV;
> +
> + /* check if is the vref-supply defined */
> + pdata->use_vref = of_property_read_bool(np, "vref-supply");
> + pdata->vref_buffered =
> + of_property_read_bool(np, "microchip,vref-buffered");
> +
> + return 0;
> +}
> +#else
> +static int mcp4725_probe_dt(struct device *dev,
> + struct mcp4725_platform_data *platform_data)
> +{
> + return -ENODEV;
> +}
> +#endif
> +
> static int mcp4725_probe(struct i2c_client *client,
> const struct i2c_device_id *id)
> {
> @@ -375,11 +400,6 @@ static int mcp4725_probe(struct i2c_client *client,
> u8 ref;
> int err;
>
> - if (!pdata) {
> - dev_err(&client->dev, "invalid platform data");
> - return -EINVAL;
> - }
> -
> indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
> if (indio_dev == NULL)
> return -ENOMEM;
> @@ -388,6 +408,19 @@ static int mcp4725_probe(struct i2c_client *client,
> data->client = client;
> data->id = id->driver_data;
>
> + if (!pdata) {
May seem an odd way to do it, but I would use
if (!dev_get_platdata(&client->dev)) so it's obvious what it matches
against when it comes to unwinding this down below.
> + pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL);
> + if (!pdata)
> + return -ENOMEM;
> +
> + err = mcp4725_probe_dt(&client->dev, pdata);
> + if (err) {
> + dev_err(&client->dev,
> + "invalid platform or devicetree data");
> + return err;
> + }
> + }
> +
> if (data->id == MCP4725 && pdata->use_vref) {
> dev_warn(&client->dev,
> "ignoring unavailable external reference on MCP4725");
> @@ -460,6 +493,9 @@ static int mcp4725_probe(struct i2c_client *client,
> if (err)
> goto err_disable_vref_reg;
>
> + if (!dev_get_platdata(&client->dev))
> + devm_kfree(&client->dev, pdata);
Hmm. I wonder if it's worth freeing this explicitly rather than just letting
it clear up on driver remove. It seems odd to use devm allocations for
what is a short term termporary variable.
Actually why not just use a local variable on the stack and set
pdata to point to that? Then your cleanup is all nice an automatic
without having to do this slightly odd devm usage.
> +
> return 0;
>
> err_disable_vref_reg:
>
next prev parent reply other threads:[~2016-10-15 14:14 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-11 13:57 [PATCH v2 0/4] iio: dac: mcp4725: use regulator framework, add vref and dt support Tomas Novotny
[not found] ` <1476194263-12015-1-git-send-email-tomas-P46umIhNmdHrBKCeMvbIDA@public.gmane.org>
2016-10-11 13:57 ` [PATCH v2 1/4] iio: dac: mcp4725: use regulator framework Tomas Novotny
[not found] ` <1476194263-12015-2-git-send-email-tomas-P46umIhNmdHrBKCeMvbIDA@public.gmane.org>
2016-10-14 11:58 ` Lars-Peter Clausen
[not found] ` <87088906-8986-cca0-c29a-747610bae982-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
2016-10-14 12:06 ` Lars-Peter Clausen
2016-10-14 12:24 ` Tomas Novotny
2016-10-15 14:00 ` Jonathan Cameron
2016-10-11 13:57 ` [PATCH v2 2/4] iio: dac: mcp4725: support voltage reference selection Tomas Novotny
[not found] ` <1476194263-12015-3-git-send-email-tomas-P46umIhNmdHrBKCeMvbIDA@public.gmane.org>
2016-10-15 14:07 ` Jonathan Cameron
[not found] ` <e015de34-51bd-f43b-4a9f-cfe047d4fb3c-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2016-10-18 13:51 ` Tomas Novotny
2016-10-11 13:57 ` [PATCH v2 3/4] Documentation: dt: iio: add mcp4725/6 dac device binding Tomas Novotny
[not found] ` <1476194263-12015-4-git-send-email-tomas-P46umIhNmdHrBKCeMvbIDA@public.gmane.org>
2016-10-15 14:08 ` Jonathan Cameron
2016-10-18 12:43 ` Rob Herring
2016-10-11 13:57 ` [PATCH v2 4/4] iio: dac: mcp4725: add devicetree support Tomas Novotny
[not found] ` <1476194263-12015-5-git-send-email-tomas-P46umIhNmdHrBKCeMvbIDA@public.gmane.org>
2016-10-15 14:14 ` Jonathan Cameron [this message]
[not found] ` <a710bc16-24e9-8b30-5db0-8eff371a012b-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2016-10-18 13:56 ` Tomas Novotny
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=a710bc16-24e9-8b30-5db0-8eff371a012b@kernel.org \
--to=jic23-dgejt+ai2ygdnm+yrofe0a@public.gmane.org \
--cc=akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=knaack.h-Mmb7MZpHnFY@public.gmane.org \
--cc=lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org \
--cc=linux-iio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=mark.rutland-5wv7dgnIgG8@public.gmane.org \
--cc=pmeerw-jW+XmwGofnusTnJN9+BGXg@public.gmane.org \
--cc=robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=sdliyong-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=tomas-P46umIhNmdHrBKCeMvbIDA@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).