Skip to content

Commit 7f2a66e

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 <me@josuah.net>
1 parent 7eea58d commit 7f2a66e

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
#include "video_ctrls.h"
1516
#include "video_device.h"
@@ -72,9 +73,9 @@ static int video_sw_generator_set_fmt(const struct device *dev, struct video_for
7273
int i = 0;
7374

7475
for (i = 0; i < ARRAY_SIZE(fmts); ++i) {
75-
if (fmt->pixelformat == fmts[i].pixelformat && fmt->width >= fmts[i].width_min &&
76-
fmt->width <= fmts[i].width_max && fmt->height >= fmts[i].height_min &&
77-
fmt->height <= fmts[i].height_max) {
76+
if (fmt->pixelformat == fmts[i].pixelformat &&
77+
IN_RANGE(fmt->width, fmts[i].width_min, fmts[i].width_max) &&
78+
IN_RANGE(fmt->height, fmts[i].height_min, fmts[i].height_max)) {
7879
break;
7980
}
8081
}
@@ -283,10 +284,9 @@ static int video_sw_generator_enum_frmival(const struct device *dev, struct vide
283284
i++;
284285
}
285286

286-
if ((i == ARRAY_SIZE(fmts)) || (fie->format->width > fmts[i].width_max) ||
287-
(fie->format->width < fmts[i].width_min) ||
288-
(fie->format->height > fmts[i].height_max) ||
289-
(fie->format->height < fmts[i].height_min)) {
287+
if ((i == ARRAY_SIZE(fmts)) ||
288+
!IN_RANGE(fie->format->width, fmts[i].width_min, fmts[i].width_max) &&
289+
!IN_RANGE(fie->format->height, fmts[i].height_min, fmts[i].height_max)) {
290290
return -EINVAL;
291291
}
292292

0 commit comments

Comments
 (0)