Skip to content

Conversation

@raiden00pl
Copy link
Member

Summary

drivers/can/can.c: fix broken O_NONBLOCK

O_NONBLOCK open mode was broken since #17360

MIN() comapres signed value (int) with unsigned value (size_t) which causes an unexpected return value when ret is negative.

Impact

fix regression

Testing

simulator with CAN.

a simple test showing that the previous code was wrong:

#include <stdio.h>

int main()
{
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
  int x = -11; size_t y = 11;
  printf("x=%d y=%d min=%d min=%d\n", x, y, MIN(x,y), MIN(x,(int)y));
  return 0;
}
x=-11 y=11 min=11 min=-11

@github-actions github-actions bot added Area: Drivers Drivers issues Size: XS The size of the change in this PR is very small labels Dec 7, 2025
acassis
acassis previously approved these changes Dec 7, 2025
Copy link
Contributor

@acassis acassis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

linguini1
linguini1 previously approved these changes Dec 9, 2025
O_NONBLOCK open mode was broken since
apache#17360

MIN() comapres signed value (int) with unsigned value (size_t) which causes
an unexpected return value when ret is negative

Signed-off-by: raiden00pl <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Drivers Drivers issues Size: XS The size of the change in this PR is very small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants