On 12/04/2019 15:30, Andrzej Hajda wrote: >>>> +static const unsigned int sii902x_mclk_div_table[] = { >>>> + 128, 256, 384, 512, 768, 1024, 1152, 192 }; >>>> + >>>> +static int sii902x_select_mclk_div(u8 *i2s_config_reg, unsigned int rate, >>>> + unsigned int mclk) >>>> +{ >>>> + unsigned int div = mclk / rate; >>>> + int distance = 100000; >>>> + u8 i, nearest = 0; >>>> + >>>> + for (i = 0; i < ARRAY_SIZE(sii902x_mclk_div_table); i++) { >>>> + unsigned int d = abs(div - sii902x_mclk_div_table[i]); >>> Using unsigned types in this context seems to be asking for troubles. >>> >> Why? Isn't return value of abs() by definition unsigned? Using signed >> integers when comparing absolute distances would seem awkward to me. > > (div - sii902x_mclk_div_table[i]) is unsigned, if div is lower, there is overflow, and the value is big int, I suppose this is not what you want. > Oh yes. I had my eyes fixed on wrong unsigned. The first operand of subtraction should indeed be signed for the result to be signed, I completely overlooked that. Thanks, Jyri -- Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki _______________________________________________ Alsa-devel mailing list Alsa-devel@xxxxxxxxxxxxxxxx https://mailman.alsa-project.org/mailman/listinfo/alsa-devel