[{"id":30116,"web_url":"https://patchwork.libcamera.org/comment/30116/","msgid":"<CAEmqJPqRvHXzQQ75Yrn3Y8qjCUOjV6p2hkriN9RiN6oBTByQSQ@mail.gmail.com>","date":"2024-06-28T07:02:24","subject":"Re: [PATCH] libcamera: fix maybe-uninitialized error","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/people/34/","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"content":"Hi Stefan,\n\nOn Thu, 27 Jun 2024 at 14:37, Stefan Klug <stefan.klug@ideasonboard.com> wrote:\n>\n> The gcc used in my current buildroot (Version 12.3) errors out with\n> -Wmaybe-uninitialized. Fix that.\n>\n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> ---\n>\n> @Naush: Could you have a look at the rpi specific changes? Specifically\n> I'm not sure if the change in AwbConfig::read() is correct. It was\n> unclear to me if there are cases where line 125 should return 0 even\n> though a error got logged one line above.\n\nI think the original error handling is probably wrong and we need\nsomething like:\n\ndiff --git a/src/ipa/rpi/controller/rpi/awb.cpp\nb/src/ipa/rpi/controller/rpi/awb.cpp\nindex 5ae0c2fad6e9..81f700dba2c7 100644\n--- a/src/ipa/rpi/controller/rpi/awb.cpp\n+++ b/src/ipa/rpi/controller/rpi/awb.cpp\n@@ -121,7 +121,7 @@ int AwbConfig::read(const libcamera::YamlObject &params)\n                }\n                if (priors.empty()) {\n                        LOG(RPiAwb, Error) << \"AwbConfig: no AWB\npriors configured\";\n-                       return ret;\n+                       return -EINVAL;\n                }\n\nFeel free to make that change as part of this commt, or I can submit a\nseparate patch.\n\nYour changes look good to me otherwise.\n\nReviewed-by: Naushir Patuck <naush@raspberrypi.com>\n\n\n>\n> Regards,\n> Stefan\n>\n>\n>  src/ipa/libipa/exposure_mode_helper.cpp   | 15 ++++++---------\n>  src/ipa/rpi/controller/rpi/awb.cpp        |  2 +-\n>  src/libcamera/device_enumerator_sysfs.cpp |  2 +-\n>  src/libcamera/pipeline/rpi/vc4/vc4.cpp    |  2 +-\n>  4 files changed, 9 insertions(+), 12 deletions(-)\n>\n> diff --git a/src/ipa/libipa/exposure_mode_helper.cpp b/src/ipa/libipa/exposure_mode_helper.cpp\n> index 683a564a01c8..9d1387636d05 100644\n> --- a/src/ipa/libipa/exposure_mode_helper.cpp\n> +++ b/src/ipa/libipa/exposure_mode_helper.cpp\n> @@ -166,7 +166,7 @@ ExposureModeHelper::splitExposure(utils::Duration exposure) const\n>                 return { minShutter_, minGain_, exposure / (minShutter_ * minGain_) };\n>\n>         utils::Duration shutter;\n> -       double stageGain;\n> +       double stageGain = 1.0;\n>         double gain;\n>\n>         for (unsigned int stage = 0; stage < gains_.size(); stage++) {\n> @@ -198,15 +198,12 @@ ExposureModeHelper::splitExposure(utils::Duration exposure) const\n>         }\n>\n>         /*\n> -        * From here on all we can do is max out the shutter time, followed by\n> -        * the analogue gain. If we still haven't achieved the target we send\n> -        * the rest of the exposure time to digital gain. If we were given no\n> -        * stages to use then set stageGain to 1.0 so that shutter time is maxed\n> -        * before gain touched at all.\n> +        * From here on all we can do is max out the shutter time, followed by the\n> +        * analogue gain. If we still haven't achieved the target we send the rest\n> +        * of the exposure time to digital gain. If we were given no stages to use\n> +        * then the default stageGain of 1.0 is used so that shutter time is maxed\n> +        * before gain is touched at all.\n>          */\n> -       if (gains_.empty())\n> -               stageGain = 1.0;\n> -\n>         shutter = clampShutter(exposure / clampGain(stageGain));\n>         gain = clampGain(exposure / shutter);\n>\n> diff --git a/src/ipa/rpi/controller/rpi/awb.cpp b/src/ipa/rpi/controller/rpi/awb.cpp\n> index 003c8fa137f3..3503a5ab9218 100644\n> --- a/src/ipa/rpi/controller/rpi/awb.cpp\n> +++ b/src/ipa/rpi/controller/rpi/awb.cpp\n> @@ -91,7 +91,7 @@ static int readCtCurve(ipa::Pwl &ctR, ipa::Pwl &ctB, const libcamera::YamlObject\n>\n>  int AwbConfig::read(const libcamera::YamlObject &params)\n>  {\n> -       int ret;\n> +       int ret = 0;\n>\n>         bayes = params[\"bayes\"].get<int>(1);\n>         framePeriod = params[\"frame_period\"].get<uint16_t>(10);\n> diff --git a/src/libcamera/device_enumerator_sysfs.cpp b/src/libcamera/device_enumerator_sysfs.cpp\n> index fc33ba52b813..7866885c0f73 100644\n> --- a/src/libcamera/device_enumerator_sysfs.cpp\n> +++ b/src/libcamera/device_enumerator_sysfs.cpp\n> @@ -33,7 +33,7 @@ int DeviceEnumeratorSysfs::init()\n>  int DeviceEnumeratorSysfs::enumerate()\n>  {\n>         struct dirent *ent;\n> -       DIR *dir;\n> +       DIR *dir = nullptr;\n>\n>         static const char * const sysfs_dirs[] = {\n>                 \"/sys/subsystem/media/devices\",\n> diff --git a/src/libcamera/pipeline/rpi/vc4/vc4.cpp b/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n> index 4a89e35f5d7b..e5b6ef2b37cd 100644\n> --- a/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n> +++ b/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n> @@ -802,7 +802,7 @@ void Vc4CameraData::ispInputDequeue(FrameBuffer *buffer)\n>  void Vc4CameraData::ispOutputDequeue(FrameBuffer *buffer)\n>  {\n>         RPi::Stream *stream = nullptr;\n> -       unsigned int index;\n> +       unsigned int index = 0;\n>\n>         if (!isRunning())\n>                 return;\n> --\n> 2.43.0\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 4C743BDB1D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 28 Jun 2024 07:03:05 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4912062C99;\n\tFri, 28 Jun 2024 09:03:04 +0200 (CEST)","from mail-yw1-x1131.google.com (mail-yw1-x1131.google.com\n\t[IPv6:2607:f8b0:4864:20::1131])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1CCCA619D7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 28 Jun 2024 09:03:02 +0200 (CEST)","by mail-yw1-x1131.google.com with SMTP id\n\t00721157ae682-643acefd1afso2768417b3.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 28 Jun 2024 00:03:01 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"bUd/PGa0\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1719558181; x=1720162981;\n\tdarn=lists.libcamera.org; \n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:from:to:cc:subject:date:message-id:reply-to;\n\tbh=zAoDhb5R45peJXYQ7pEtZuRjGSQpzaCBQV+/0eUui2M=;\n\tb=bUd/PGa0JZopSvOTBYFn4toqPREO/e2VCVhDExCBQrK6Hp3l+VmUlXRUMrV7m+sGZd\n\t8RHDvR0V+71lV5I8Smu5kwELjplzCoGxl6MZhQsWUxU/LNrIPJZKAPWNFRaicD0WVn7k\n\t/pwj1ZDDIci6pr0CV5l4g/e3x7mns+bU/iPZQyubZFZ2Mgg6pFWRPG4Luox69QU9Giy1\n\tyZ0Oznk/qLOkxmkPcRlMm9jEfwvspXyNklKhhQn1bYhBOboU0t7XeaJRbFOqHR70kcQQ\n\tZBB3nsHUq4NdFTkBAGztLYZ+CFAggrKmYeeXl7oYGh4wiESbeKmkiEihyqzQxZdzaYgz\n\tA3bA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1719558181; x=1720162981;\n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:x-gm-message-state:from:to:cc:subject:date:message-id\n\t:reply-to;\n\tbh=zAoDhb5R45peJXYQ7pEtZuRjGSQpzaCBQV+/0eUui2M=;\n\tb=RS+ScInylKxslpRHAA+hgNa6l7xwt+Eyznv0TEKJE4ErWL4cCUk66BQYwFcu2V1PaL\n\t7dKKC6HBCLUiCzBW7ye93GbgFriA0VjN8Ih3E5MCvm9KuMrH2tD9SACwLynq+k4ntCrz\n\tr9vJwx4bfcKVZMy/0hI4h7XWItIhqnnVivKpfXOg3yPFm7TAA3Iy0BEeM50wAqZBgD0M\n\t/fIsvlQtMHLK1cAxNt9e93kHubxVvOm8S3vbY1mudIFI/+x0AL+RzoBnNNChTHFGmQMO\n\t/vEuyM1iVBEaYKNrWBgJ6S3NVAXRvy1FJ9IReJMldLABlcZHYNRcprxGx9lmK/+lwMrf\n\tBRhQ==","X-Gm-Message-State":"AOJu0YxEb3D9NDrZCAVO8ViHodd6wNm5k43/zQv9hftH2DUmCLyDrJtn\n\thAWELQtAiQjwjF/XkY3CXk5rjOgu6D8XFa1sh/JPgEuvsDvGQwLRnOh129mKwtOHw/EbwVX9O3h\n\t7D+cfEFMrnSbWubW6kkI4E1mHtJa4WKnZv5aIYw==","X-Google-Smtp-Source":"AGHT+IH1Mm3/Gr/ebO+8ecG9unn83pcVsvDB9gSlM2ITHKlmm2+zfiFLfgp1tYPSW7N/1a4XAEt+HxhV0b1atg/a+3k=","X-Received":"by 2002:a05:690c:c07:b0:64b:4219:768a with SMTP id\n\t00721157ae682-64b4219780cmr2553747b3.24.1719558180765;\n\tFri, 28 Jun 2024 00:03:00 -0700 (PDT)","MIME-Version":"1.0","References":"<20240627133730.2554717-1-stefan.klug@ideasonboard.com>","In-Reply-To":"<20240627133730.2554717-1-stefan.klug@ideasonboard.com>","From":"Naushir Patuck <naush@raspberrypi.com>","Date":"Fri, 28 Jun 2024 08:02:24 +0100","Message-ID":"<CAEmqJPqRvHXzQQ75Yrn3Y8qjCUOjV6p2hkriN9RiN6oBTByQSQ@mail.gmail.com>","Subject":"Re: [PATCH] libcamera: fix maybe-uninitialized error","To":"Stefan Klug <stefan.klug@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Content-Type":"text/plain; charset=\"UTF-8\"","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":30117,"web_url":"https://patchwork.libcamera.org/comment/30117/","msgid":"<qxgmeyloww7cuf26e4s4f2wbbq76avku2coljc33zbhxezpgsk@hmb73ahlwpou>","date":"2024-06-28T07:17:34","subject":"Re: [PATCH] libcamera: fix maybe-uninitialized error","submitter":{"id":143,"url":"https://patchwork.libcamera.org/api/people/143/","name":"Jacopo Mondi","email":"jacopo.mondi@ideasonboard.com"},"content":"Hi Stefan\n\nOn Thu, Jun 27, 2024 at 03:31:00PM GMT, Stefan Klug wrote:\n> The gcc used in my current buildroot (Version 12.3) errors out with\n> -Wmaybe-uninitialized. Fix that.\n>\n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> ---\n>\n> @Naush: Could you have a look at the rpi specific changes? Specifically\n> I'm not sure if the change in AwbConfig::read() is correct. It was\n> unclear to me if there are cases where line 125 should return 0 even\n> though a error got logged one line above.\n>\n> Regards,\n> Stefan\n>\n>\n>  src/ipa/libipa/exposure_mode_helper.cpp   | 15 ++++++---------\n>  src/ipa/rpi/controller/rpi/awb.cpp        |  2 +-\n>  src/libcamera/device_enumerator_sysfs.cpp |  2 +-\n>  src/libcamera/pipeline/rpi/vc4/vc4.cpp    |  2 +-\n>  4 files changed, 9 insertions(+), 12 deletions(-)\n>\n> diff --git a/src/ipa/libipa/exposure_mode_helper.cpp b/src/ipa/libipa/exposure_mode_helper.cpp\n> index 683a564a01c8..9d1387636d05 100644\n> --- a/src/ipa/libipa/exposure_mode_helper.cpp\n> +++ b/src/ipa/libipa/exposure_mode_helper.cpp\n> @@ -166,7 +166,7 @@ ExposureModeHelper::splitExposure(utils::Duration exposure) const\n>  \t\treturn { minShutter_, minGain_, exposure / (minShutter_ * minGain_) };\n>\n>  \tutils::Duration shutter;\n> -\tdouble stageGain;\n> +\tdouble stageGain = 1.0;\n>  \tdouble gain;\n>\n>  \tfor (unsigned int stage = 0; stage < gains_.size(); stage++) {\n> @@ -198,15 +198,12 @@ ExposureModeHelper::splitExposure(utils::Duration exposure) const\n>  \t}\n>\n>  \t/*\n> -\t * From here on all we can do is max out the shutter time, followed by\n> -\t * the analogue gain. If we still haven't achieved the target we send\n> -\t * the rest of the exposure time to digital gain. If we were given no\n> -\t * stages to use then set stageGain to 1.0 so that shutter time is maxed\n> -\t * before gain touched at all.\n> +\t * From here on all we can do is max out the shutter time, followed by the\n> +\t * analogue gain. If we still haven't achieved the target we send the rest\n> +\t * of the exposure time to digital gain. If we were given no stages to use\n> +\t * then the default stageGain of 1.0 is used so that shutter time is maxed\n> +\t * before gain is touched at all.\n\nNo need to go over 80-cols\n\n>  \t */\n> -\tif (gains_.empty())\n> -\t\tstageGain = 1.0;\n> -\n>  \tshutter = clampShutter(exposure / clampGain(stageGain));\n>  \tgain = clampGain(exposure / shutter);\n>\n> diff --git a/src/ipa/rpi/controller/rpi/awb.cpp b/src/ipa/rpi/controller/rpi/awb.cpp\n> index 003c8fa137f3..3503a5ab9218 100644\n> --- a/src/ipa/rpi/controller/rpi/awb.cpp\n> +++ b/src/ipa/rpi/controller/rpi/awb.cpp\n> @@ -91,7 +91,7 @@ static int readCtCurve(ipa::Pwl &ctR, ipa::Pwl &ctB, const libcamera::YamlObject\n>\n>  int AwbConfig::read(const libcamera::YamlObject &params)\n>  {\n> -\tint ret;\n> +\tint ret = 0;\n>\n>  \tbayes = params[\"bayes\"].get<int>(1);\n>  \tframePeriod = params[\"frame_period\"].get<uint16_t>(10);\n\nThere's one code path below were you could return 0 on an error\ncondition\n\n\tif (params.contains(\"priors\")) {\n\t\tfor (const auto &p : params[\"priors\"].asList()) {\n\t\t\tAwbPrior prior;\n\t\t\tret = prior.read(p);\n\t\t\tif (ret)\n\t\t\t\treturn ret;\n\t\t\tif (!priors.empty() && prior.lux <= priors.back().lux) {\n\t\t\t\tLOG(RPiAwb, Error) << \"AwbConfig: Prior must be ordered in increasing lux value\";\n\t\t\t\treturn -EINVAL;\n\t\t\t}\n\t\t\tpriors.push_back(prior);\n\t\t}\n\t\tif (priors.empty()) {\n\t\t\tLOG(RPiAwb, Error) << \"AwbConfig: no AWB priors configured\";\n\t\t\treturn ret; <---- HERE\n\t\t}\n\nWhile at it, could you return -EINVAL here ?\n\n> diff --git a/src/libcamera/device_enumerator_sysfs.cpp b/src/libcamera/device_enumerator_sysfs.cpp\n> index fc33ba52b813..7866885c0f73 100644\n> --- a/src/libcamera/device_enumerator_sysfs.cpp\n> +++ b/src/libcamera/device_enumerator_sysfs.cpp\n> @@ -33,7 +33,7 @@ int DeviceEnumeratorSysfs::init()\n>  int DeviceEnumeratorSysfs::enumerate()\n>  {\n>  \tstruct dirent *ent;\n> -\tDIR *dir;\n> +\tDIR *dir = nullptr;\n>\n>  \tstatic const char * const sysfs_dirs[] = {\n>  \t\t\"/sys/subsystem/media/devices\",\n> diff --git a/src/libcamera/pipeline/rpi/vc4/vc4.cpp b/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n> index 4a89e35f5d7b..e5b6ef2b37cd 100644\n> --- a/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n> +++ b/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n> @@ -802,7 +802,7 @@ void Vc4CameraData::ispInputDequeue(FrameBuffer *buffer)\n>  void Vc4CameraData::ispOutputDequeue(FrameBuffer *buffer)\n>  {\n>  \tRPi::Stream *stream = nullptr;\n> -\tunsigned int index;\n> +\tunsigned int index = 0;\n>\n>  \tif (!isRunning())\n>  \t\treturn;\n\nThese two look good!\n\nThanks\n  j\n\n> --\n> 2.43.0\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 65FC6BD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 28 Jun 2024 07:17:40 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5787862C99;\n\tFri, 28 Jun 2024 09:17:39 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C427C619D7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 28 Jun 2024 09:17:37 +0200 (CEST)","from ideasonboard.com (93-61-96-190.ip145.fastwebnet.it\n\t[93.61.96.190])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 1E287735;\n\tFri, 28 Jun 2024 09:17:13 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"sM0Bqko2\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1719559033;\n\tbh=d3uDqKiY7Nnv6UBjoIjwtwTRc7L5eRTTCO7rlPllbac=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=sM0Bqko2zr3HCW6/GCzFItoJ57ABR1sP62f7hhX3Yefh9hGsk7BY/99U6CjaTb2wC\n\t+lts40JpW9hO0Bo9k1lHYKuAJP5fSD/b/owCw9LwSHLeYjfXY009yRiilIwCu2V2Tx\n\t/ve8w/9tOVEsG7qelqM+/HjeLDw9FoIG2cMl39U0=","Date":"Fri, 28 Jun 2024 09:17:34 +0200","From":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org, \n\tNaushir Patuck <naush@raspberrypi.com>","Subject":"Re: [PATCH] libcamera: fix maybe-uninitialized error","Message-ID":"<qxgmeyloww7cuf26e4s4f2wbbq76avku2coljc33zbhxezpgsk@hmb73ahlwpou>","References":"<20240627133730.2554717-1-stefan.klug@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20240627133730.2554717-1-stefan.klug@ideasonboard.com>","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":30118,"web_url":"https://patchwork.libcamera.org/comment/30118/","msgid":"<z37bl43vujrtcin5p65rkfmugi7riozhdy7do3zguudp5kealw@pvxyzm4m6b3x>","date":"2024-06-28T09:25:29","subject":"Re: [PATCH] libcamera: fix maybe-uninitialized error","submitter":{"id":184,"url":"https://patchwork.libcamera.org/api/people/184/","name":"Stefan Klug","email":"stefan.klug@ideasonboard.com"},"content":"Hi Jacopo,\n\nthanks for the review.\n\nOn Fri, Jun 28, 2024 at 09:17:34AM +0200, Jacopo Mondi wrote:\n> Hi Stefan\n> \n> On Thu, Jun 27, 2024 at 03:31:00PM GMT, Stefan Klug wrote:\n> > The gcc used in my current buildroot (Version 12.3) errors out with\n> > -Wmaybe-uninitialized. Fix that.\n> >\n> > Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> > ---\n> >\n> > @Naush: Could you have a look at the rpi specific changes? Specifically\n> > I'm not sure if the change in AwbConfig::read() is correct. It was\n> > unclear to me if there are cases where line 125 should return 0 even\n> > though a error got logged one line above.\n> >\n> > Regards,\n> > Stefan\n> >\n> >\n> >  src/ipa/libipa/exposure_mode_helper.cpp   | 15 ++++++---------\n> >  src/ipa/rpi/controller/rpi/awb.cpp        |  2 +-\n> >  src/libcamera/device_enumerator_sysfs.cpp |  2 +-\n> >  src/libcamera/pipeline/rpi/vc4/vc4.cpp    |  2 +-\n> >  4 files changed, 9 insertions(+), 12 deletions(-)\n> >\n> > diff --git a/src/ipa/libipa/exposure_mode_helper.cpp b/src/ipa/libipa/exposure_mode_helper.cpp\n> > index 683a564a01c8..9d1387636d05 100644\n> > --- a/src/ipa/libipa/exposure_mode_helper.cpp\n> > +++ b/src/ipa/libipa/exposure_mode_helper.cpp\n> > @@ -166,7 +166,7 @@ ExposureModeHelper::splitExposure(utils::Duration exposure) const\n> >  \t\treturn { minShutter_, minGain_, exposure / (minShutter_ * minGain_) };\n> >\n> >  \tutils::Duration shutter;\n> > -\tdouble stageGain;\n> > +\tdouble stageGain = 1.0;\n> >  \tdouble gain;\n> >\n> >  \tfor (unsigned int stage = 0; stage < gains_.size(); stage++) {\n> > @@ -198,15 +198,12 @@ ExposureModeHelper::splitExposure(utils::Duration exposure) const\n> >  \t}\n> >\n> >  \t/*\n> > -\t * From here on all we can do is max out the shutter time, followed by\n> > -\t * the analogue gain. If we still haven't achieved the target we send\n> > -\t * the rest of the exposure time to digital gain. If we were given no\n> > -\t * stages to use then set stageGain to 1.0 so that shutter time is maxed\n> > -\t * before gain touched at all.\n> > +\t * From here on all we can do is max out the shutter time, followed by the\n> > +\t * analogue gain. If we still haven't achieved the target we send the rest\n> > +\t * of the exposure time to digital gain. If we were given no stages to use\n> > +\t * then the default stageGain of 1.0 is used so that shutter time is maxed\n> > +\t * before gain is touched at all.\n> \n> No need to go over 80-cols\n\nArg, right. My tab width was incorrect, therfore the 80cols where\ndifferent ones... will fix.\n\n> \n> >  \t */\n> > -\tif (gains_.empty())\n> > -\t\tstageGain = 1.0;\n> > -\n> >  \tshutter = clampShutter(exposure / clampGain(stageGain));\n> >  \tgain = clampGain(exposure / shutter);\n> >\n> > diff --git a/src/ipa/rpi/controller/rpi/awb.cpp b/src/ipa/rpi/controller/rpi/awb.cpp\n> > index 003c8fa137f3..3503a5ab9218 100644\n> > --- a/src/ipa/rpi/controller/rpi/awb.cpp\n> > +++ b/src/ipa/rpi/controller/rpi/awb.cpp\n> > @@ -91,7 +91,7 @@ static int readCtCurve(ipa::Pwl &ctR, ipa::Pwl &ctB, const libcamera::YamlObject\n> >\n> >  int AwbConfig::read(const libcamera::YamlObject &params)\n> >  {\n> > -\tint ret;\n> > +\tint ret = 0;\n> >\n> >  \tbayes = params[\"bayes\"].get<int>(1);\n> >  \tframePeriod = params[\"frame_period\"].get<uint16_t>(10);\n> \n> There's one code path below were you could return 0 on an error\n> condition\n> \n> \tif (params.contains(\"priors\")) {\n> \t\tfor (const auto &p : params[\"priors\"].asList()) {\n> \t\t\tAwbPrior prior;\n> \t\t\tret = prior.read(p);\n> \t\t\tif (ret)\n> \t\t\t\treturn ret;\n> \t\t\tif (!priors.empty() && prior.lux <= priors.back().lux) {\n> \t\t\t\tLOG(RPiAwb, Error) << \"AwbConfig: Prior must be ordered in increasing lux value\";\n> \t\t\t\treturn -EINVAL;\n> \t\t\t}\n> \t\t\tpriors.push_back(prior);\n> \t\t}\n> \t\tif (priors.empty()) {\n> \t\t\tLOG(RPiAwb, Error) << \"AwbConfig: no AWB priors configured\";\n> \t\t\treturn ret; <---- HERE\n> \t\t}\n> \n> While at it, could you return -EINVAL here ?\n\nThat was the thing I asked Naushir about. I will modify it that way.\n\nCheers,\nStefan\n\n> \n> > diff --git a/src/libcamera/device_enumerator_sysfs.cpp b/src/libcamera/device_enumerator_sysfs.cpp\n> > index fc33ba52b813..7866885c0f73 100644\n> > --- a/src/libcamera/device_enumerator_sysfs.cpp\n> > +++ b/src/libcamera/device_enumerator_sysfs.cpp\n> > @@ -33,7 +33,7 @@ int DeviceEnumeratorSysfs::init()\n> >  int DeviceEnumeratorSysfs::enumerate()\n> >  {\n> >  \tstruct dirent *ent;\n> > -\tDIR *dir;\n> > +\tDIR *dir = nullptr;\n> >\n> >  \tstatic const char * const sysfs_dirs[] = {\n> >  \t\t\"/sys/subsystem/media/devices\",\n> > diff --git a/src/libcamera/pipeline/rpi/vc4/vc4.cpp b/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n> > index 4a89e35f5d7b..e5b6ef2b37cd 100644\n> > --- a/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n> > +++ b/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n> > @@ -802,7 +802,7 @@ void Vc4CameraData::ispInputDequeue(FrameBuffer *buffer)\n> >  void Vc4CameraData::ispOutputDequeue(FrameBuffer *buffer)\n> >  {\n> >  \tRPi::Stream *stream = nullptr;\n> > -\tunsigned int index;\n> > +\tunsigned int index = 0;\n> >\n> >  \tif (!isRunning())\n> >  \t\treturn;\n> \n> These two look good!\n> \n> Thanks\n>   j\n> \n> > --\n> > 2.43.0\n> >","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id C6C46BDB1D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 28 Jun 2024 09:25:35 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 039B662C99;\n\tFri, 28 Jun 2024 11:25:35 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5AAB5619D7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 28 Jun 2024 11:25:33 +0200 (CEST)","from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:82ab:924:d918:cd24])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id A3D25735;\n\tFri, 28 Jun 2024 11:25:08 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"IPnksHr3\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1719566708;\n\tbh=iDxnW9oUScROC4URKmm+B76rTTR5F7DfopPV+WmxWOc=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=IPnksHr3q9bJJnvuk3rxkpwbsZIwGDkXvWoD9rJ1kiAXBuFSX7LiGttsd2syLQZln\n\tQmg4xFAwI5ngHfVygED4S7KXC0AofzZdC1Nqsxu5hwGEkIeYrgHEXtH1VkH/Dmq22H\n\tRtppnR0jVG3W1sUPa+R0B4h1si61Ff7J+g5O91aU=","Date":"Fri, 28 Jun 2024 11:25:29 +0200","From":"Stefan Klug <stefan.klug@ideasonboard.com>","To":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org, \n\tNaushir Patuck <naush@raspberrypi.com>","Subject":"Re: [PATCH] libcamera: fix maybe-uninitialized error","Message-ID":"<z37bl43vujrtcin5p65rkfmugi7riozhdy7do3zguudp5kealw@pvxyzm4m6b3x>","References":"<20240627133730.2554717-1-stefan.klug@ideasonboard.com>\n\t<qxgmeyloww7cuf26e4s4f2wbbq76avku2coljc33zbhxezpgsk@hmb73ahlwpou>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<qxgmeyloww7cuf26e4s4f2wbbq76avku2coljc33zbhxezpgsk@hmb73ahlwpou>","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]