@@ -1209,108 +1209,145 @@ int of_property_read_u32_index(const struct device_node *np,
1209
1209
EXPORT_SYMBOL_GPL (of_property_read_u32_index );
1210
1210
1211
1211
/**
1212
- * of_property_read_u8_array - Find and read an array of u8 from a property.
1212
+ * of_property_read_variable_u8_array - Find and read an array of u8 from a
1213
+ * property, with bounds on the minimum and maximum array size.
1213
1214
*
1214
1215
* @np: device node from which the property value is to be read.
1215
1216
* @propname: name of the property to be searched.
1216
1217
* @out_values: pointer to return value, modified only if return value is 0.
1217
- * @sz: number of array elements to read
1218
+ * @sz_min: minimum number of array elements to read
1219
+ * @sz_max: maximum number of array elements to read, if zero there is no
1220
+ * upper limit on the number of elements in the dts entry but only
1221
+ * sz_min will be read.
1218
1222
*
1219
1223
* Search for a property in a device node and read 8-bit value(s) from
1220
- * it. Returns 0 on success, -EINVAL if the property does not exist,
1221
- * -ENODATA if property does not have a value, and -EOVERFLOW if the
1222
- * property data isn't large enough .
1224
+ * it. Returns number of elements read on success, -EINVAL if the property
1225
+ * does not exist, -ENODATA if property does not have a value, and -EOVERFLOW
1226
+ * if the property data is smaller than sz_min or longer than sz_max .
1223
1227
*
1224
1228
* dts entry of array should be like:
1225
1229
* property = /bits/ 8 <0x50 0x60 0x70>;
1226
1230
*
1227
1231
* The out_values is modified only if a valid u8 value can be decoded.
1228
1232
*/
1229
- int of_property_read_u8_array (const struct device_node * np ,
1230
- const char * propname , u8 * out_values , size_t sz )
1233
+ int of_property_read_variable_u8_array (const struct device_node * np ,
1234
+ const char * propname , u8 * out_values ,
1235
+ size_t sz_min , size_t sz_max )
1231
1236
{
1237
+ size_t sz , count ;
1232
1238
const u8 * val = of_find_property_value_of_size (np , propname ,
1233
- (sz * sizeof (* out_values )),
1234
- 0 ,
1235
- NULL );
1239
+ (sz_min * sizeof (* out_values )),
1240
+ ( sz_max * sizeof ( * out_values )) ,
1241
+ & sz );
1236
1242
1237
1243
if (IS_ERR (val ))
1238
1244
return PTR_ERR (val );
1239
1245
1240
- while (sz -- )
1246
+ if (!sz_max )
1247
+ sz = sz_min ;
1248
+ else
1249
+ sz /= sizeof (* out_values );
1250
+
1251
+ count = sz ;
1252
+ while (count -- )
1241
1253
* out_values ++ = * val ++ ;
1242
- return 0 ;
1254
+
1255
+ return sz ;
1243
1256
}
1244
- EXPORT_SYMBOL_GPL (of_property_read_u8_array );
1257
+ EXPORT_SYMBOL_GPL (of_property_read_variable_u8_array );
1245
1258
1246
1259
/**
1247
- * of_property_read_u16_array - Find and read an array of u16 from a property.
1260
+ * of_property_read_variable_u16_array - Find and read an array of u16 from a
1261
+ * property, with bounds on the minimum and maximum array size.
1248
1262
*
1249
1263
* @np: device node from which the property value is to be read.
1250
1264
* @propname: name of the property to be searched.
1251
1265
* @out_values: pointer to return value, modified only if return value is 0.
1252
- * @sz: number of array elements to read
1266
+ * @sz_min: minimum number of array elements to read
1267
+ * @sz_max: maximum number of array elements to read, if zero there is no
1268
+ * upper limit on the number of elements in the dts entry but only
1269
+ * sz_min will be read.
1253
1270
*
1254
1271
* Search for a property in a device node and read 16-bit value(s) from
1255
- * it. Returns 0 on success, -EINVAL if the property does not exist,
1256
- * -ENODATA if property does not have a value, and -EOVERFLOW if the
1257
- * property data isn't large enough .
1272
+ * it. Returns number of elements read on success, -EINVAL if the property
1273
+ * does not exist, -ENODATA if property does not have a value, and -EOVERFLOW
1274
+ * if the property data is smaller than sz_min or longer than sz_max .
1258
1275
*
1259
1276
* dts entry of array should be like:
1260
1277
* property = /bits/ 16 <0x5000 0x6000 0x7000>;
1261
1278
*
1262
1279
* The out_values is modified only if a valid u16 value can be decoded.
1263
1280
*/
1264
- int of_property_read_u16_array (const struct device_node * np ,
1265
- const char * propname , u16 * out_values , size_t sz )
1281
+ int of_property_read_variable_u16_array (const struct device_node * np ,
1282
+ const char * propname , u16 * out_values ,
1283
+ size_t sz_min , size_t sz_max )
1266
1284
{
1285
+ size_t sz , count ;
1267
1286
const __be16 * val = of_find_property_value_of_size (np , propname ,
1268
- (sz * sizeof (* out_values )),
1269
- 0 ,
1270
- NULL );
1287
+ (sz_min * sizeof (* out_values )),
1288
+ ( sz_max * sizeof ( * out_values )) ,
1289
+ & sz );
1271
1290
1272
1291
if (IS_ERR (val ))
1273
1292
return PTR_ERR (val );
1274
1293
1275
- while (sz -- )
1294
+ if (!sz_max )
1295
+ sz = sz_min ;
1296
+ else
1297
+ sz /= sizeof (* out_values );
1298
+
1299
+ count = sz ;
1300
+ while (count -- )
1276
1301
* out_values ++ = be16_to_cpup (val ++ );
1277
- return 0 ;
1302
+
1303
+ return sz ;
1278
1304
}
1279
- EXPORT_SYMBOL_GPL (of_property_read_u16_array );
1305
+ EXPORT_SYMBOL_GPL (of_property_read_variable_u16_array );
1280
1306
1281
1307
/**
1282
- * of_property_read_u32_array - Find and read an array of 32 bit integers
1283
- * from a property.
1308
+ * of_property_read_variable_u32_array - Find and read an array of 32 bit
1309
+ * integers from a property, with bounds on the minimum and maximum array size .
1284
1310
*
1285
1311
* @np: device node from which the property value is to be read.
1286
1312
* @propname: name of the property to be searched.
1287
1313
* @out_values: pointer to return value, modified only if return value is 0.
1288
- * @sz: number of array elements to read
1314
+ * @sz_min: minimum number of array elements to read
1315
+ * @sz_max: maximum number of array elements to read, if zero there is no
1316
+ * upper limit on the number of elements in the dts entry but only
1317
+ * sz_min will be read.
1289
1318
*
1290
1319
* Search for a property in a device node and read 32-bit value(s) from
1291
- * it. Returns 0 on success, -EINVAL if the property does not exist,
1292
- * -ENODATA if property does not have a value, and -EOVERFLOW if the
1293
- * property data isn't large enough .
1320
+ * it. Returns number of elements read on success, -EINVAL if the property
1321
+ * does not exist, -ENODATA if property does not have a value, and -EOVERFLOW
1322
+ * if the property data is smaller than sz_min or longer than sz_max .
1294
1323
*
1295
1324
* The out_values is modified only if a valid u32 value can be decoded.
1296
1325
*/
1297
- int of_property_read_u32_array (const struct device_node * np ,
1326
+ int of_property_read_variable_u32_array (const struct device_node * np ,
1298
1327
const char * propname , u32 * out_values ,
1299
- size_t sz )
1328
+ size_t sz_min , size_t sz_max )
1300
1329
{
1330
+ size_t sz , count ;
1301
1331
const __be32 * val = of_find_property_value_of_size (np , propname ,
1302
- (sz * sizeof (* out_values )),
1303
- 0 ,
1304
- NULL );
1332
+ (sz_min * sizeof (* out_values )),
1333
+ ( sz_max * sizeof ( * out_values )) ,
1334
+ & sz );
1305
1335
1306
1336
if (IS_ERR (val ))
1307
1337
return PTR_ERR (val );
1308
1338
1309
- while (sz -- )
1339
+ if (!sz_max )
1340
+ sz = sz_min ;
1341
+ else
1342
+ sz /= sizeof (* out_values );
1343
+
1344
+ count = sz ;
1345
+ while (count -- )
1310
1346
* out_values ++ = be32_to_cpup (val ++ );
1311
- return 0 ;
1347
+
1348
+ return sz ;
1312
1349
}
1313
- EXPORT_SYMBOL_GPL (of_property_read_u32_array );
1350
+ EXPORT_SYMBOL_GPL (of_property_read_variable_u32_array );
1314
1351
1315
1352
/**
1316
1353
* of_property_read_u64 - Find and read a 64 bit integer from a property
@@ -1342,40 +1379,51 @@ int of_property_read_u64(const struct device_node *np, const char *propname,
1342
1379
EXPORT_SYMBOL_GPL (of_property_read_u64 );
1343
1380
1344
1381
/**
1345
- * of_property_read_u64_array - Find and read an array of 64 bit integers
1346
- * from a property.
1382
+ * of_property_read_variable_u64_array - Find and read an array of 64 bit
1383
+ * integers from a property, with bounds on the minimum and maximum array size .
1347
1384
*
1348
1385
* @np: device node from which the property value is to be read.
1349
1386
* @propname: name of the property to be searched.
1350
1387
* @out_values: pointer to return value, modified only if return value is 0.
1351
- * @sz: number of array elements to read
1388
+ * @sz_min: minimum number of array elements to read
1389
+ * @sz_max: maximum number of array elements to read, if zero there is no
1390
+ * upper limit on the number of elements in the dts entry but only
1391
+ * sz_min will be read.
1352
1392
*
1353
1393
* Search for a property in a device node and read 64-bit value(s) from
1354
- * it. Returns 0 on success, -EINVAL if the property does not exist,
1355
- * -ENODATA if property does not have a value, and -EOVERFLOW if the
1356
- * property data isn't large enough .
1394
+ * it. Returns number of elements read on success, -EINVAL if the property
1395
+ * does not exist, -ENODATA if property does not have a value, and -EOVERFLOW
1396
+ * if the property data is smaller than sz_min or longer than sz_max .
1357
1397
*
1358
1398
* The out_values is modified only if a valid u64 value can be decoded.
1359
1399
*/
1360
- int of_property_read_u64_array (const struct device_node * np ,
1400
+ int of_property_read_variable_u64_array (const struct device_node * np ,
1361
1401
const char * propname , u64 * out_values ,
1362
- size_t sz )
1402
+ size_t sz_min , size_t sz_max )
1363
1403
{
1404
+ size_t sz , count ;
1364
1405
const __be32 * val = of_find_property_value_of_size (np , propname ,
1365
- (sz * sizeof (* out_values )),
1366
- 0 ,
1367
- NULL );
1406
+ (sz_min * sizeof (* out_values )),
1407
+ ( sz_max * sizeof ( * out_values )) ,
1408
+ & sz );
1368
1409
1369
1410
if (IS_ERR (val ))
1370
1411
return PTR_ERR (val );
1371
1412
1372
- while (sz -- ) {
1413
+ if (!sz_max )
1414
+ sz = sz_min ;
1415
+ else
1416
+ sz /= sizeof (* out_values );
1417
+
1418
+ count = sz ;
1419
+ while (count -- ) {
1373
1420
* out_values ++ = of_read_number (val , 2 );
1374
1421
val += 2 ;
1375
1422
}
1376
- return 0 ;
1423
+
1424
+ return sz ;
1377
1425
}
1378
- EXPORT_SYMBOL_GPL (of_property_read_u64_array );
1426
+ EXPORT_SYMBOL_GPL (of_property_read_variable_u64_array );
1379
1427
1380
1428
/**
1381
1429
* of_property_read_string - Find and read a string from a property
0 commit comments