]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
media: ivtv: use clamp in ivtv_try_fmt_vid_{out,cap}
authorThorsten Blum <thorsten.blum@linux.dev>
Sun, 17 May 2026 17:17:43 +0000 (19:17 +0200)
committerHans Verkuil <hverkuil+cisco@kernel.org>
Wed, 20 May 2026 07:01:58 +0000 (09:01 +0200)
Replace multiple min(), max() calls with clamp().

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
drivers/media/pci/ivtv/ivtv-ioctl.c

index 8d5ea3aec06f3dcb36ba4f52c9a8d621511d5c10..fc95f0bf48d5574bc147ee8a72619535df4643e2 100644 (file)
@@ -467,15 +467,13 @@ static int ivtv_try_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format
        int h = fmt->fmt.pix.height;
        int min_h = 2;
 
-       w = min(w, 720);
-       w = max(w, 2);
+       w = clamp(w, 2, 720);
        if (id->type == IVTV_ENC_STREAM_TYPE_YUV) {
                /* YUV height must be a multiple of 32 */
                h &= ~0x1f;
                min_h = 32;
        }
-       h = min(h, itv->is_50hz ? 576 : 480);
-       h = max(h, min_h);
+       h = clamp(h, min_h, itv->is_50hz ? 576 : 480);
        ivtv_g_fmt_vid_cap(file, fh, fmt);
        fmt->fmt.pix.width = w;
        fmt->fmt.pix.height = h;
@@ -516,8 +514,7 @@ static int ivtv_try_fmt_vid_out(struct file *file, void *fh, struct v4l2_format
        int field = fmt->fmt.pix.field;
        int ret = ivtv_g_fmt_vid_out(file, fh, fmt);
 
-       w = min(w, 720);
-       w = max(w, 2);
+       w = clamp(w, 2, 720);
        /* Why can the height be 576 even when the output is NTSC?
 
           Internally the buffers of the PVR350 are always set to 720x576. The
@@ -533,8 +530,7 @@ static int ivtv_try_fmt_vid_out(struct file *file, void *fh, struct v4l2_format
           resolution is locked to the broadcast standard and not scaled.
 
           Thanks to Ian Armstrong for this explanation. */
-       h = min(h, 576);
-       h = max(h, 2);
+       h = clamp(h, 2, 576);
        if (id->type == IVTV_DEC_STREAM_TYPE_YUV)
                fmt->fmt.pix.field = field;
        fmt->fmt.pix.width = w;