From patchwork Thu Sep 12 05:09:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harvey Yang X-Patchwork-Id: 21246 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 235D7BF415 for ; Thu, 12 Sep 2024 05:14:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D9496634FF; Thu, 12 Sep 2024 07:14:20 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="WRWAYCKP"; dkim-atps=neutral Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D6E04618F0 for ; Thu, 12 Sep 2024 07:14:17 +0200 (CEST) Received: by mail-pj1-x1029.google.com with SMTP id 98e67ed59e1d1-2d8881850d9so435776a91.3 for ; Wed, 11 Sep 2024 22:14:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1726118055; x=1726722855; darn=lists.libcamera.org; 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=7+fqqkDQ80DgARYQpLwDpjYvmrJNNkk0b7z3EHMkHGU=; b=WRWAYCKPP30n9GsMQpJip3GFj0e93Pb63IKuRWV/fVJ58PeXbuZOhDWmNI3BJYVsqo 2nRulB5CrQmhhG7fOYuowikyw4ZftCpSH3MZ4xD07O5MY1Djyf62SMQDdMxEIX3puIYp /XfHdT0i6W14uiNeeZitOeGNJT+x4KB9RkkBs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726118055; x=1726722855; 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=7+fqqkDQ80DgARYQpLwDpjYvmrJNNkk0b7z3EHMkHGU=; b=ByFx7y/YaWT5FSu6bLYb9+cfRfsSkRF/0SIVVyuGrmiQliYDqcWmRzRcGU59SR4AbZ czpqw4iEJQMKUCQ4jn9qeYU/EU3JyfrVlT9QSuqO32eu1Cl4a43r2TwQDOZkivAE2UFv 3Otc8npxkXIny2qaOCHP5ABlFmJdDt5mWaDt0rXXyZ6ZdM8JZVZoPbfDTaWFecMkC866 IqYhF9RGtgNXACABaxLNoHO2FQLZmlRvjT9T01gzeRlDw0Gb6/JNw4aAkPvzCmaDQPQG pmVJJPkLDTBOo4irEVa/dapqlHMhtxkJEwWZVrisCcjr6jyMm4cBksPiVPpQhBMNiwaW ODng== X-Gm-Message-State: AOJu0Yw5NVGjOunaZqmxoDoLBzoOzufMV+li5FCLzchle//VKZGBcyZ4 5Z5LlBqXLeOvnstjgPvcMSt+fR0jTznInDsLXYt20o6vJGidjhnjYPZjHNDYCQKEuD76Q+q6dP4 = X-Google-Smtp-Source: AGHT+IGrCBBYrIlEiLLEgpBNxzrFzhgiG/iKiu57iOoIWIaNhnz6eUEUW5OmT8f/jwJGNKz/xI4elA== X-Received: by 2002:a17:90a:4906:b0:2d8:9c97:3c33 with SMTP id 98e67ed59e1d1-2dba0061173mr1662525a91.28.1726118055496; Wed, 11 Sep 2024 22:14:15 -0700 (PDT) Received: from chenghaoyang-low.c.googlers.com.com (208.158.221.35.bc.googleusercontent.com. [35.221.158.208]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2db0419aab4sm9599977a91.15.2024.09.11.22.14.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 22:14:14 -0700 (PDT) From: Harvey Yang X-Google-Original-From: Harvey Yang To: libcamera-devel@lists.libcamera.org Cc: Han-Lin Chen , Harvey Yang Subject: [PATCH 1/1] libcamera: Put buffer back to V4L2BufferCache when VIDIOC_QBUF fails Date: Thu, 12 Sep 2024 05:09:39 +0000 Message-ID: <20240912051409.3495486-2-chenghaoyang@google.com> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog In-Reply-To: <20240912051409.3495486-1-chenghaoyang@google.com> References: <20240912051409.3495486-1-chenghaoyang@google.com> 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" From: Han-Lin Chen The patch puts buffer back to V4L2BufferCache when VIDIOC_QBUF fails in V4L2VideoDevice. This is to avoid cache leaks and causing assert. Signed-off-by: Han-Lin Chen Co-developed-by: Harvey Yang --- src/libcamera/v4l2_videodevice.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 76742e18..75a2cdb1 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -1626,11 +1626,15 @@ int V4L2VideoDevice::queueBuffer(FrameBuffer *buffer) */ if (planes.size() < numV4l2Planes) { LOG(V4L2, Error) << "Frame buffer has too few planes"; + cache_->put(buf.index); + return -EINVAL; } if (planes.size() != numV4l2Planes && !buffer->_d()->isContiguous()) { LOG(V4L2, Error) << "Device format requires contiguous buffer"; + cache_->put(buf.index); + return -EINVAL; } @@ -1673,6 +1677,8 @@ int V4L2VideoDevice::queueBuffer(FrameBuffer *buffer) if (i != planes.size() - 1 && bytesused != length) { LOG(V4L2, Error) << "Holes in multi-planar buffer not supported"; + cache_->put(buf.index); + return -EINVAL; } } @@ -1722,6 +1728,8 @@ int V4L2VideoDevice::queueBuffer(FrameBuffer *buffer) LOG(V4L2, Error) << "Failed to queue buffer " << buf.index << ": " << strerror(-ret); + cache_->put(buf.index); + return ret; }