From patchwork Fri Jul 23 08:22:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 12395519 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CDEBAC4338F for ; Fri, 23 Jul 2021 08:23:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A677260E93 for ; Fri, 23 Jul 2021 08:23:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234313AbhGWHmb (ORCPT ); Fri, 23 Jul 2021 03:42:31 -0400 Received: from lb2-smtp-cloud8.xs4all.net ([194.109.24.25]:59411 "EHLO lb2-smtp-cloud8.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234263AbhGWHm3 (ORCPT ); Fri, 23 Jul 2021 03:42:29 -0400 Received: from cust-b5b5937f ([IPv6:fc0c:c16d:66b8:757f:c639:739b:9d66:799d]) by smtp-cloud8.xs4all.net with ESMTPA id 6qSRmWaaWXTlc6qSSmAKCE; Fri, 23 Jul 2021 10:23:00 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xs4all.nl; s=s2; t=1627028580; bh=/oObasBvh6BxPQoqcMXwC7ygC2rvHQBai1B3H0oMhsQ=; h=To:From:Subject:Message-ID:Date:MIME-Version:Content-Type:From: Subject; b=WyWywwkwvUao7hnwQlTXChYQ5b1Ssle61P6woO+dIWWnPqkARCANdr0Giq85YWx2t dmaJBNHmbvhWsiDoHZhnObZWAw1VhquThSBiZ5J5uACwdf4EeMtho7fNVOhNtPM2Kt so86A8gf0/goWFaOaaqWSxUtXPOxcqQQR7k+iUvZbfQYZAfrxddp9BKWaOPIRYfirm uShvQKxKLrPvIHO6x/+G5EoBPMnmXp4oCavl6j5RjSI/5WJde0iy0RlhkrnBsUSdiB XkhruQL9mPZR5Uh7+xwAR6e2LEhryDjqJs9Hus/0KtchHGO77i9NMe/yu8mw86yt08 Y/+eT0rkt8iSQ== To: Linux Media Mailing List Cc: =?utf-8?q?Krzysztof_Ha=C5=82asa?= From: Hans Verkuil Subject: [PATCH] v4l2-dv-timings.c: fix wrong condition in two for-loops Message-ID: Date: Fri, 23 Jul 2021 10:22:59 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 Content-Language: en-US X-CMAE-Envelope: MS4xfI4tzQ++7ScmHXWORlVTrOUgxNtWo9YfHfamz73yHoB8Q5fy9m1d9wBZSkWiZNO/2JqlcOh+FsEn8Dj8Zm7DX3PknHC5tKk9Wr3GLlo9LPnmH6s4+8Z9 bIJvX5MG3dx0/OtiyNTv2f+DD60yN8Semyfa5DA2N37mDVt8I/uZIvpQZEsn092WJLbwHP/7El+G+76yP6bTLgfEmYDiruvO6k3vC4sWb0iLPjWE0WNT5eWo 10sMXnPJEo4JJq9bjhS9+9fdY3ZqTKxDlaX4cIGeVGnVnSa6joXTY0p45sz5qWefzixsXRlu9FHcAMyLX4hVsA== Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org These for-loops should test against v4l2_dv_timings_presets[i].bt.width, not if i < v4l2_dv_timings_presets[i].bt.width. Luckily nothing ever broke, since the smallest width is still a lot higher than the total number of presets, but it is wrong. The last item in the presets array is all 0, so the for-loop must stop when it reaches that sentinel. Signed-off-by: Hans Verkuil Reported-by: Krzysztof HaƂasa diff --git a/drivers/media/v4l2-core/v4l2-dv-timings.c b/drivers/media/v4l2-core/v4l2-dv-timings.c index 230d65a64217..af48705c704f 100644 --- a/drivers/media/v4l2-core/v4l2-dv-timings.c +++ b/drivers/media/v4l2-core/v4l2-dv-timings.c @@ -196,7 +196,7 @@ bool v4l2_find_dv_timings_cap(struct v4l2_dv_timings *t, if (!v4l2_valid_dv_timings(t, cap, fnc, fnc_handle)) return false; - for (i = 0; i < v4l2_dv_timings_presets[i].bt.width; i++) { + for (i = 0; v4l2_dv_timings_presets[i].bt.width; i++) { if (v4l2_valid_dv_timings(v4l2_dv_timings_presets + i, cap, fnc, fnc_handle) && v4l2_match_dv_timings(t, v4l2_dv_timings_presets + i, @@ -218,7 +218,7 @@ bool v4l2_find_dv_timings_cea861_vic(struct v4l2_dv_timings *t, u8 vic) { unsigned int i; - for (i = 0; i < v4l2_dv_timings_presets[i].bt.width; i++) { + for (i = 0; v4l2_dv_timings_presets[i].bt.width; i++) { const struct v4l2_bt_timings *bt = &v4l2_dv_timings_presets[i].bt;