Teach 'interpolate()' about zero-sized ranges

No, they don't make sense.  We should normally not have multiple samples
that are on the same second.  But they seem to happen on the EON Steel
under some circumstances, and instead of dividing by zero when trying to
interpolate across such a sample, do something sane.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Linus Torvalds 2016-08-29 20:05:20 -07:00 committed by Dirk Hohndel
parent 5a66ac7698
commit d8a6b917a5

View file

@ -169,8 +169,11 @@ static inline bool gasmix_is_air(const struct gasmix *gasmix)
static inline int interpolate(int a, int b, int part, int whole) static inline int interpolate(int a, int b, int part, int whole)
{ {
/* It is doubtful that we actually need floating point for this, but whatever */ /* It is doubtful that we actually need floating point for this, but whatever */
double x = (double)a * (whole - part) + (double)b * part; if (whole) {
return rint(x / whole); double x = (double)a * (whole - part) + (double)b * part;
return rint(x / whole);
}
return (a+b)/2;
} }
void get_gas_string(const struct gasmix *gasmix, char *text, int len); void get_gas_string(const struct gasmix *gasmix, char *text, int len);