Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1338033 > unrolled thread

m88ds3103: Undefined division

Started byPeter Rosin <peda@lysator.liu.se>
First post2016-02-19 11:20 +0100
Last post2016-02-19 11:50 +0100
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  m88ds3103: Undefined division Peter Rosin <peda@lysator.liu.se> - 2016-02-19 11:20 +0100
    Re: m88ds3103: Undefined division Antti Palosaari <crope@iki.fi> - 2016-02-19 11:50 +0100

#1338033 — m88ds3103: Undefined division

FromPeter Rosin <peda@lysator.liu.se>
Date2016-02-19 11:20 +0100
Subjectm88ds3103: Undefined division
Message-ID<r3Qki-3vx-17@gated-at.bofh.it>
Hi!

I'm looking at this code in drivers/media/dvb-frontends/m88ds3103.c in
the m88ds3103_set_frontend() function, line 600 (give or take):

	s32tmp = 0x10000 * (tuner_frequency - c->frequency);
	s32tmp = DIV_ROUND_CLOSEST(s32tmp, priv->mclk_khz);
	if (s32tmp < 0)
		s32tmp += 0x10000;

There is code that tries to handle negative s32tmp, so I assume that
negative s32tmp is a possibility. Further, priv->mclk_khz is an unsigned
type as far as I can tell. But then we have this comment for the
DIV_ROUND_CLOSEST macro:

/*
 * Divide positive or negative dividend by positive divisor and round
 * to closest integer. Result is undefined for negative divisors and
 * for negative dividends if the divisor variable type is unsigned.
 */
#define DIV_ROUND_CLOSEST(x, divisor)(                  \

I don't know how bad this is, and what the consequences of garbage are,
but from here it looks like a problem waiting to happen...

Cheers,
Peter

[toc] | [next] | [standalone]


#1338045

FromAntti Palosaari <crope@iki.fi>
Date2016-02-19 11:50 +0100
Message-ID<r3QNj-3My-11@gated-at.bofh.it>
In reply to#1338033
On 02/19/2016 12:10 PM, Peter Rosin wrote:
> Hi!
>
> I'm looking at this code in drivers/media/dvb-frontends/m88ds3103.c in
> the m88ds3103_set_frontend() function, line 600 (give or take):
>
> 	s32tmp = 0x10000 * (tuner_frequency - c->frequency);
> 	s32tmp = DIV_ROUND_CLOSEST(s32tmp, priv->mclk_khz);
> 	if (s32tmp < 0)
> 		s32tmp += 0x10000;
>
> There is code that tries to handle negative s32tmp, so I assume that
> negative s32tmp is a possibility. Further, priv->mclk_khz is an unsigned
> type as far as I can tell. But then we have this comment for the
> DIV_ROUND_CLOSEST macro:
>
> /*
>   * Divide positive or negative dividend by positive divisor and round
>   * to closest integer. Result is undefined for negative divisors and
>   * for negative dividends if the divisor variable type is unsigned.
>   */
> #define DIV_ROUND_CLOSEST(x, divisor)(                  \
>
> I don't know how bad this is, and what the consequences of garbage are,
> but from here it looks like a problem waiting to happen...

Divisor type (mclk) needs to be changed signed then somehow...

regards
Antti

-- 
http://palosaari.fi/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web