DF-4666 / find_closest_vddci_zero_patched.c
/* * DF-4666 PATCHED twin — identical harness with the fix.diff guard * (empty table returns the caller's vddci instead of entries[0xFFFFFFFF]). */ #include <stdio.h> #include <stdlib.h> #include <stdint.h> #define PP_ATOMCTRL_MAX_VOLTAGE_ENTRIES 32 struct pp_atomctrl_voltage_table_entry { uint16_t value; uint32_t smio_low; }; struct pp_atomctrl_voltage_table { uint32_t count; uint32_t mask_low; uint32_t phase_delay; struct pp_atomctrl_voltage_table_entry entries[PP_ATOMCTRL_MAX_VOLTAGE_ENTRIES]; }; /* PATCHED per fix.diff */ uint16_t phm_find_closest_vddci_fixed(struct pp_atomctrl_voltage_table *vddci_table, uint16_t vddci) { uint32_t i; if (vddci_table == NULL || vddci_table->count == 0 || vddci_table->count > PP_ATOMCTRL_MAX_VOLTAGE_ENTRIES) return vddci; for (i = 0; i < vddci_table->count; i++) { if (vddci_table->entries[i].value >= vddci) return vddci_table->entries[i].value; } printf("vddci is larger than max value in vddci_table\n"); return vddci_table->entries[i-1].value; } int main(void) { struct pp_atomctrl_voltage_table *t = calloc(1, sizeof(*t)); uint16_t r; t->count = 0; r = phm_find_closest_vddci_fixed(t, 1000); printf("[patched] count=0 -> returned %u (caller's request), NO wild access\n", r); t->count = 4; for (uint32_t k = 0; k < 4; k++) t->entries[k].value = (uint16_t)(800 + 10 * k); r = phm_find_closest_vddci_fixed(t, 9999); printf("[patched] count=4 -> returned %u (normal path intact)\n", r); printf("FIX VALIDATED: empty table no longer indexes entries[0xFFFFFFFF]\n"); return 0; } |