modules/batt_health/nvm.c
static void nvm_file_bms_data_purify(bhd_state_t *state)
{
	/* Limit table for BMS values.  Set limit value to BHD_INVALID_VALUE if there is no
	   limit */
	const nvm_file_limit_t limit_table[] = {
		/* TODO: Need to determine valid ranges for:
		   real_fcc_batt_temp, real_fcc, rbatt */
		{offsetof(bhd_state_t, bms.soc), 0, 100,
		 	 BHD_INVALID_VALUE, "SOC"},
		/* TODO: These values reasonable? */
		{offsetof(bhd_state_t, bms.ocv_uv), 1000000, 5000000,
			 BHD_INVALID_VALUE, "OCV UV"},
		{offsetof(bhd_state_t, bms.charge_increase), 0, 100,
		 	0, "charge increase"},
		{offsetof(bhd_state_t, bms.chargecycles), 0, BHD_INVALID_VALUE,
		 	0, "charge cycles"},
		{offsetof(bhd_state_t, aged_capacity), 0, 100,
		 	0, "aged capacity"}
	};
	int num_elem = (sizeof(limit_table) / sizeof(limit_table[0]));
	int i;
	int *val_ptr;

	for (i = 0; i < num_elem; i++) {
		val_ptr = (int*)( (char *) state + limit_table[i].offset);
		ALOGV("NVM purify check - %s value = %d (range: low = %d, high = %d)",
			limit_table[i].name, *val_ptr,
			limit_table[i].low_limit, limit_table[i].high_limit);
		if (*val_ptr != BHD_INVALID_VALUE) {
			if ( (limit_table[i].low_limit != BHD_INVALID_VALUE) &&
				(*val_ptr < limit_table[i].low_limit)) {
				ALOGE("NVM purify check - Parameter %s "
					"too low = %d, reset to %d",
					limit_table[i].name, *val_ptr, limit_table[i].def_val);
				*val_ptr = limit_table[i].def_val;
			} else if ( (limit_table[i].high_limit != BHD_INVALID_VALUE) &&
				(*val_ptr > limit_table[i].high_limit)) {
				ALOGE("NVM purify check - Parameter %s "
					"too high = %d, reset to %d",
					limit_table[i].name, *val_ptr, limit_table[i].def_val);
				*val_ptr = limit_table[i].def_val;
			}
		}
	}
}
/* Does range checks on data read from NVM */
Does range checks on data read from NVM
Does range checks on data read from NVM
static void nvm_file_bms_data_purify(bhd_state_t *state)
{
	const nvm_file_limit_t limit_table[] = {
		{offsetof(bhd_state_t, bms.soc), 0, 100,
		 	 BHD_INVALID_VALUE, "SOC"},
		{offsetof(bhd_state_t, bms.ocv_uv), 1000000, 5000000,
			 BHD_INVALID_VALUE, "OCV UV"},
		{offsetof(bhd_state_t, bms.charge_increase), 0, 100,
		 	0, "charge increase"},
		{offsetof(bhd_state_t, bms.chargecycles), 0, BHD_INVALID_VALUE,
		 	0, "charge cycles"},
		{offsetof(bhd_state_t, aged_capacity), 0, 100,
		 	0, "aged capacity"}
	};
	int num_elem = (sizeof(limit_table) / sizeof(limit_table[0]));
	int i;
	int *val_ptr;
	for (i = 0; i < num_elem; i++) {
		val_ptr = (int*)( (char *) state + limit_table[i].offset);
		ALOGV("NVM purify check - %s value = %d (range: low = %d, high = %d)",
			limit_table[i].name, *val_ptr,
			limit_table[i].low_limit, limit_table[i].high_limit);
		if (*val_ptr != BHD_INVALID_VALUE) {
			if ( (limit_table[i].low_limit != BHD_INVALID_VALUE) &&
				(*val_ptr < limit_table[i].low_limit)) {
				ALOGE("NVM purify check - Parameter %s "
					"too low = %d, reset to %d",
					limit_table[i].name, *val_ptr, limit_table[i].def_val);
				*val_ptr = limit_table[i].def_val;
			} else if ( (limit_table[i].high_limit != BHD_INVALID_VALUE) &&
				(*val_ptr > limit_table[i].high_limit)) {
				ALOGE("NVM purify check - Parameter %s "
					"too high = %d, reset to %d",
					limit_table[i].name, *val_ptr, limit_table[i].def_val);
				*val_ptr = limit_table[i].def_val;
			}
		}
	}
}
static void nvm_file_bms_data_purify ( bhd_state_t * state ) { const nvm_file_limit_t limit_table [ ] = { { offsetof ( bhd_state_t , bms . soc ) , 0 , 100 , BHD_INVALID_VALUE , " " } , { offsetof ( bhd_state_t , bms . ocv_uv ) , 1000000 , 5000000 , BHD_INVALID_VALUE , " " } , { offsetof ( bhd_state_t , bms . charge_increase ) , 0 , 100 , 0 , " " } , { offsetof ( bhd_state_t , bms . chargecycles ) , 0 , BHD_INVALID_VALUE , 0 , " " } , { offsetof ( bhd_state_t , aged_capacity ) , 0 , 100 , 0 , " " } } ; int num_elem = ( sizeof ( limit_table ) / sizeof ( limit_table [ 0 ] ) ) ; int i ; int * val_ptr ; for ( i = 0 ; i < num_elem ; i ++ ) { val_ptr = ( int * ) ( ( char * ) state + limit_table [ i ] . offset ) ; ALOGV ( " " , limit_table [ i ] . name , * val_ptr , limit_table [ i ] . low_limit , limit_table [ i ] . high_limit ) ; if ( * val_ptr != BHD_INVALID_VALUE ) { if ( ( limit_table [ i ] . low_limit != BHD_INVALID_VALUE ) && ( * val_ptr < limit_table [ i ] . low_limit ) ) { ALOGE ( " " " " , limit_table [ i ] . name , * val_ptr , limit_table [ i ] . def_val ) ; * val_ptr = limit_table [ i ] . def_val ; } else if ( ( limit_table [ i ] . high_limit != BHD_INVALID_VALUE ) && ( * val_ptr > limit_table [ i ] . high_limit ) ) { ALOGE ( " " " " , limit_table [ i ] . name , * val_ptr , limit_table [ i ] . def_val ) ; * val_ptr = limit_table [ i ] . def_val ; } } } }
Does range checks on data read from NVM
Does range checks on data read from NVM
/* Limit table for BMS values.  Set limit value to BHD_INVALID_VALUE if there is no
	   limit */ /* TODO: Need to determine valid ranges for:
		   real_fcc_batt_temp, real_fcc, rbatt */ /* TODO: These values reasonable? */