@@ -1146,26 +1146,33 @@ EXPORT_SYMBOL_GPL(of_property_count_elems_of_size);
1146
1146
*
1147
1147
* @np: device node from which the property value is to be read.
1148
1148
* @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
1150
1152
*
1151
1153
* Search for a property in a device node and valid the requested size.
1152
1154
* Returns the property value on success, -EINVAL if the property does not
1153
1155
* 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 .
1155
1157
*
1156
1158
*/
1157
1159
static 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 )
1159
1161
{
1160
1162
struct property * prop = of_find_property (np , propname , NULL );
1161
1163
1162
1164
if (!prop )
1163
1165
return ERR_PTR (- EINVAL );
1164
1166
if (!prop -> value )
1165
1167
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 )
1167
1171
return ERR_PTR (- EOVERFLOW );
1168
1172
1173
+ if (len )
1174
+ * len = prop -> length ;
1175
+
1169
1176
return prop -> value ;
1170
1177
}
1171
1178
@@ -1189,7 +1196,9 @@ int of_property_read_u32_index(const struct device_node *np,
1189
1196
u32 index , u32 * out_value )
1190
1197
{
1191
1198
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 );
1193
1202
1194
1203
if (IS_ERR (val ))
1195
1204
return PTR_ERR (val );
@@ -1221,7 +1230,9 @@ int of_property_read_u8_array(const struct device_node *np,
1221
1230
const char * propname , u8 * out_values , size_t sz )
1222
1231
{
1223
1232
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 );
1225
1236
1226
1237
if (IS_ERR (val ))
1227
1238
return PTR_ERR (val );
@@ -1254,7 +1265,9 @@ int of_property_read_u16_array(const struct device_node *np,
1254
1265
const char * propname , u16 * out_values , size_t sz )
1255
1266
{
1256
1267
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 );
1258
1271
1259
1272
if (IS_ERR (val ))
1260
1273
return PTR_ERR (val );
@@ -1286,7 +1299,9 @@ int of_property_read_u32_array(const struct device_node *np,
1286
1299
size_t sz )
1287
1300
{
1288
1301
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 );
1290
1305
1291
1306
if (IS_ERR (val ))
1292
1307
return PTR_ERR (val );
@@ -1314,7 +1329,9 @@ int of_property_read_u64(const struct device_node *np, const char *propname,
1314
1329
u64 * out_value )
1315
1330
{
1316
1331
const __be32 * val = of_find_property_value_of_size (np , propname ,
1317
- sizeof (* out_value ));
1332
+ sizeof (* out_value ),
1333
+ 0 ,
1334
+ NULL );
1318
1335
1319
1336
if (IS_ERR (val ))
1320
1337
return PTR_ERR (val );
@@ -1345,7 +1362,9 @@ int of_property_read_u64_array(const struct device_node *np,
1345
1362
size_t sz )
1346
1363
{
1347
1364
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 );
1349
1368
1350
1369
if (IS_ERR (val ))
1351
1370
return PTR_ERR (val );
0 commit comments