All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ezequiel Garcia <ezequiel.garcia@imgtec.com>
To: Hartmut Knaack <knaack.h@gmx.de>,
	Andrew Bresticker <abrestic@chromium.org>,
	James Hartley <james.hartley@imgtec.com>,
	"Lars-Peter Clausen" <lars@metafoo.de>,
	Jonathan Cameron <jic23@kernel.org>
Cc: <linux-iio@vger.kernel.org>, <devicetree@vger.kernel.org>,
	<robh+dt@kernel.org>, <Pawel.Moll@arm.com>,
	<Mark.Rutland@arm.com>, <ijc+devicetree@hellion.org.uk>,
	<galak@codeaurora.org>, <Naidu.Tellapati@imgtec.com>,
	Phani Movva <Phani.Movva@imgtec.com>
Subject: Re: [PATCH v3 1/3] iio: adc: Cosmic Circuits 10001 ADC driver
Date: Tue, 25 Nov 2014 19:03:52 -0300	[thread overview]
Message-ID: <5474FCC8.8080906@imgtec.com> (raw)
In-Reply-To: <5474F7A5.6030008@gmx.de>



On 11/25/2014 06:41 PM, Hartmut Knaack wrote:
>>
>> Unless I'm missing something, that's exactly what XOR does.
>>
>> Example:
>>
>> reserved_channels = 0x2;
>> channel_map = 0x7 ^ reserved_channels -> 0x5
>>
> You miss to check ret for a valid range, which you don't need to do when masking out channels.
> Example:
> reserved_channels = 0x8;
> channel_map = 0x7 ^ reserved_channels -> 0xf
> And this is actually happening in the current revision (with the wrong channel_map assignment), that a reserved channel in DT would become usable.

Right, definitely a check is needed.

>>>> +
>>>> +	adc_dev->reg = devm_regulator_get(&pdev->dev, "vref");
>>>> +	if (IS_ERR_OR_NULL(adc_dev->reg))
>>>> +		return -EINVAL;
>>> 	if (IS_ERR(adc_dev->reg))
>>> 		return PTR_ERR(adc_dev->reg);
>>
>> Are you sure? What if devm_regulator_get() returns NULL?
>>
> I had a look at it, but couldn't figure out a condition in which it would return NULL. But I'd be happy to be informed of anything different.

If CONFIG_REGULATOR=n you get NULL there (although I added a select REGULATOR
on the v4 I just posted).

>>>> +
>>>> +	ret = regulator_enable(adc_dev->reg);
>>>> +	if (ret)
>>>> +		return ret;
>>>> +
>>>> +	indio_dev->dev.parent = &pdev->dev;
>>>> +	indio_dev->name = dev_name(&pdev->dev);
>>>> +	indio_dev->info = &cc10001_adc_info;
>>>> +	indio_dev->modes = INDIO_DIRECT_MODE;
>>>> +
>>>> +	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>>>> +	adc_dev->reg_base = devm_ioremap_resource(&pdev->dev, res);
>>>> +	if (IS_ERR(adc_dev->reg_base))
>>> Need to put error code into ret.
>>
>> Right.
>>
>>>> +		goto err_disable_reg;
>>>> +
>>>> +	adc_dev->adc_clk = devm_clk_get(&pdev->dev, "adc");
>>>> +	if (IS_ERR(adc_dev->adc_clk)) {
>>>> +		dev_err(&pdev->dev, "Failed to get the clock\n");
>>> Need to put error code into ret.
>>>> +		goto err_disable_reg;
>>>> +	}
>>>> +
>>>> +	ret = clk_prepare_enable(adc_dev->adc_clk);
>>>> +	if (ret) {
>>>> +		dev_err(&pdev->dev, "Failed to enable the clock\n");
>>>> +		goto err_disable_reg;
>>>> +	}
>>>> +
>>>> +	adc_clk_rate = clk_get_rate(adc_dev->adc_clk);
>>>> +	if (!adc_clk_rate) {
>>>> +		ret = -EINVAL;
>>>> +		dev_err(&pdev->dev, "null clock rate!\n");
>>> Start message with upper case?
>>
>> Actually, I'd rather make the others start with lower case.
> Fair enough, unless they are full sentences like here. My english grammar tells me they should start with capital letters.

Yeah, but it's not the start of the message, as it's prefixed
with the device stuff.

>>
>>>> +		goto err_disable_clk;
>>>> +	}
>>>> +
>>>> +	adc_dev->eoc_delay_ns = NSEC_PER_SEC / adc_clk_rate;
>>>> +	adc_dev->start_delay_ns = adc_dev->eoc_delay_ns * CC10001_WAIT_CYCLES;
>>>> +
>>>> +	/* Setup the ADC channels available on the device */
>>>> +	ret = cc10001_adc_channel_init(indio_dev);
>>>> +	if (ret < 0) {
>>>> +		dev_err(&pdev->dev, "Could not initialize the channels.\n");
>>>> +		goto err_disable_clk;
>>>> +	}
>>>> +
>>>> +	mutex_init(&adc_dev->lock);
>>>> +
>>>> +	ret = iio_triggered_buffer_setup(indio_dev, NULL,
>>>> +					 &cc10001_adc_trigger_h, NULL);
>>>> +	if (ret < 0)
>>>> +		goto err_disable_clk;
>>>> +
>>>> +	ret = iio_device_register(indio_dev);
>>>> +	if (ret < 0)
>>>> +		goto err_cleanup_buffer;
>>>> +
>>>> +	platform_set_drvdata(pdev, indio_dev);
>>> Move this above iio_device_register.
>>
>> What for?
> To make iio_device_register the last operation of the probe.

