WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Tiny Core v12.0  (Read 8173 times)

Offline andyj

  • Hero Member
  • *****
  • Posts: 951
Re: Tiny Core v12.0
« Reply #15 on: February 20, 2021, 05:00:35 PM »
@Rich Now that you point it out, yes it does not look like the division is necessary. Based on the surrounding code it is probably for consistency but I could clean it up for speed. There is another further down that I did not post that is used as an argument to some other function so it should stay:

Code: [Select]
+ unsigned long x = ktime_get_seconds();
- epoch_min = ktime_get_seconds() / 60;
+ epoch_min = do_div(x, 60);

@curaga Yes, I believe the time type should be time64_t, but throughout this module long is used so I am going to stick with that.

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 9024
Re: Tiny Core v12.0
« Reply #16 on: February 20, 2021, 07:42:23 PM »
Hi andyj
Forget what I said.
... if a/c == b/c

to which my response would be:

then a == b ...
That's not true for integer math since the remainder gets discarded. I'm guessing the divide by 60 is to convert to
whole minutes and discard any fractional minute.

Offline bela.d

  • Newbie
  • *
  • Posts: 8
Re: Tiny Core v12.0
« Reply #17 on: February 22, 2021, 01:31:12 PM »
Hi all,

I get a kernel panic after updating to v12.0 in VirtualBox Version 6.1.18 amd64 (Windows host).
The VM is Tiny Core x86.

Is anybody else using TC x86 in Virtualbox?

Offline andyj

  • Hero Member
  • *****
  • Posts: 951
Re: Tiny Core v12.0
« Reply #18 on: February 24, 2021, 04:50:58 AM »
For the benefit of people who think TC is a minor distro and we can't create change in the world:

That's probably worth submitting upstream...

Done: https://www.spinics.net/lists/netfilter-devel/msg70361.html

Offline btlneck

  • Newbie
  • *
  • Posts: 1
Re: Tiny Core v12.0
« Reply #19 on: February 27, 2021, 02:51:13 PM »
Hi andyj.
In the original code check peer for NULL prepends peer->login_sec reference.

Code: newbielink:javascript:void(0); [nonactive]
static inline bool
 has_logged_during_this_minute(const struct peer *peer)
 {
- return peer != NULL && peer->login_sec / 60 == ktime_get_seconds() / 60;
+ unsigned long x = ktime_get_seconds();
+ unsigned long y = peer->login_sec;
+ return peer != NULL && do_div(y, 60) == do_div(x, 60);
 }

Excuse me for maybe stupid question, but if the

peer == NULL

whould this code work:

unsigned long y = peer->login_sec;

?

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 9024
Re: Tiny Core v12.0
« Reply #20 on: February 27, 2021, 06:20:24 PM »
Hi btlneck
Welcome to the forum.

Nice catch. If  peer == NULL  then this will segfault:
Code: [Select]
unsigned long y = peer->login_sec;
Maybe casting the times to a long would work:
Code: [Select]
return peer != NULL && do_div((long)peer->login_sec, 60) == do_div((long)ktime_get_seconds(), 60);
« Last Edit: February 27, 2021, 06:43:12 PM by Rich »

Offline andyj

  • Hero Member
  • *****
  • Posts: 951
Re: Tiny Core v12.0
« Reply #21 on: February 28, 2021, 06:35:20 AM »
This is a kernel module, so I would expect it to OOPS. There is a lot of "short circuit" type logic throughout this package, so in this case it should be something like this:

Code: [Select]
- unsigned long x = ktime_get_seconds();
- unsigned long y = peer->login_sec + autoclose_time * 60;
- return peer != NULL && autoclose_time != 0 && time_after(x, y);
+ if (peer != NULL) {
+ unsigned long x = ktime_get_seconds();
+ unsigned long y = peer->login_sec + autoclose_time * 60;
+ return autoclose_time != 0 && time_after(x, y);
+ } else {
+ return 0;
+ }

I can't post the whole patch here because our forum software apparently has a few bugs.

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 9024
Re: Tiny Core v12.0
« Reply #22 on: February 28, 2021, 07:33:56 AM »
Hi andyj
Looks OK. This should work too:
Code: [Select]
if ((peer == NULL) || (autoclose_time == 0))
return 0;

unsigned long x = ktime_get_seconds();
unsigned long y = peer->login_sec + autoclose_time * 60;
return time_after(x, y);

Offline andyj

  • Hero Member
  • *****
  • Posts: 951
Re: Tiny Core v12.0
« Reply #23 on: February 28, 2021, 08:12:31 AM »
That section of code doesn't have the original presenting problem of long division so it doesn't actually need the check anyway because the short circuit would work in that case, and thanks to trying to avoid our forum bug with patches I didn't post the part I should have:

Code: [Select]
static inline bool       
has_logged_during_this_minute(const struct peer *peer)
{                         
        if (peer != NULL) {
                unsigned long x = ktime_get_seconds(), y = peer->login_sec;
                return do_div(y, 60) == do_div(x, 60);
        } else {                     
                return 0;
        }             
}                         

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 9024
Re: Tiny Core v12.0
« Reply #24 on: February 28, 2021, 08:31:57 AM »
Hi andyj
... and thanks to trying to avoid our forum bug with patches I didn't post the part I should have: ...
That explains it. I thought maybe I'd missed something. :)

The compiler won't add any code because of it, but the  return 0;  doesn't need to be wrapped in an  else  clause.

Offline andyj

  • Hero Member
  • *****
  • Posts: 951
Re: Tiny Core v12.0
« Reply #25 on: February 28, 2021, 09:39:03 AM »
There are always different ways to code to get the same end result. In most cases I have learned to prefer towards the solution that reads most naturally and explains what is happening so I won't have to figure it out again the next time I look at it. How many times did I do this in my youth:



Or worse, come behind someone else?