Skip to content

Commit 6d47411

Browse files
committed
drivers: video: sw_generator: use IN_RANGE() when possible
Use the IN_RANGE() macro to compare a format against the format caps width/height_min and width/height_max fields. Signed-off-by: Josuah Demangeon <[email protected]>
1 parent 4bd15f7 commit 6d47411

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

drivers/video/video_sw_generator.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <zephyr/drivers/video.h>
1111
#include <zephyr/drivers/video-controls.h>
1212
#include <zephyr/logging/log.h>
13+
#include <zephyr/sys/util.h>
1314

1415
LOG_MODULE_REGISTER(video_sw_generator, CONFIG_VIDEO_LOG_LEVEL);
1516

@@ -71,9 +72,9 @@ static int video_sw_generator_set_fmt(const struct device *dev, enum video_endpo
7172
}
7273

7374
for (i = 0; i < ARRAY_SIZE(fmts); ++i) {
74-
if (fmt->pixelformat == fmts[i].pixelformat && fmt->width >= fmts[i].width_min &&
75-
fmt->width <= fmts[i].width_max && fmt->height >= fmts[i].height_min &&
76-
fmt->height <= fmts[i].height_max) {
75+
if (fmt->pixelformat == fmts[i].pixelformat &&
76+
IN_RANGE(fmt->width, fmts[i].width_min, fmts[i].width_max) &&
77+
IN_RANGE(fmt->height, fmts[i].height_min, fmts[i].height_max)) {
7778
break;
7879
}
7980
}
@@ -321,10 +322,9 @@ static int video_sw_generator_enum_frmival(const struct device *dev, enum video_
321322
i++;
322323
}
323324

324-
if ((i == ARRAY_SIZE(fmts)) || (fie->format->width > fmts[i].width_max) ||
325-
(fie->format->width < fmts[i].width_min) ||
326-
(fie->format->height > fmts[i].height_max) ||
327-
(fie->format->height < fmts[i].height_min)) {
325+
if ((i == ARRAY_SIZE(fmts)) ||
326+
!IN_RANGE(fie->format->width, fmts[i].width_min, fmts[i].width_max) &&
327+
!IN_RANGE(fie->format->height, fmts[i].height_min, fmts[i].height_max)) {
328328
return -EINVAL;
329329
}
330330

0 commit comments

Comments
 (0)