Tiny Core Base > Final Releases

Tiny Core v12.0

<< < (5/6) > >>

Rich:
Hi btlneck
Welcome to the forum.

Nice catch. If  peer == NULL  then this will segfault:

--- Code: ---unsigned long y = peer->login_sec;
--- End code ---

Maybe casting the times to a long would work:

--- Code: ---return peer != NULL && do_div((long)peer->login_sec, 60) == do_div((long)ktime_get_seconds(), 60);
--- End code ---

andyj:
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: ---- 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;
+ }

--- End code ---

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

Rich:
Hi andyj
Looks OK. This should work too:

--- Code: --- 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);
--- End code ---

andyj:
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: ---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;
        }             
}                         

--- End code ---

Rich:
Hi andyj

--- Quote from: andyj on February 28, 2021, 11:12:31 AM --- ... and thanks to trying to avoid our forum bug with patches I didn't post the part I should have: ...
--- End quote ---
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.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version