From patchwork Mon May 31 02:07:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 12475 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 88921C3206 for ; Mon, 31 May 2021 02:08:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 49EB168925; Mon, 31 May 2021 04:08:03 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="wZKefelj"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DCA596891F for ; Mon, 31 May 2021 04:07:58 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7D1AC8AB for ; Mon, 31 May 2021 04:07:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1622426878; bh=dxroh8JJ3hkJJ1GOwoNC6PmbOq3TRCcdIto7Flhd0qI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=wZKefeljbUOk9IAA5f0GM7CAbYD7OPmLHmIuIKhGMpdnzL9WSjtk+Oe7WRvJLhzDa KdduM6eFfkDt+fpPZcDzmja3ooO9W9topLDFlELRSP65Ce/9LSczCJPx8hzqGDTlYx bsv3LSu0BuKpfqmCdr6o9p1K7naEpFeZ+R18wsQE= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 31 May 2021 05:07:45 +0300 Message-Id: <20210531020745.13815-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531020745.13815-1-laurent.pinchart@ideasonboard.com> References: <20210531020745.13815-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/2] libcamera: pipeline: ipu3: Fix incorrect bdsHeight calculation X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" When compiling with optimization, gcc 9 and newer throw an unitialized variable warning: ../../src/libcamera/pipeline/ipu3/imgu.cpp: In function ‘void libcamera::{anonymous}::calculateBDSHeight(libcamera::ImgUDevice::Pipe*, const libcamera::Size&, const libcamera::Size&, unsigned int, float)’: ../../src/libcamera/pipeline/ipu3/imgu.cpp:172:17: error: ‘bdsHeight’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 172 | unsigned int bdsIntHeight = static_cast(bdsHeight); Neither clang not gcc versions older than 9 complain. This seems to be a false positive. However, there's an obvious error in the code. The second while () loop in the first part of calculateBDSHeight() modifies the bdsHeight variable set by the first loop even if the second loop doesn't find a suitable height. This can result in an incorrect bdsHeight value. Fix this, which also gets rid of the compiler warning. Signed-off-by: Laurent Pinchart Reviewed-by: Hirokazu Honda Tested-by: Jean-Michel Hautbois Reviewed-by: Jean-Michel Hautbois --- src/libcamera/pipeline/ipu3/imgu.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/imgu.cpp b/src/libcamera/pipeline/ipu3/imgu.cpp index 3e517ac67962..4eb3f7b730a9 100644 --- a/src/libcamera/pipeline/ipu3/imgu.cpp +++ b/src/libcamera/pipeline/ipu3/imgu.cpp @@ -138,12 +138,13 @@ void calculateBDSHeight(ImgUDevice::Pipe *pipe, const Size &iif, const Size &gdc while (ifHeight >= minIFHeight && ifHeight <= iif.height && ifHeight / bdsSF >= minBDSHeight) { - bdsHeight = ifHeight / bdsSF; - if (std::fmod(bdsHeight, 1.0) == 0) { - unsigned int bdsIntHeight = static_cast(bdsHeight); + float height = ifHeight / bdsSF; + if (std::fmod(height, 1.0) == 0) { + unsigned int bdsIntHeight = static_cast(height); if (!(bdsIntHeight % BDS_ALIGN_H)) { foundIfHeight = ifHeight; + bdsHeight = height; break; } } @@ -155,12 +156,13 @@ void calculateBDSHeight(ImgUDevice::Pipe *pipe, const Size &iif, const Size &gdc while (ifHeight >= minIFHeight && ifHeight <= iif.height && ifHeight / bdsSF >= minBDSHeight) { - bdsHeight = ifHeight / bdsSF; - if (std::fmod(bdsHeight, 1.0) == 0) { - unsigned int bdsIntHeight = static_cast(bdsHeight); + float height = ifHeight / bdsSF; + if (std::fmod(height, 1.0) == 0) { + unsigned int bdsIntHeight = static_cast(height); if (!(bdsIntHeight % BDS_ALIGN_H)) { foundIfHeight = ifHeight; + bdsHeight = height; break; } }