diff options
| author | Andy Shevchenko <andriy.shevchenko@linux.intel.com> | 2019-06-13 12:59:51 -0400 |
|---|---|---|
| committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2019-06-13 16:41:59 -0400 |
| commit | 33ee09cd59ce154b64f9df942dfa5456db90d5f9 (patch) | |
| tree | 2b513f0f32f18ef93ab2f1e9222316ff6604fca2 /include/linux | |
| parent | be6dc3291e0fc19e6c8cc8f231968ab9b51f5abf (diff) | |
device property: Add helpers to count items in an array
The usual pattern to allocate the necessary space for an array of properties is
to count them first by calling:
count = device_property_read_uXX_array(dev, propname, NULL, 0);
if (count < 0)
return count;
Introduce helpers device_property_count_uXX() to count items by supplying hard
coded last two parameters to device_property_readXX_array().
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'include/linux')
| -rw-r--r-- | include/linux/property.h | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/include/linux/property.h b/include/linux/property.h index 088d4db7e949..dbacf17fff2e 100644 --- a/include/linux/property.h +++ b/include/linux/property.h | |||
| @@ -148,6 +148,26 @@ static inline int device_property_read_u64(struct device *dev, | |||
| 148 | return device_property_read_u64_array(dev, propname, val, 1); | 148 | return device_property_read_u64_array(dev, propname, val, 1); |
| 149 | } | 149 | } |
| 150 | 150 | ||
| 151 | static inline int device_property_count_u8(struct device *dev, const char *propname) | ||
| 152 | { | ||
| 153 | return device_property_read_u8_array(dev, propname, NULL, 0); | ||
| 154 | } | ||
| 155 | |||
| 156 | static inline int device_property_count_u16(struct device *dev, const char *propname) | ||
| 157 | { | ||
| 158 | return device_property_read_u16_array(dev, propname, NULL, 0); | ||
| 159 | } | ||
| 160 | |||
| 161 | static inline int device_property_count_u32(struct device *dev, const char *propname) | ||
| 162 | { | ||
| 163 | return device_property_read_u32_array(dev, propname, NULL, 0); | ||
| 164 | } | ||
| 165 | |||
| 166 | static inline int device_property_count_u64(struct device *dev, const char *propname) | ||
| 167 | { | ||
| 168 | return device_property_read_u64_array(dev, propname, NULL, 0); | ||
| 169 | } | ||
| 170 | |||
| 151 | static inline bool fwnode_property_read_bool(const struct fwnode_handle *fwnode, | 171 | static inline bool fwnode_property_read_bool(const struct fwnode_handle *fwnode, |
| 152 | const char *propname) | 172 | const char *propname) |
| 153 | { | 173 | { |
| @@ -178,6 +198,30 @@ static inline int fwnode_property_read_u64(const struct fwnode_handle *fwnode, | |||
| 178 | return fwnode_property_read_u64_array(fwnode, propname, val, 1); | 198 | return fwnode_property_read_u64_array(fwnode, propname, val, 1); |
| 179 | } | 199 | } |
| 180 | 200 | ||
| 201 | static inline int fwnode_property_count_u8(const struct fwnode_handle *fwnode, | ||
| 202 | const char *propname) | ||
| 203 | { | ||
| 204 | return fwnode_property_read_u8_array(fwnode, propname, NULL, 0); | ||
| 205 | } | ||
| 206 | |||
| 207 | static inline int fwnode_property_count_u16(const struct fwnode_handle *fwnode, | ||
| 208 | const char *propname) | ||
| 209 | { | ||
| 210 | return fwnode_property_read_u16_array(fwnode, propname, NULL, 0); | ||
| 211 | } | ||
| 212 | |||
| 213 | static inline int fwnode_property_count_u32(const struct fwnode_handle *fwnode, | ||
| 214 | const char *propname) | ||
| 215 | { | ||
| 216 | return fwnode_property_read_u32_array(fwnode, propname, NULL, 0); | ||
| 217 | } | ||
| 218 | |||
| 219 | static inline int fwnode_property_count_u64(const struct fwnode_handle *fwnode, | ||
| 220 | const char *propname) | ||
| 221 | { | ||
| 222 | return fwnode_property_read_u64_array(fwnode, propname, NULL, 0); | ||
| 223 | } | ||
| 224 | |||
| 181 | /** | 225 | /** |
| 182 | * struct property_entry - "Built-in" device property representation. | 226 | * struct property_entry - "Built-in" device property representation. |
| 183 | * @name: Name of the property. | 227 | * @name: Name of the property. |
