From patchwork Thu Mar 2 19:06:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suhrid Subramaniam X-Patchwork-Id: 18337 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 3E698BF415 for ; Thu, 2 Mar 2023 19:06:49 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id F3BAD626E7; Thu, 2 Mar 2023 20:06:48 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1677784009; bh=XOz1FrvY7SWwVe4qXQvCadGwaGheac2+Ec6GZJPJxcY=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=f+lUaBXxeK/cryYLeuV1xtHB96HKrXYpd0+DF24m1jDmrz7ahLzluWdDhDSoiz6GK 5388FAPkrxmN+ZTRxb0NkTxYV1cdFEiU1rkLx6Igk6xxGq7CVo536a/ODQQPCouzOA 8ZRGZETpaIVBhBtF1+4g8SUBHDC0WcThXHeC1WYg/VAAsgUGjw2dHBhLS/FL68Q6JJ dC+6rQRHiWzSQRoEuOuLfqQWK7HGU44B6nxekFQhNsfs66+k6n6VvEdsloisg13UAl f6+wjhUw5wiApdtfRQ7HLTLYlBf94P12lEgMJb5et3o1RK7nJJjg8mKvPiHXHgl/yD 0cIQ4d16Nu0Qg== Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4AB60626C0 for ; Thu, 2 Mar 2023 20:06:47 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="IVHXMSbi"; dkim-atps=neutral Received: by mail-pg1-x52a.google.com with SMTP id bn17so67353pgb.10 for ; Thu, 02 Mar 2023 11:06:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TyOC1x3ApcC5bBRg9wLAKO3a40hcsJotiPl1gabBuHM=; b=IVHXMSbiMADINKJAvJO5PBCsOhsWqZRbOYSSJ1hMeqVlXVEJB1MexrDKGYglzsKmF0 GPLHuW06dMqTHFcikZ4+hjCesDrKhvj8tWx3+Rn9IXX1512ZDGV5eyWzifzDyAWYUODg rc1iq5JzYMS+yRPdz4pcGKHWWNt5mZ96J6eztkZ5UsQL9RhE61YCtPqPR66UjvQzP4Zg 4fFjzumuiaxRTgSIIdyuJgkiyFw+SkZlIJiN4D67nFA+Yx1CiB2Vujnk0/J/3p+Us/zA yZKfVVNx+F77Q9gkhtHLZQXyHuNdN4zXNSNNkbUikvDg3yxdSP9vk1svcLs6QX5aAFNR UrMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TyOC1x3ApcC5bBRg9wLAKO3a40hcsJotiPl1gabBuHM=; b=DVQg4Le57EiqEkolnEQDZ2CzGDvDN+ubMMHm2dZYfzHrexHa920Xz+eJWtbsE92+1v DVEFmfY/IZf96QPCXjgyQOi9FrPP2t6boJz/TFSQyGzJLJm1Bf4zBT/sbXNut7KFIXHB mDH6xCX9+DINxnwErBQkYSiVqfWkzMAx1OlfcwBQ14OGPtVIl5B7O0zpKAT/gFcC5bMh nVYBOpk8hujJmjbbmz/Iz/O7pRCM3fqvSBX/73m+pylNVRpWRyKORHWK0rQ5uzzI6r7U opITqgckYa9jVlP5WU2jQ4hIam2dOF3pTN53WK3U0HwKXvA3t25d39m95Cxd6MDQST2v ETLg== X-Gm-Message-State: AO0yUKUhPhXG0BJRgjtUYew7eOXSTt3OKmdEzLWUwL3d7N3Oj+7ZtH/s KrzoQXFGXoPWuUnZlFu3fFV+GfFh6DMi3A== X-Google-Smtp-Source: AK7set/uQOQYncbZ0ofHBSHum/WNzX/drvPx/F50Fh1tI3TwHhSxQZf8ipHwYDibY2Dn0I4S1M24Kw== X-Received: by 2002:a05:6a00:1502:b0:5fc:cd83:92f1 with SMTP id q2-20020a056a00150200b005fccd8392f1mr10140333pfu.1.1677784005644; Thu, 02 Mar 2023 11:06:45 -0800 (PST) Received: from localhost.localdomain (sfosm0151r356001-v22.wiline.com. [67.207.106.98]) by smtp.gmail.com with ESMTPSA id x26-20020aa784da000000b005d92c9afbd4sm63678pfn.33.2023.03.02.11.06.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Mar 2023 11:06:45 -0800 (PST) X-Google-Original-From: Suhrid Subramaniam To: libcamera-devel@lists.libcamera.org Date: Thu, 2 Mar 2023 11:06:29 -0800 Message-Id: <20230302190629.12506-2-suhrid.subramaniam@mediatek.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230302190629.12506-1-suhrid.subramaniam@mediatek.com> References: <20230302190629.12506-1-suhrid.subramaniam@mediatek.com> MIME-Version: 1.0 Subject: [libcamera-devel] [libcamera-devel, v3, 1/1] libcamera: converter: Check converter validity 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: , X-Patchwork-Original-From: Suhrid Subramaniam via libcamera-devel From: Suhrid Subramaniam Reply-To: Suhrid Subramaniam Cc: Suhrid Subramaniam Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" - In cases where ConverterFactoryBase::create returns a nullptr, converter_->isValid() causes a segmentation fault. - Solve this by checking if converter_ is a nullptr. - Additionally, check for converter validity in the create function itself and return a nullptr if the converter is invalid. Signed-off-by: Suhrid Subramaniam --- src/libcamera/converter.cpp | 3 ++- src/libcamera/pipeline/simple/simple.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libcamera/converter.cpp b/src/libcamera/converter.cpp index 3de39cff..38141da6 100644 --- a/src/libcamera/converter.cpp +++ b/src/libcamera/converter.cpp @@ -226,8 +226,9 @@ std::unique_ptr ConverterFactoryBase::create(MediaDevice *media) << "Creating converter from " << factory->name_ << " factory with " << (it == compatibles.end() ? "no" : media->driver()) << " alias."; + std::unique_ptr converter_ = factory->createInstance(media); - return factory->createInstance(media); + return converter_->isValid() ? std::move(converter_) : nullptr; } return nullptr; diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp index 24ded4db..2423ec10 100644 --- a/src/libcamera/pipeline/simple/simple.cpp +++ b/src/libcamera/pipeline/simple/simple.cpp @@ -493,7 +493,7 @@ int SimpleCameraData::init() MediaDevice *converter = pipe->converter(); if (converter) { converter_ = ConverterFactoryBase::create(converter); - if (!converter_->isValid()) { + if (!converter_) { LOG(SimplePipeline, Warning) << "Failed to create converter, disabling format conversion"; converter_.reset();