Linux Documentation
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Leo Yang <leo.yang.sy0@gmail.com>
Cc: jdelvare@suse.com, robh@kernel.org, davem@davemloft.net,
	krzk+dt@kernel.org, conor+dt@kernel.org, Leo-Yang@quantatw.com,
	corbet@lwn.net, Delphine_CC_Chiu@wiwynn.com,
	linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org,
	kernel test robot <lkp@intel.com>
Subject: Re: [PATCH v2 2/2] hwmon: Add driver for TI INA232 Current and Power Monitor
Date: Tue, 14 Jan 2025 11:23:19 -0800	[thread overview]
Message-ID: <dc5380a7-e257-441f-a264-7bcfe193de2c@roeck-us.net> (raw)
In-Reply-To: <CAAfUjZF7jOoZz5h6XkxqOyt=x8xnv+SUbMWJ1bVdxUzFRTO8cA@mail.gmail.com>

On 1/14/25 00:02, Leo Yang wrote:
> Hi Guenter,
> 
> On Sat, Jan 11, 2025 at 12:22 AM Guenter Roeck <linux@roeck-us.net> wrote:
>>
>>> +
>>> +     /* If INA233 skips current/power, shunt-resistor and current-lsb aren't needed. */
>>> +     /* read rshunt value (uOhm) */
>>> +     if (of_property_read_u32(client->dev.of_node, "shunt-resistor", &rshunt) < 0)
>>> +             rshunt = INA233_RSHUNT_DEFAULT;
>>> +
>>> +     /* read current_lsb value (uA) */
>>> +     if (of_property_read_u16(client->dev.of_node, "ti,current-lsb", &current_lsb) < 0)
>>> +             current_lsb = INA233_CURRENT_LSB_DEFAULT;
>>> +
>> of_property_read_u16() returns -EOVERFLOW if the value provided was too large.
>> This should be checked to avoid situations where the value provided in devicetree
>> is too large.
>>
> Sorry I have a question, I can't get it to return -EOVERFLOW when I test it
> I am using the following properties:
> test16 = /bits/ 16 <0xfffd>;
> of_property_read_u16 reads 0xfffd
> 
> test16o = /bits/ 16 <0xfffdd>;
> of_property_read_u16 reads 0xffdd
> 
> test16o = <0xfffdd>;
> of_property_read_u16 reads 0xf
> 
> test16array = /bits/ 16 <0xfffd 0xfffe>;
> of_property_read_u16 reads 0xfffd
> 
> The same result for device_property_read_u16, it seems that a data
> truncation occurs and none of them return -EOVERFLOW.
> 
> So maybe there is no need to check EOVERFLOW?
> Or maybe we could use the minimum and maximum of the binding to
> indicate the range.
> 

of_property_read_u16() calls of_property_read_u16_array(). The API documentation
of of_property_read_u16_array() lists -ENODATA and -EOVERFLOW as possible error
return values, in addition to -EINVAL. Ignoring those errors is not a good idea,
even if it is not immediately obvious how to reproduce them.

Guenter


  reply	other threads:[~2025-01-14 19:23 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-10  8:15 [PATCH v2 0/2] hwmon: Add support for INA233 Leo Yang
2025-01-10  8:15 ` [PATCH v2 1/2] dt-bindings: hwmon: ti,ina2xx: Add INA233 device Leo Yang
2025-01-10  8:22   ` Krzysztof Kozlowski
2025-01-10  8:36   ` Krzysztof Kozlowski
2025-01-10  8:15 ` [PATCH v2 2/2] hwmon: Add driver for TI INA232 Current and Power Monitor Leo Yang
2025-01-10  8:25   ` Krzysztof Kozlowski
2025-01-10 16:22   ` Guenter Roeck
2025-01-14  8:02     ` Leo Yang
2025-01-14 19:23       ` Guenter Roeck [this message]
2025-01-10 21:19   ` Christophe JAILLET

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=dc5380a7-e257-441f-a264-7bcfe193de2c@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=Delphine_CC_Chiu@wiwynn.com \
    --cc=Leo-Yang@quantatw.com \
    --cc=conor+dt@kernel.org \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=jdelvare@suse.com \
    --cc=krzk+dt@kernel.org \
    --cc=leo.yang.sy0@gmail.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkp@intel.com \
    --cc=robh@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox