Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp8506098ybl; Thu, 16 Jan 2020 18:19:40 -0800 (PST) X-Google-Smtp-Source: APXvYqxLOw0QtBhMsYGuBgwb1zaNlhtncx4e9uSLHC+1gQI48UBf07K7bKqyEQxIHgqX9JIurQIc X-Received: by 2002:aca:1a17:: with SMTP id a23mr1742283oia.84.1579227580556; Thu, 16 Jan 2020 18:19:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579227580; cv=none; d=google.com; s=arc-20160816; b=hLARGkL0bMZjbdKWnBhE66tqdYtXXPj1no8dw34SrSm6nbfWaKJDodPMPEebKyaTbV dLm6puVQioeM56YBZXKIAOy5RzUqEZkdXepAp81O2HHFiqVRXjFHfqlSgbW8tvT+2MJj kXa8GUKpWITSpxAPavt4V7ehWgxGFDZ38Az0ReJmV7n63tVJahKjKze2HmXnFR44sGHE uIfN/lSqLc9xeYHzRbbbcKkHEZF5C2eeBHOPoujOT1kNkPxZGQM5vNBiQqaCrNxwdTuf 80426Id0r9rFpnA1w4fcQMTFdP74BEptzm82T87PFS4gPIpi9qUMoBz70IbmJc/Y67F3 CMwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=oSLpaCaNsACVdpdt4jonN57Mb+A/3QRVdvMldfslXec=; b=eyQq/Pe00xGxap7GcV57I9VKqw2WFNJqlXFlnjQTsOcqYkkriVGw9Oou7KzRbzn/iS /T7m/0vTuEbBQvN9YwiovyzOQQenIIX4kmrWbEe0ohAbJ6XvGIrYwnzhJydUFB2yT+ES fofa4jm9oiKF8ENc/2c7rv5rIlLmMVBW8jPPoD4z+VD58MDISEJzIvRTVnndvFA+Qyn6 L+FF2E7G7Zl1Ir2VKbzyCGKn4jTmSXpT3VaERlT5FCkfvcqlzsrpOCPV2miL9e5w61vq zKZ7xx9INCsWWFwr8qQ9eoniwx+SeH9Z01TtDYkuPvS6KgbnYej0GIuFfUn1QoKw5yp5 S/ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LOqKuHQK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n8si14371086otr.102.2020.01.16.18.19.29; Thu, 16 Jan 2020 18:19:40 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LOqKuHQK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388499AbgAPXZF (ORCPT + 99 others); Thu, 16 Jan 2020 18:25:05 -0500 Received: from mail.kernel.org ([198.145.29.99]:54300 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387705AbgAPXY7 (ORCPT ); Thu, 16 Jan 2020 18:24:59 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0640F20748; Thu, 16 Jan 2020 23:24:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579217098; bh=Rgu0CM3dCYRiyWzMm1lyZZjA+gpZ6G8TmMMTDSWG+IY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LOqKuHQKpwajwirl1QGfYcXZZkpw07QKbM9LrOT4IdX9uBXhE84PNMOZngAkXdXKH 2vppeZ5xRltukJGAyWtg7ZwTyM+CsGB3ROb2mFl/tTCn6gjjtkiHC3WgALyx+yypxa XdQUd1+JQ3ijO602J+zuC7V/7/vWMvkSVbbZYhqs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Janusz Krzysztofik , Sakari Ailus , Mauro Carvalho Chehab Subject: [PATCH 5.4 147/203] media: ov6650: Fix some format attributes not under control Date: Fri, 17 Jan 2020 00:17:44 +0100 Message-Id: <20200116231757.773908129@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200116231745.218684830@linuxfoundation.org> References: <20200116231745.218684830@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Janusz Krzysztofik commit 1c6a2b63095154bbf9e8f38d79487a728331bf65 upstream. User arguments passed to .get/set_fmt() pad operation callbacks may contain unsupported values. The driver takes control over frame size and pixel code as well as colorspace and field attributes but has never cared for remainig format attributes, i.e., ycbcr_enc, quantization and xfer_func, introduced by commit 11ff030c7365 ("[media] v4l2-mediabus: improve colorspace support"). Fix it. Set up a static v4l2_mbus_framefmt structure with attributes initialized to reasonable defaults and use it for updating content of user provided arguments. In case of V4L2_SUBDEV_FORMAT_ACTIVE, postpone frame size update, now performed from inside ov6650_s_fmt() helper, util the user argument is first updated in ov6650_set_fmt() with default frame format content. For V4L2_SUBDEV_FORMAT_TRY, don't copy all attributes to pad config, only those handled by the driver, then fill the response with the default frame format updated with resulting pad config format code and frame size. Fixes: 11ff030c7365 ("[media] v4l2-mediabus: improve colorspace support") Signed-off-by: Janusz Krzysztofik Signed-off-by: Sakari Ailus Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Greg Kroah-Hartman --- drivers/media/i2c/ov6650.c | 51 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 12 deletions(-) --- a/drivers/media/i2c/ov6650.c +++ b/drivers/media/i2c/ov6650.c @@ -213,6 +213,17 @@ static u32 ov6650_codes[] = { MEDIA_BUS_FMT_Y8_1X8, }; +static const struct v4l2_mbus_framefmt ov6650_def_fmt = { + .width = W_CIF, + .height = H_CIF, + .code = MEDIA_BUS_FMT_SBGGR8_1X8, + .colorspace = V4L2_COLORSPACE_SRGB, + .field = V4L2_FIELD_NONE, + .ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT, + .quantization = V4L2_QUANTIZATION_DEFAULT, + .xfer_func = V4L2_XFER_FUNC_DEFAULT, +}; + /* read a register */ static int ov6650_reg_read(struct i2c_client *client, u8 reg, u8 *val) { @@ -513,11 +524,13 @@ static int ov6650_get_fmt(struct v4l2_su if (format->pad) return -EINVAL; + /* initialize response with default media bus frame format */ + *mf = ov6650_def_fmt; + + /* update media bus format code and frame size */ mf->width = priv->rect.width >> priv->half_scale; mf->height = priv->rect.height >> priv->half_scale; mf->code = priv->code; - mf->colorspace = V4L2_COLORSPACE_SRGB; - mf->field = V4L2_FIELD_NONE; return 0; } @@ -656,10 +669,6 @@ static int ov6650_s_fmt(struct v4l2_subd if (!ret) priv->code = code; - if (!ret) { - mf->width = priv->rect.width >> half_scale; - mf->height = priv->rect.height >> half_scale; - } return ret; } @@ -678,9 +687,6 @@ static int ov6650_set_fmt(struct v4l2_su v4l_bound_align_image(&mf->width, 2, W_CIF, 1, &mf->height, 2, H_CIF, 1, 0); - mf->field = V4L2_FIELD_NONE; - mf->colorspace = V4L2_COLORSPACE_SRGB; - switch (mf->code) { case MEDIA_BUS_FMT_Y10_1X10: mf->code = MEDIA_BUS_FMT_Y8_1X8; @@ -698,10 +704,31 @@ static int ov6650_set_fmt(struct v4l2_su break; } - if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE) - return ov6650_s_fmt(sd, mf); - cfg->try_fmt = *mf; + if (format->which == V4L2_SUBDEV_FORMAT_TRY) { + /* store media bus format code and frame size in pad config */ + cfg->try_fmt.width = mf->width; + cfg->try_fmt.height = mf->height; + cfg->try_fmt.code = mf->code; + + /* return default mbus frame format updated with pad config */ + *mf = ov6650_def_fmt; + mf->width = cfg->try_fmt.width; + mf->height = cfg->try_fmt.height; + mf->code = cfg->try_fmt.code; + + } else { + /* apply new media bus format code and frame size */ + int ret = ov6650_s_fmt(sd, mf); + if (ret) + return ret; + + /* return default format updated with active size and code */ + *mf = ov6650_def_fmt; + mf->width = priv->rect.width >> priv->half_scale; + mf->height = priv->rect.height >> priv->half_scale; + mf->code = priv->code; + } return 0; }