Re: [PATCH 03/20] device property: of_property_read_string_array() returns number of strings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Rob,

On Thu, Feb 23, 2017 at 05:42:07PM -0600, Rob Herring wrote:
> On Thu, Feb 23, 2017 at 11:00 AM, Sakari Ailus
> <sakari.ailus@xxxxxxxxxxxxxxx> wrote:
> > of_property_read_string_array() returns number of strings read if the
> > target array of pointers is non-NULL. fwnode_property_read_string_array()
> > is documented to return 0 in that case. Fix this.
> 
> It seems of_property_read_string_array is more capable. If the number
> of strings is variable and I want use the fwnode API, then what do I
> do? IMO, you should fix the fwnode API.

It is not more capable but simply different.

The caller typically needs to allocate memory to hold a pointer array, which
means it needs to call the function with NULL output array argument anyway.
There is the special case where the maximum number of strings is known,
though. You could remove an additional call in this case.

However, why I do argue for this interface is safety: returning zero on
success is always a safe choice. Programmers often check for zero only
because it might be shorter to write or someone might thing it looks nicer:

int ret = fwnode_property_read_string_array(fwnode, "foo");
if (ret)
	goto err;

Additionally, returning zero is consistent within the pack: the OF (and
fwnode) integer array access functions return zero on success, i.e. not the
number of array elements read.

-- 
Kind regards,

Sakari Ailus
e-mail: sakari.ailus@xxxxxx	XMPP: sailus@xxxxxxxxxxxxxx
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux IBM ACPI]     [Linux Power Management]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]     [Linux Resources]

  Powered by Linux