@@ -1146,26 +1146,33 @@ EXPORT_SYMBOL_GPL(of_property_count_elems_of_size);
11461146 *
11471147 * @np: device node from which the property value is to be read.
11481148 * @propname: name of the property to be searched.
1149- * @len: requested length of property value
1149+ * @min: minimum allowed length of property value
1150+ * @max: maximum allowed length of property value (0 means unlimited)
1151+ * @len: if !=NULL, actual length is written to here
11501152 *
11511153 * Search for a property in a device node and valid the requested size.
11521154 * Returns the property value on success, -EINVAL if the property does not
11531155 * exist, -ENODATA if property does not have a value, and -EOVERFLOW if the
1154- * property data isn't large enough .
1156+ * property data is too small or too large .
11551157 *
11561158 */
11571159static void * of_find_property_value_of_size (const struct device_node * np ,
1158- const char * propname , u32 len )
1160+ const char * propname , u32 min , u32 max , size_t * len )
11591161{
11601162 struct property * prop = of_find_property (np , propname , NULL );
11611163
11621164 if (!prop )
11631165 return ERR_PTR (- EINVAL );
11641166 if (!prop -> value )
11651167 return ERR_PTR (- ENODATA );
1166- if (len > prop -> length )
1168+ if (prop -> length < min )
1169+ return ERR_PTR (- EOVERFLOW );
1170+ if (max && prop -> length > max )
11671171 return ERR_PTR (- EOVERFLOW );
11681172
1173+ if (len )
1174+ * len = prop -> length ;
1175+
11691176 return prop -> value ;
11701177}
11711178
@@ -1189,7 +1196,9 @@ int of_property_read_u32_index(const struct device_node *np,
11891196 u32 index , u32 * out_value )
11901197{
11911198 const u32 * val = of_find_property_value_of_size (np , propname ,
1192- ((index + 1 ) * sizeof (* out_value )));
1199+ ((index + 1 ) * sizeof (* out_value )),
1200+ 0 ,
1201+ NULL );
11931202
11941203 if (IS_ERR (val ))
11951204 return PTR_ERR (val );
@@ -1221,7 +1230,9 @@ int of_property_read_u8_array(const struct device_node *np,
12211230 const char * propname , u8 * out_values , size_t sz )
12221231{
12231232 const u8 * val = of_find_property_value_of_size (np , propname ,
1224- (sz * sizeof (* out_values )));
1233+ (sz * sizeof (* out_values )),
1234+ 0 ,
1235+ NULL );
12251236
12261237 if (IS_ERR (val ))
12271238 return PTR_ERR (val );
@@ -1254,7 +1265,9 @@ int of_property_read_u16_array(const struct device_node *np,
12541265 const char * propname , u16 * out_values , size_t sz )
12551266{
12561267 const __be16 * val = of_find_property_value_of_size (np , propname ,
1257- (sz * sizeof (* out_values )));
1268+ (sz * sizeof (* out_values )),
1269+ 0 ,
1270+ NULL );
12581271
12591272 if (IS_ERR (val ))
12601273 return PTR_ERR (val );
@@ -1286,7 +1299,9 @@ int of_property_read_u32_array(const struct device_node *np,
12861299 size_t sz )
12871300{
12881301 const __be32 * val = of_find_property_value_of_size (np , propname ,
1289- (sz * sizeof (* out_values )));
1302+ (sz * sizeof (* out_values )),
1303+ 0 ,
1304+ NULL );
12901305
12911306 if (IS_ERR (val ))
12921307 return PTR_ERR (val );
@@ -1314,7 +1329,9 @@ int of_property_read_u64(const struct device_node *np, const char *propname,
13141329 u64 * out_value )
13151330{
13161331 const __be32 * val = of_find_property_value_of_size (np , propname ,
1317- sizeof (* out_value ));
1332+ sizeof (* out_value ),
1333+ 0 ,
1334+ NULL );
13181335
13191336 if (IS_ERR (val ))
13201337 return PTR_ERR (val );
@@ -1345,7 +1362,9 @@ int of_property_read_u64_array(const struct device_node *np,
13451362 size_t sz )
13461363{
13471364 const __be32 * val = of_find_property_value_of_size (np , propname ,
1348- (sz * sizeof (* out_values )));
1365+ (sz * sizeof (* out_values )),
1366+ 0 ,
1367+ NULL );
13491368
13501369 if (IS_ERR (val ))
13511370 return PTR_ERR (val );
0 commit comments