Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

of: base: Add of_property_read_u8_index

Add support for of_property_read_u8_index(), simillar to others
u16 and u32 variants. Having this helper makes the code more tidy in
isome cases, specially when we are parsing multiple of these into
data structures.

Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
Reviewed-by: Rob Herring (Arm) <robh@kernel.org>
Tested-by: Alexey Klimov <alexey.klimov@linaro.org> # sm8550
Link: https://patch.msgid.link/20250912083225.228778-2-srinivas.kandagatla@oss.qualcomm.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>

authored by

Srinivas Kandagatla and committed by
Vinod Koul
18223eec 3a866087

+42
+33
drivers/of/property.c
··· 148 148 } 149 149 150 150 /** 151 + * of_property_read_u8_index - Find and read a u8 from a multi-value property. 152 + * 153 + * @np: device node from which the property value is to be read. 154 + * @propname: name of the property to be searched. 155 + * @index: index of the u8 in the list of values 156 + * @out_value: pointer to return value, modified only if no error. 157 + * 158 + * Search for a property in a device node and read nth 8-bit value from 159 + * it. 160 + * 161 + * Return: 0 on success, -EINVAL if the property does not exist, 162 + * -ENODATA if property does not have a value, and -EOVERFLOW if the 163 + * property data isn't large enough. 164 + * 165 + * The out_value is modified only if a valid u8 value can be decoded. 166 + */ 167 + int of_property_read_u8_index(const struct device_node *np, 168 + const char *propname, 169 + u32 index, u8 *out_value) 170 + { 171 + const u8 *val = of_find_property_value_of_size(np, propname, 172 + ((index + 1) * sizeof(*out_value)), 173 + 0, NULL); 174 + 175 + if (IS_ERR(val)) 176 + return PTR_ERR(val); 177 + 178 + *out_value = val[index]; 179 + return 0; 180 + } 181 + EXPORT_SYMBOL_GPL(of_property_read_u8_index); 182 + 183 + /** 151 184 * of_property_read_u16_index - Find and read a u16 from a multi-value property. 152 185 * 153 186 * @np: device node from which the property value is to be read.
+9
include/linux/of.h
··· 316 316 extern bool of_property_read_bool(const struct device_node *np, const char *propname); 317 317 extern int of_property_count_elems_of_size(const struct device_node *np, 318 318 const char *propname, int elem_size); 319 + extern int of_property_read_u8_index(const struct device_node *np, 320 + const char *propname, 321 + u32 index, u8 *out_value); 319 322 extern int of_property_read_u16_index(const struct device_node *np, 320 323 const char *propname, 321 324 u32 index, u16 *out_value); ··· 645 642 646 643 static inline int of_property_count_elems_of_size(const struct device_node *np, 647 644 const char *propname, int elem_size) 645 + { 646 + return -ENOSYS; 647 + } 648 + 649 + static inline int of_property_read_u8_index(const struct device_node *np, 650 + const char *propname, u32 index, u8 *out_value) 648 651 { 649 652 return -ENOSYS; 650 653 }