From b9361dc088985af79384e36b3e9ae3a9a1f20af6 Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Wed, 29 Jan 2014 14:39:34 +0000 Subject: [PATCH] libsensors: Adjust memory pre-allocation steps Make memory pre-allocation steps depend on the sensor type. Things like voltages, temperatures or fans are typically plenty, however vid and chassis intrusion are typically only a few, and there can only be one beep_enable by design. This saves a small amount of temporary memory for cheap. --- lib/sysfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/sysfs.c b/lib/sysfs.c index 6789127e..89ad4001 100644 --- a/lib/sysfs.c +++ b/lib/sysfs.c @@ -480,9 +480,11 @@ static int sensors_read_dynamic_chip(sensors_chip_features *chip, /* (Re-)allocate memory if needed */ if (all_types[ftype].count < nr + 1) { int old_count = all_types[ftype].count; + int step = ftype < SENSORS_FEATURE_VID ? 8 : + ftype < SENSORS_FEATURE_BEEP_ENABLE ? 2 : 1; while (all_types[ftype].count < nr + 1) - all_types[ftype].count += 8; + all_types[ftype].count += step; all_types[ftype].sf = realloc(all_types[ftype].sf, all_types[ftype].count *