[PATCH v5 6/6] drm/bridge: sii902x: Implement HDMI audio support

Andrzej Hajda a.hajda at samsung.com
Mon Apr 15 09:44:41 UTC 2019


On 15.04.2019 09:26, Jyri Sarha wrote:
> 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.


Worse, both operands must be int to avoid casting to unsigned.


Regards

Andrzej


>
> Thanks,
> Jyri
>
>
>



More information about the dri-devel mailing list