From patchwork Wed Jun 3 14:16:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 3908 Return-Path: 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 AB4576115D for ; Wed, 3 Jun 2020 16:16:28 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="CXHw+/VC"; dkim-atps=neutral Received: from emerald.amanokami.net (fs76eef344.knge213.ap.nuro.jp [118.238.243.68]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 0F9A827C; Wed, 3 Jun 2020 16:16:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1591193788; bh=fzX5dsUHNWEcVPbQjILd17OrXxrDz+27H6d9cGGr7dE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CXHw+/VC1HXIq6EptMay9rW55nuHsVAvYvq9s9S8lnPRcTvSAFfPQOIw+JASmwbZL D81OGEJJtbTJqcxzrM8Lbfxq+EF4bOJdQqX9eycA5W4uRI5APH05QYp4b0wC/wGy+4 cMYWQxKqeS3OjQ5yXu92t4Zfo3zdmFmhKEl3TiVg= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Wed, 3 Jun 2020 23:16:08 +0900 Message-Id: <20200603141609.18584-5-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200603141609.18584-1-paul.elder@ideasonboard.com> References: <20200603141609.18584-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 4/5] v4l2: v4l2_camera_proxy: Don't return -EINVAL for zero sizeimage in REQBUFS 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-List-Received-Date: Wed, 03 Jun 2020 14:16:29 -0000 If VIDIOC_REQBUFS returns -EINVAL, it signals to the application that the requested buffer or memory type is not supported. If we return -EINVAL due to a zero sizeimage, then the application will think that we don't support a memory type that we actually do. On the other hand, sizeimage will be zero for formats whose size we don't know how to calculate, such as MJPEG. If we try to stream such formats anyway, we will get a floating point exception and crash. Issue a warning for now, and don't return -EINVAL, so that we can continue operation. Signed-off-by: Paul Elder --- src/v4l2/v4l2_camera_proxy.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp index d2419b96..f84982a2 100644 --- a/src/v4l2/v4l2_camera_proxy.cpp +++ b/src/v4l2/v4l2_camera_proxy.cpp @@ -352,8 +352,18 @@ int V4L2CameraProxy::vidioc_reqbufs(struct v4l2_requestbuffers *arg) return -EINVAL; sizeimage_ = calculateSizeImage(streamConfig_); + /* + * If we return -EINVAL here then the application will think that we + * don't support streaming mmap. Since we don't support readwrite and + * userptr either, the application will get confused and think that + * we don't support anything. + * On the other hand, if a format has a zero sizeimage (eg. MJPG), + * we'll get a floating point exception when we try to stream it. + */ if (sizeimage_ == 0) - return -EINVAL; + LOG(V4L2Compat, Warning) + << "sizeimage of at least one format is zero. " + << "Streaming this format will cause a floating point exception."; setFmtFromConfig(streamConfig_);