From patchwork Thu May 7 11:23:16 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Matthews X-Patchwork-Id: 26670 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 166CDBE173 for ; Thu, 7 May 2026 11:23:32 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3766062FE1; Thu, 7 May 2026 13:23:31 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=googlemail.com header.i=@googlemail.com header.b="IxuvpeA1"; dkim-atps=neutral Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8D90962010 for ; Thu, 7 May 2026 13:23:29 +0200 (CEST) Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-48d146705b4so9064605e9.3 for ; Thu, 07 May 2026 04:23:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20251104; t=1778153009; x=1778757809; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Or3DggdgmHTOtunvwpf3FTEvLseaEwpGUBzEA0qK6RA=; b=IxuvpeA1Ml/dpR4li0wg3Fw3gvf0Q+L2jz7/yMAxXG8+pOyBEAJZJHqwLA0gmR5oxW sTXxyhzzpnge7CpuQBY46GdwgiauxEPz2qRgJ7DJ4NPMUI2C/aCGg5qDt1tRxMRDt1Hf NrpQq13uM4RB002wCTBCeyentYX566Fl8PVb8Qi5+WbyzL2txRSwb8MOUcwU4nJI1JMS XUGMjzfyFj327EZU4ggRfT97fzoBnaVxW47h816BXFWcr3rmBpe2ccPbDAhvDcej9MWQ Em5lqe8y/acudNye/tY91g8iMdKZPitFper+0bf1XKDOrEteII3MPH68VadGHKBDweZ8 u6zA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778153009; x=1778757809; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Or3DggdgmHTOtunvwpf3FTEvLseaEwpGUBzEA0qK6RA=; b=M5N3SGFgCMqY2vapJkLQ26l8YjzsiiEYxogH31TE2IW81wALy5hGU70iReltwhfHYZ gLwNK3DvSeEZn6q7g73yMRYavDiZbMoELpKwmHheyfy1Hyi7f6EBO+L3T70BCYSmHYhP dNO8n/9cyl44wco5SXA8Mh/ks1qew7M9S9IMcmMIZ0Rc7y2x0tijYGoGvUq5ZuLBlDTa /bzme0NiecMtf/oz9yM9NY+2tlYLYdEYTtI2qqadcae76hBOs/rLSIZEn6MPJ8LqMv21 rVBE8N3I+lC2sBySLsdwQ63kcwoWDHrKWz3tP0riO6dPGRqwtuZ5tdhMWd1rm02c5+hJ LO0g== X-Gm-Message-State: AOJu0Yzyv43J0ttCn596D1fGMxibAScFfSEcqlQ8csYkN3AQp1/vHxaT 6Fc1SDug0MFkvtmZFyNe68J3e7S2KbPqHGFhRcnvb4IdDkcja3+xOFCaNMi8aFou X-Gm-Gg: AeBDieuGWL7WPxmQ71Vcy9sZVCsODcWxulU3KDVD/JuKJXyPNyDw6zsUiWhdghIaLC5 Ehu1lGazivG/4kQqaRCp02MPBzDWm+FXGweXM6HwROXbTotuGl+uozjUXinMiukZOwKtSpU50HI T0X+o0d3fRYvBh44YE6Hj+DIfVrZuXLaWgIvCFzf20bnTM5JBhJ/AcjLkiAwSUYMIElUqv3YeP5 cvLy1P35pZCY5MNgzM84OK25RfBGU499JNXLRvabHge4H7wdfZ/KpCOZZVDe2N8GhzaN4PnLm4u NrDtWlTJ2uol8TePaV7ucT1Tjl/hHubRmrmEZkIULRm11rfDJDo2pyoKO3vvxxhSYTB2u5NGdSL d6ej54HnAWnKPago7dNGbyKpS0e61fPRvoYc4wMJFsxXQOUmU71TNpdzFa7FzzFicaUKBY98RYl n6zOe2Y5nA1d1UmfH9PR/QnLAa+11OjfFAkysGvo+0AYlGAABqqck6LjXgKQ6arhdNMWt5tm+C5 PjRNgXoqxAk+BMZh9ShwqlEPPrGq0phDDE7QqkyT5gmXBACScleAzel4A51 X-Received: by 2002:a05:600d:10:b0:488:e7e4:8425 with SMTP id 5b1f17b1804b1-48e51f4ea40mr102278705e9.23.1778153008751; Thu, 07 May 2026 04:23:28 -0700 (PDT) Received: from neilmatthews-Precision-3571.home (host86-132-133-211.range86-132.btcentralplus.com. [86.132.133.211]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48e538d222esm136064935e9.14.2026.05.07.04.23.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 May 2026 04:23:28 -0700 (PDT) From: Neil Matthews To: Cc: libcamera-devel@lists.libcamera.org, Neil Matthews Subject: Fix some issues highlighted by static checking Date: Thu, 7 May 2026 12:23:16 +0100 Message-ID: <20260507112321.22726-1-drneildmatthews@googlemail.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 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" Dear All, First submission -- apologies if not following established procedures. Compiles, but untested. There may be better solutions to the enum versus flag changes. Best regards, Neil Matthews From a1f071f276612e97ab29c27dc6fb5bf62d0599f0 Mon Sep 17 00:00:00 2001 From: Neil Matthews Date: Fri, 1 May 2026 16:46:30 +0100 Subject: [PATCH] Fix some issues highlighted by static checking. Checkers were invoked as: cppcheck --enable=all --force --inconclusive and as bear ninja -C build find . -name "*.cpp" -exec clang-tidy {} ';' Issues raised include: - using enums as flags that are or'ed together creating values not defined in the enum - checking result of malloc - checking (null) pointers before dereferencing - avoiding strcat() Other flagged issues remain to be reviewed and fixed if required. Signed-off-by: Neil Matthews --- include/libcamera/base/memfd.h | 1 + include/libcamera/controls.h | 1 + include/libcamera/internal/dma_buf_allocator.h | 2 ++ src/android/metadata/camera_metadata.c | 4 ++++ src/libcamera/base/object.cpp | 3 +++ src/libcamera/ipa_data_serializer.cpp | 16 ++++++++++++---- src/libcamera/pipeline/ipu3/ipu3.cpp | 4 +--- src/libcamera/pipeline/simple/simple.cpp | 3 +++ src/libcamera/software_isp/debayer_cpu.cpp | 2 -- src/libcamera/v4l2_pixelformat.cpp | 7 ++++--- 10 files changed, 31 insertions(+), 12 deletions(-) diff --git a/include/libcamera/base/memfd.h b/include/libcamera/base/memfd.h index 5ffa0f22..6805d374 100644 --- a/include/libcamera/base/memfd.h +++ b/include/libcamera/base/memfd.h @@ -21,6 +21,7 @@ public: None = 0, Shrink = (1 << 0), Grow = (1 << 1), + ShrinkAndGrow = Shrink | Grow, }; using Seals = Flags; diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index 44ff4964..a22fe28f 100644 --- a/include/libcamera/controls.h +++ b/include/libcamera/controls.h @@ -253,6 +253,7 @@ public: enum class Direction { In = (1 << 0), Out = (1 << 1), + InAndOut = In | Out, }; using DirectionFlags = Flags; diff --git a/include/libcamera/internal/dma_buf_allocator.h b/include/libcamera/internal/dma_buf_allocator.h index 13600915..40dc36da 100644 --- a/include/libcamera/internal/dma_buf_allocator.h +++ b/include/libcamera/internal/dma_buf_allocator.h @@ -26,7 +26,9 @@ public: enum class DmaBufAllocatorFlag { CmaHeap = 1 << 0, SystemHeap = 1 << 1, + CmaHeapAndSystemHeap = CmaHeap | SystemHeap, UDmaBuf = 1 << 2, + CmaHeapAndSystemHeapAndUDmaBuf = CmaHeap | SystemHeap | UDmaBuf, }; using DmaBufAllocatorFlags = Flags; diff --git a/src/android/metadata/camera_metadata.c b/src/android/metadata/camera_metadata.c index b86586a7..89cc792f 100644 --- a/src/android/metadata/camera_metadata.c +++ b/src/android/metadata/camera_metadata.c @@ -242,6 +242,10 @@ camera_metadata_t *allocate_copy_camera_metadata_checked( } void *buffer = malloc(src_size); + if(!buffer) { + return NULL; + } + memcpy(buffer, src, src_size); camera_metadata_t *metadata = (camera_metadata_t*) buffer; diff --git a/src/libcamera/base/object.cpp b/src/libcamera/base/object.cpp index 37d133cc..6f075560 100644 --- a/src/libcamera/base/object.cpp +++ b/src/libcamera/base/object.cpp @@ -207,6 +207,9 @@ void Object::message(Message *msg) * it in release mode (with -O2 or -O3). */ InvokeMessage *iMsg = dynamic_cast(msg); + if(!iMsg) + break; + Semaphore *semaphore = iMsg->semaphore(); iMsg->invoke(); diff --git a/src/libcamera/ipa_data_serializer.cpp b/src/libcamera/ipa_data_serializer.cpp index 0537f785..86698684 100644 --- a/src/libcamera/ipa_data_serializer.cpp +++ b/src/libcamera/ipa_data_serializer.cpp @@ -311,9 +311,11 @@ template<> std::tuple, std::vector> IPADataSerializer::serialize(const ControlList &data, ControlSerializer *cs) { - if (!cs) + if (!cs) { LOG(IPADataSerializer, Fatal) << "ControlSerializer not provided for serialization of ControlList"; + return {}; + } size_t size; std::vector infoData; @@ -361,9 +363,11 @@ IPADataSerializer::deserialize(std::vector::const_iterator std::vector::const_iterator dataEnd, ControlSerializer *cs) { - if (!cs) + if (!cs) { LOG(IPADataSerializer, Fatal) << "ControlSerializer not provided for deserialization of ControlList"; + return {}; + } if (std::distance(dataBegin, dataEnd) < 8) return {}; @@ -436,9 +440,11 @@ std::tuple, std::vector> IPADataSerializer::serialize(const ControlInfoMap &map, ControlSerializer *cs) { - if (!cs) + if (!cs) { LOG(IPADataSerializer, Fatal) << "ControlSerializer not provided for serialization of ControlInfoMap"; + return {}; + } size_t size = cs->binarySize(map); std::vector infoData(size); @@ -463,9 +469,11 @@ IPADataSerializer::deserialize(std::vector::const_itera std::vector::const_iterator dataEnd, ControlSerializer *cs) { - if (!cs) + if (!cs) { LOG(IPADataSerializer, Fatal) << "ControlSerializer not provided for deserialization of ControlInfoMap"; + return {}; + } if (std::distance(dataBegin, dataEnd) < 4) return {}; diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index bf4c2921..15f918cd 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -565,7 +565,6 @@ int PipelineHandlerIPU3::configure(Camera *camera, CameraConfiguration *c) /* Apply the format to the configured streams output devices. */ StreamConfiguration *mainCfg = nullptr; - StreamConfiguration *vfCfg = nullptr; for (unsigned int i = 0; i < config->size(); ++i) { StreamConfiguration &cfg = (*config)[i]; @@ -577,7 +576,6 @@ int PipelineHandlerIPU3::configure(Camera *camera, CameraConfiguration *c) if (ret) return ret; } else if (stream == vfStream) { - vfCfg = &cfg; ret = imgu->configureViewfinder(cfg, &outputFormat); if (ret) return ret; @@ -589,7 +587,7 @@ int PipelineHandlerIPU3::configure(Camera *camera, CameraConfiguration *c) * the configuration of the active one for that purpose (there should * be at least one active stream in the configuration request). */ - if (!vfCfg) { + if (mainCfg) { ret = imgu->configureViewfinder(*mainCfg, &outputFormat); if (ret) return ret; diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp index c6fe12d6..3a5f9095 100644 --- a/src/libcamera/pipeline/simple/simple.cpp +++ b/src/libcamera/pipeline/simple/simple.cpp @@ -985,6 +985,9 @@ void SimpleCameraData::clearIncompleteRequests() void SimpleCameraData::tryCompleteRequest(Request *request) { + if (!request) + return; + if (request->hasPendingBuffers()) return; diff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp index d9f5b326..1b89a721 100644 --- a/src/libcamera/software_isp/debayer_cpu.cpp +++ b/src/libcamera/software_isp/debayer_cpu.cpp @@ -820,8 +820,6 @@ void DebayerCpuThread::process2(uint32_t frame, const uint8_t *src, uint8_t *dst /* next line may point outside of src, use prev. */ linePointers[2] = linePointers[0]; debayer_->debayer1(dst, linePointers); - src += inputStride; - dst += outputStride; } } diff --git a/src/libcamera/v4l2_pixelformat.cpp b/src/libcamera/v4l2_pixelformat.cpp index e8b3eb9c..105f5bed 100644 --- a/src/libcamera/v4l2_pixelformat.cpp +++ b/src/libcamera/v4l2_pixelformat.cpp @@ -291,15 +291,16 @@ std::string V4L2PixelFormat::toString() const char ss[8] = { static_cast(fourcc_ & 0x7f), static_cast((fourcc_ >> 8) & 0x7f), static_cast((fourcc_ >> 16) & 0x7f), - static_cast((fourcc_ >> 24) & 0x7f) }; + static_cast((fourcc_ >> 24) & 0x7f), + '-', 'B', 'E', 0 }; for (unsigned int i = 0; i < 4; i++) { if (!isprint(ss[i])) ss[i] = '.'; } - if (fourcc_ & (1 << 31)) - strcat(ss, "-BE"); + if (!(fourcc_ & (1 << 31))) + ss[4] = 0; return ss; }