I really don't think it matters, since platform_get_drvdata
is only called in the remove.

I'll move it if you think it's worth it, though.

Thanks for the review!
-- 
Ezequiel

WARNING: multiple messages have this Message-ID (diff)
From: Ezequiel Garcia <ezequiel.garcia-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org>
To: Hartmut Knaack <knaack.h-Mmb7MZpHnFY@public.gmane.org>,
	Andrew Bresticker
	<abrestic-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>,
	James Hartley
	<james.hartley-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org>,
	Lars-Peter Clausen <lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>,
	Jonathan Cameron <jic23-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: linux-iio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
	Pawel.Moll-5wv7dgnIgG8@public.gmane.org,
	Mark.Rutland-5wv7dgnIgG8@public.gmane.org,
	ijc+devicetree-KcIKpvwj1kUDXYZnReoRVg@public.gmane.org,
	galak-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org,
	Naidu.Tellapati-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org,
	Phani Movva <Phani.Movva-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org>
Subject: Re: [PATCH v3 1/3] iio: adc: Cosmic Circuits 10001 ADC driver
Date: Tue, 25 Nov 2014 19:03:52 -0300	[thread overview]
Message-ID: <5474FCC8.8080906@imgtec.com> (raw)
In-Reply-To: <5474F7A5.6030008-Mmb7MZpHnFY@public.gmane.org>



On 11/25/2014 06:41 PM, Hartmut Knaack wrote:
>>
>> Unless I'm missing something, that's exactly what XOR does.
>>
>> Example:
>>
>> reserved_channels = 0x2;
>> channel_map = 0x7 ^ reserved_channels -> 0x5
>>
> You miss to check ret for a valid range, which you don't need to do when masking out channels.
> Example:
> reserved_channels = 0x8;
> channel_map = 0x7 ^ reserved_channels -> 0xf
> And this is actually happening in the current revision (with the wrong channel_map assignment), that a reserved channel in DT would become usable.

Right, definitely a check is needed.

>>>> +
>>>> +	adc_dev->reg = devm_regulator_get(&pdev->dev, "vref");
>>>> +	if (IS_ERR_OR_NULL(adc_dev->reg))
>>>> +		return -EINVAL;
>>> 	if (IS_ERR(adc_dev->reg))
>>> 		return PTR_ERR(adc_dev->reg);
>>
>> Are you sure? What if devm_regulator_get() returns NULL?
>>
> I had a look at it, but couldn't figure out a condition in which it would return NULL. But I'd be happy to be informed of anything different.

If CONFIG_REGULATOR=n you get NULL there (although I added a select REGULATOR
on the v4 I just posted).

>>>> +
>>>> +	ret = regulator_enable(adc_dev->reg);
>>>> +	if (ret)
>>>> +		return ret;
>>>> +
>>>> +	indio_dev->dev.parent = &pdev->dev;
>>>> +	indio_dev->name = dev_name(&pdev->dev);
>>>> +	indio_dev->info = &cc10001_adc_info;
>>>> +	indio_dev->modes = INDIO_DIRECT_MODE;
>>>> +
>>>> +	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>>>> +	adc_dev->reg_base = devm_ioremap_resource(&pdev->dev, res);
>>>> +	if (IS_ERR(adc_dev->reg_base))
>>> Need to put error code into ret.
>>
>> Right.
>>
>>>> +		goto err_disable_reg;
>>>> +
>>>> +	adc_dev->adc_clk = devm_clk_get(&pdev->dev, "adc");
>>>> +	if (IS_ERR(adc_dev->adc_clk)) {
>>>> +		dev_err(&pdev->dev, "Failed to get the clock\n");
>>> Need to put error code into ret.
>>>> +		goto err_disable_reg;
>>>> +	}
>>>> +
>>>> +	ret = clk_prepare_enable(adc_dev->adc_clk);
>>>> +	if (ret) {
>>>> +		dev_err(&pdev->dev, "Failed to enable the clock\n");
>>>> +		goto err_disable_reg;
>>>> +	}
>>>> +
>>>> +	adc_clk_rate = clk_get_rate(adc_dev->adc_clk);
>>>> +	if (!adc_clk_rate) {
>>>> +		ret = -EINVAL;
>>>> +		dev_err(&pdev->dev, "null clock rate!\n");
>>> Start message with upper case?
>>
>> Actually, I'd rather make the others start with lower case.
> Fair enough, unless they are full sentences like here. My english grammar tells me they should start with capital letters.

Yeah, but it's not the start of the message, as it's prefixed
with the device stuff.

>>
>>>> +		goto err_disable_clk;
>>>> +	}
>>>> +
>>>> +	adc_dev->eoc_delay_ns = NSEC_PER_SEC / adc_clk_rate;
>>>> +	adc_dev->start_delay_ns = adc_dev->eoc_delay_ns * CC10001_WAIT_CYCLES;
>>>> +
>>>> +	/* Setup the ADC channels available on the device */
>>>> +	ret = cc10001_adc_channel_init(indio_dev);
>>>> +	if (ret < 0) {
>>>> +		dev_err(&pdev->dev, "Could not initialize the channels.\n");
>>>> +		goto err_disable_clk;
>>>> +	}
>>>> +
>>>> +	mutex_init(&adc_dev->lock);
>>>> +
>>>> +	ret = iio_triggered_buffer_setup(indio_dev, NULL,
>>>> +					 &cc10001_adc_trigger_h, NULL);
>>>> +	if (ret < 0)
>>>> +		goto err_disable_clk;
>>>> +
>>>> +	ret = iio_device_register(indio_dev);
>>>> +	if (ret < 0)
>>>> +		goto err_cleanup_buffer;
>>>> +
>>>> +	platform_set_drvdata(pdev, indio_dev);
>>> Move this above iio_device_register.
>>
>> What for?
> To make iio_device_register the last operation of the probe.

