Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3383968pxb; Mon, 17 Jan 2022 19:13:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJzSIfLN48QzePac3G4TEat+5VQYR8jbq9N3eXDdxUEZP3E9VIptw+qWttcHAUqGyUChchRd X-Received: by 2002:a17:90b:4c8a:: with SMTP id my10mr12693691pjb.71.1642475601131; Mon, 17 Jan 2022 19:13:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642475601; cv=none; d=google.com; s=arc-20160816; b=rh1e+5DF4Hl9AM9RgdQ5mj17iqgMheKLbrz/d90/XsJYxYru0/bR521f9z4HHg7UP6 g/HvIDzVY0AtEqwTIh/A/1hPWM0GcQ2NscIMVV0ZfeFa7V8M4BCITDlSPeAuQz2QBYlL BwjjyvGea/YjdkHSYJc7b4WjBzv46pHxrmQ3bgFTy9PxtgGHt2a/nOSsjrgfV+v7RhZr I+G9sfqHm+RTTJFDSoNoV7TNp4GM4Cz9jbKxnpMG9bGyQGtkKe77+iAW3RXedWQXyC+I LPFMXQCnlls27t+FYySQRyBvAQ/Ok4+xm9yOZv8ed/Y5c4SItf1dxhj5b8wd70JH6bpq WE4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/vzYwISv2hbRW6FTaV+oIXMhD8fKVo05QU91dTwKz2A=; b=g0eQl+wHyntFslhjz5el+u9ur9mMcOMEaCjt/asBrJYMl42leUHBdWN6jANirBYJ4E mVry/SVHFAsFUTn7L52S3kheyof8OjKkbGEx4jRRZSrbvOTGBSRubEujurcGH8IZkJJo WFKnKMcCr+CtyXp3DFyfcAYX8mrU89m3Wmbv/bdeVZ1KCL1LevqOtvEjSENB5mwQGLpo R15teTtcawjA7GH6pyjZCoZuaEvBKB0OtyL/ZcAh1HLeD8WGNu+R3Y4wVeAGs+p5erac +nFPOy+3KiP25f7Q5kpm4j3ie4a6c6g1W3gE64Yxom8Xjzl2L8LqgYYOzwihrt06kRit GutA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=c1mV5eSV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qe8si1239803pjb.41.2022.01.17.19.13.09; Mon, 17 Jan 2022 19:13:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=c1mV5eSV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244560AbiARCV3 (ORCPT + 99 others); Mon, 17 Jan 2022 21:21:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244567AbiARCU4 (ORCPT ); Mon, 17 Jan 2022 21:20:56 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66FD3C06175D; Mon, 17 Jan 2022 18:20:48 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 22C03B81233; Tue, 18 Jan 2022 02:20:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A5CDDC36AE3; Tue, 18 Jan 2022 02:20:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642472446; bh=TUnm+Toda9hJczhj3ziIH/SgtocelZAF6EwqaINvxNg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c1mV5eSV+z5NuuS1HembPB5KH1L2ekzlHBKjqqfNb6BO+IAu2JIk4mIH5zTcOsADG QE5aPhQiEpXR+xYy1P2L7OLPJCc6NHyLgqSG+unujnyeWTjre9oDGRwN7DOWtLfzRB dwMPDPCkArJz0OZK0dZnx1YJPL917Gjtbd3k5WZyQQCyHZj6t0e9CdSeMh3bAZgLEc u6E8Ijk5yG5P7AYuYqo/wXWrH225svWkGjZ2lOj7lXTb4dlAz/YUpy24wie5wm7hju sH7eoReWdG6no2zFvrYAPYzlk05VXSGr9YWv9juEcw43gWSfMKZ/kjLlmx5HBQz0TE IGvCMeh8s38Ng== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Mauro Carvalho Chehab , Sasha Levin , mchehab@kernel.org, gregkh@linuxfoundation.org, peterz@infradead.org, kitakar@gmail.com, andriy.shevchenko@linux.intel.com, arnd@arndb.de, dan.carpenter@oracle.com, linux-media@vger.kernel.org, linux-staging@lists.linux.dev Subject: [PATCH AUTOSEL 5.16 019/217] media: atomisp: fix try_fmt logic Date: Mon, 17 Jan 2022 21:16:22 -0500 Message-Id: <20220118021940.1942199-19-sashal@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220118021940.1942199-1-sashal@kernel.org> References: <20220118021940.1942199-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mauro Carvalho Chehab [ Upstream commit c9e9094c4e42124af909b2f5f6ded0498e0854ac ] The internal try_fmt logic is not meant to provide everything that the V4L2 API should provide. Also, it doesn't decrement the pads that are used only internally by the driver, but aren't part of the device's output. Fix it. Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- .../staging/media/atomisp/pci/atomisp_ioctl.c | 72 ++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) diff --git a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c b/drivers/staging/media/atomisp/pci/atomisp_ioctl.c index a57e640fbf791..442446e5d59f7 100644 --- a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c +++ b/drivers/staging/media/atomisp/pci/atomisp_ioctl.c @@ -852,6 +852,72 @@ static int atomisp_g_fmt_file(struct file *file, void *fh, return 0; } +static int atomisp_adjust_fmt(struct v4l2_format *f) +{ + const struct atomisp_format_bridge *format_bridge; + u32 padded_width; + + format_bridge = atomisp_get_format_bridge(f->fmt.pix.pixelformat); + + padded_width = f->fmt.pix.width + pad_w; + + if (format_bridge->planar) { + f->fmt.pix.bytesperline = padded_width; + f->fmt.pix.sizeimage = PAGE_ALIGN(f->fmt.pix.height * + DIV_ROUND_UP(format_bridge->depth * + padded_width, 8)); + } else { + f->fmt.pix.bytesperline = DIV_ROUND_UP(format_bridge->depth * + padded_width, 8); + f->fmt.pix.sizeimage = PAGE_ALIGN(f->fmt.pix.height * f->fmt.pix.bytesperline); + } + + if (f->fmt.pix.field == V4L2_FIELD_ANY) + f->fmt.pix.field = V4L2_FIELD_NONE; + + format_bridge = atomisp_get_format_bridge(f->fmt.pix.pixelformat); + if (!format_bridge) + return -EINVAL; + + /* Currently, raw formats are broken!!! */ + if (format_bridge->sh_fmt == IA_CSS_FRAME_FORMAT_RAW) { + f->fmt.pix.pixelformat = V4L2_PIX_FMT_YUV420; + + format_bridge = atomisp_get_format_bridge(f->fmt.pix.pixelformat); + if (!format_bridge) + return -EINVAL; + } + + padded_width = f->fmt.pix.width + pad_w; + + if (format_bridge->planar) { + f->fmt.pix.bytesperline = padded_width; + f->fmt.pix.sizeimage = PAGE_ALIGN(f->fmt.pix.height * + DIV_ROUND_UP(format_bridge->depth * + padded_width, 8)); + } else { + f->fmt.pix.bytesperline = DIV_ROUND_UP(format_bridge->depth * + padded_width, 8); + f->fmt.pix.sizeimage = PAGE_ALIGN(f->fmt.pix.height * f->fmt.pix.bytesperline); + } + + if (f->fmt.pix.field == V4L2_FIELD_ANY) + f->fmt.pix.field = V4L2_FIELD_NONE; + + /* + * FIXME: do we need to setup this differently, depending on the + * sensor or the pipeline? + */ + f->fmt.pix.colorspace = V4L2_COLORSPACE_REC709; + f->fmt.pix.ycbcr_enc = V4L2_YCBCR_ENC_709; + f->fmt.pix.xfer_func = V4L2_XFER_FUNC_709; + + f->fmt.pix.width -= pad_w; + f->fmt.pix.height -= pad_h; + + return 0; +} + /* This function looks up the closest available resolution. */ static int atomisp_try_fmt_cap(struct file *file, void *fh, struct v4l2_format *f) @@ -863,7 +929,11 @@ static int atomisp_try_fmt_cap(struct file *file, void *fh, rt_mutex_lock(&isp->mutex); ret = atomisp_try_fmt(vdev, &f->fmt.pix, NULL); rt_mutex_unlock(&isp->mutex); - return ret; + + if (ret) + return ret; + + return atomisp_adjust_fmt(f); } static int atomisp_s_fmt_cap(struct file *file, void *fh, -- 2.34.1