linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH 5/8] staging: rtl8188eu: Remove function rtw_modular64()
       [not found] <20190712071746.2474-5-nishkadg.linux@gmail.com>
@ 2020-04-12 13:34 ` Ivan Safonov
  2020-04-14 11:56   ` Dan Carpenter
  0 siblings, 1 reply; 4+ messages in thread
From: Ivan Safonov @ 2020-04-12 13:34 UTC (permalink / raw)
  To: Nishka Dasgupta, Larry Finger, Greg Kroah-Hartman,
	Michael Straube, devel, linux-kernel

> Remove function rtw_modular64 as all it does is call do_div.

This is wrong. Macro do_div(x, y) change first argument x, but 
rtw_modular64(x, y) preserve it.

> +			tsf = pmlmeext->TSFValue - do_div(pmlmeext->TSFValue, (pmlmeinfo->bcn_interval*1024)) - 1024; /* us */

rounddown(pmlmeext->TSFValue, pmlmeinfo->bcn_interval * 1024) - 1024
is a better replacement for

> -			tsf = pmlmeext->TSFValue - rtw_modular64(pmlmeext->TSFValue, (pmlmeinfo->bcn_interval*1024)) - 1024; /* us */

Patch '[PATCH 01/10] staging: rtl8723bs: Remove function 
rtw_modular64()' have same bug.

Ivan Safonov.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 5/8] staging: rtl8188eu: Remove function rtw_modular64()
  2020-04-12 13:34 ` [PATCH 5/8] staging: rtl8188eu: Remove function rtw_modular64() Ivan Safonov
@ 2020-04-14 11:56   ` Dan Carpenter
  2020-04-14 12:22     ` Ivan Safonov
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2020-04-14 11:56 UTC (permalink / raw)
  To: Ivan Safonov
  Cc: Nishka Dasgupta, Larry Finger, Greg Kroah-Hartman,
	Michael Straube, devel, linux-kernel

On Sun, Apr 12, 2020 at 04:34:08PM +0300, Ivan Safonov wrote:
> > Remove function rtw_modular64 as all it does is call do_div.
> 
> This is wrong. Macro do_div(x, y) change first argument x, but
> rtw_modular64(x, y) preserve it.
> 
> > +			tsf = pmlmeext->TSFValue - do_div(pmlmeext->TSFValue, (pmlmeinfo->bcn_interval*1024)) - 1024; /* us */
> 
> rounddown(pmlmeext->TSFValue, pmlmeinfo->bcn_interval * 1024) - 1024
> is a better replacement for

You're absolutely correct that the patch is buggy, but I'm not sure that
rounddown() is what we want.

rtw_modular64() took the MOD of x.  So it should be something like:

	tsf = pmlmeext->TSFValue - (pmlmeext->TSFValue % (pmlmeinfo->bcn_interval * 1024)) - 1024; /* us */

But what the heck is that even???  If pmlmeinfo->bcn_interval is zero
or one then the subtraction ends up giving us a negative.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 5/8] staging: rtl8188eu: Remove function rtw_modular64()
  2020-04-14 11:56   ` Dan Carpenter
@ 2020-04-14 12:22     ` Ivan Safonov
  2020-04-14 13:25       ` Dan Carpenter
  0 siblings, 1 reply; 4+ messages in thread
From: Ivan Safonov @ 2020-04-14 12:22 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Nishka Dasgupta, Larry Finger, Greg Kroah-Hartman,
	Michael Straube, devel, linux-kernel

On 4/14/20 2:56 PM, Dan Carpenter wrote:
> On Sun, Apr 12, 2020 at 04:34:08PM +0300, Ivan Safonov wrote:
>>> Remove function rtw_modular64 as all it does is call do_div.
>>
>> This is wrong. Macro do_div(x, y) change first argument x, but
>> rtw_modular64(x, y) preserve it.
>>
>>> +			tsf = pmlmeext->TSFValue - do_div(pmlmeext->TSFValue, (pmlmeinfo->bcn_interval*1024)) - 1024; /* us */
>>
>> rounddown(pmlmeext->TSFValue, pmlmeinfo->bcn_interval * 1024) - 1024
>> is a better replacement for
> 
> You're absolutely correct that the patch is buggy, but I'm not sure that
> rounddown() is what we want.
> 
> rtw_modular64() took the MOD of x.  So it should be something like:
> 
> 	tsf = pmlmeext->TSFValue - (pmlmeext->TSFValue % (pmlmeinfo->bcn_interval * 1024)) - 1024; /* us */
> 
> But what the heck is that even???  If pmlmeinfo->bcn_interval is zero
> or one then the subtraction ends up giving us a negative.
> 
> regards,
> dan carpenter
> 

1. pmlmeext->TSFValue can not be negative, because it is uint64_t;
2. pmlmeext->TSFValue is cyclic value:
     https://en.wikipedia.org/wiki/Timing_synchronization_function ;
3. (rounddown(a, b)) is equal to (a - a % b) by definition.

Ivan Safonov.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 5/8] staging: rtl8188eu: Remove function rtw_modular64()
  2020-04-14 12:22     ` Ivan Safonov
@ 2020-04-14 13:25       ` Dan Carpenter
  0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2020-04-14 13:25 UTC (permalink / raw)
  To: Ivan Safonov
  Cc: devel, Greg Kroah-Hartman, linux-kernel, Nishka Dasgupta, Larry Finger

On Tue, Apr 14, 2020 at 03:22:59PM +0300, Ivan Safonov wrote:
> On 4/14/20 2:56 PM, Dan Carpenter wrote:
> > On Sun, Apr 12, 2020 at 04:34:08PM +0300, Ivan Safonov wrote:
> > > > Remove function rtw_modular64 as all it does is call do_div.
> > > 
> > > This is wrong. Macro do_div(x, y) change first argument x, but
> > > rtw_modular64(x, y) preserve it.
> > > 
> > > > +			tsf = pmlmeext->TSFValue - do_div(pmlmeext->TSFValue, (pmlmeinfo->bcn_interval*1024)) - 1024; /* us */
> > > 
> > > rounddown(pmlmeext->TSFValue, pmlmeinfo->bcn_interval * 1024) - 1024
> > > is a better replacement for
> > 
> > You're absolutely correct that the patch is buggy, but I'm not sure that
> > rounddown() is what we want.
> > 
> > rtw_modular64() took the MOD of x.  So it should be something like:
> > 
> > 	tsf = pmlmeext->TSFValue - (pmlmeext->TSFValue % (pmlmeinfo->bcn_interval * 1024)) - 1024; /* us */
> > 
> > But what the heck is that even???  If pmlmeinfo->bcn_interval is zero
> > or one then the subtraction ends up giving us a negative.
> > 
> > regards,
> > dan carpenter
> > 
> 
> 1. pmlmeext->TSFValue can not be negative, because it is uint64_t;
> 2. pmlmeext->TSFValue is cyclic value:
>     https://en.wikipedia.org/wiki/Timing_synchronization_function ;
> 3. (rounddown(a, b)) is equal to (a - a % b) by definition.

Yeah.  You're right.  I got mixed up and I misread what you were
suggesting.

	tsf = rounddown(pmlmeext->TSFValue, pmlmeinfo->bcn_interval * 1024) - 1024;

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-04-14 13:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20190712071746.2474-5-nishkadg.linux@gmail.com>
2020-04-12 13:34 ` [PATCH 5/8] staging: rtl8188eu: Remove function rtw_modular64() Ivan Safonov
2020-04-14 11:56   ` Dan Carpenter
2020-04-14 12:22     ` Ivan Safonov
2020-04-14 13:25       ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).