I really don't think it matters, since platform_get_drvdata
is only called in the remove.

I'll move it if you think it's worth it, though.

Thanks for the review!
-- 
Ezequiel

  reply	other threads:[~2014-11-25 22:03 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-13 14:13 [PATCH v3 0/3] iio: Add Cosmic Circuits ADC support Ezequiel Garcia
2014-11-13 14:13 ` Ezequiel Garcia
2014-11-13 14:13 ` [PATCH v3 1/3] iio: adc: Cosmic Circuits 10001 ADC driver Ezequiel Garcia
2014-11-13 14:13   ` Ezequiel Garcia
2014-11-15 10:46   ` Jonathan Cameron
2014-11-15 10:46     ` Jonathan Cameron
2014-11-15 18:05     ` Ezequiel Garcia
2014-11-15 18:05       ` Ezequiel Garcia
2014-11-22  1:15   ` Hartmut Knaack
2014-11-22  1:15     ` Hartmut Knaack
2014-11-25 17:46     ` Ezequiel Garcia
2014-11-25 17:46       ` Ezequiel Garcia
2014-11-25 21:41       ` Hartmut Knaack
2014-11-25 21:41         ` Hartmut Knaack
2014-11-25 22:03         ` Ezequiel Garcia [this message]
2014-11-25 22:03           ` Ezequiel Garcia
2014-11-25 22:53           ` Hartmut Knaack
2014-11-25 22:53             ` Hartmut Knaack
2014-11-27 15:08             ` Ezequiel Garcia
2014-11-27 15:08               ` Ezequiel Garcia
2014-11-27 15:16               ` Lars-Peter Clausen
2014-11-27 15:16                 ` Lars-Peter Clausen
2014-11-27 15:18                 ` Ezequiel Garcia
2014-11-27 15:18                   ` Ezequiel Garcia
2014-11-13 14:13 ` [PATCH v3 2/3] DT: iio: adc: Add CC_10001 binding documentation Ezequiel Garcia
2014-11-13 14:13   ` Ezequiel Garcia
2014-11-13 14:37   ` Rob Herring
2014-11-13 14:37     ` Rob Herring
2014-11-13 18:18     ` Ezequiel Garcia
2014-11-13 18:18       ` Ezequiel Garcia
2014-11-13 18:19   ` [PATCH v4 " Ezequiel Garcia
2014-11-13 18:19     ` Ezequiel Garcia
2014-11-13 14:14 ` [PATCH v3 3/3] DT: Add a vendor prefix for Cosmic Circuits Ezequiel Garcia
2014-11-13 14:14   ` Ezequiel Garcia
2014-11-13 14:34   ` Rob Herring
2014-11-13 14:34     ` Rob Herring
2014-11-13 14:14 ` [PATCH v3 0/3] iio: Add Cosmic Circuits ADC support Ezequiel Garcia
2014-11-13 14:14   ` Ezequiel Garcia
2014-11-13 19:10   ` Andrew Bresticker
2014-11-13 19:10     ` Andrew Bresticker

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=5474FCC8.8080906@imgtec.com \
    --to=ezequiel.garcia@imgtec.com \
    --cc=Mark.Rutland@arm.com \
    --cc=Naidu.Tellapati@imgtec.com \
    --cc=Pawel.Moll@arm.com \
    --cc=Phani.Movva@imgtec.com \
    --cc=abrestic@chromium.org \
    --cc=devicetree@vger.kernel.org \
    --cc=galak@codeaurora.org \
    --cc=ijc+devicetree@hellion.org.uk \
    --cc=james.hartley@imgtec.com \
    --cc=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=robh+dt@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.