Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp53050ybg; Mon, 8 Jun 2020 16:13:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzJFKaLigfxbFus1txt2hiInSj29hVOuBBUzQfeZhOVdzfRJwhwNlnxi/b28OOc1e1IcOpG X-Received: by 2002:aa7:c15a:: with SMTP id r26mr23242711edp.21.1591657986152; Mon, 08 Jun 2020 16:13:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591657986; cv=none; d=google.com; s=arc-20160816; b=WuVX3K0oJ5gzhL7Wa7dK+1lIvfbaqHG6DoTpyq3h2SjRBQjMK8/yv53YCgSfXrXeSG GVxNbeu+1j01Kg/BR6g2jBn4J+050FZvtLzRDp9YILtO0yv1TZf9BKHqks5uBfKUvAl3 4lUfvKwF+pfHHaxLvViuUti6XXOpblcfDXRDiqZsQhjHSo7V5HEFOYO/UY5cPOjwQNxj I3yTJ0GBVQf6DX571gOGAnpLQePAOgIYb//xmBdwTyUOexZUUYMA/dAuJBTYHGV5qvu2 EtfxEiXSff60uv156PHgVcXNm+WmcVUDmjJVnU/MRRWOrDTOVQHQE0YoKafjmlQc+hGC Uecw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=k+RcTPrvPq1VrGEoCFo5kPhuLh92iSAqDjYtKilO4QQ=; b=RlbI2OmFJaCxPGyciB1TIjde/gbgv7QK9mqI/LEOR+ICIOYgBF6T/u/cW7QsIrPS/G nJot5Ch8ZbjsUgLuBWAND+AjagUCsZEsBSBQQ+zGHxg28VQNFTRcylu77Ej6ZuMrPXpC UV6dUEl6sWHtgFSUNj5MERdCEQmGm2gTZcDH1B2b14jEyk/W61t8gk0RmuG0YRHhtma7 yPph1jJFXToVrMapIx+nOHOsaDbBzOo4WnLz+CVf6bmhLTjVxDnuN4CrZMupFzojvftJ dZ7JkF+4InMIKMni6VeVUrX8/gpDZ4VmyQ1hcgbp1DnYjSWBb+pjDLOr+YpL7vUtZZIC sKCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cMFxXh4X; 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 y24si60726edu.80.2020.06.08.16.12.43; Mon, 08 Jun 2020 16:13:06 -0700 (PDT) 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=default header.b=cMFxXh4X; 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 S1728482AbgFHXJl (ORCPT + 99 others); Mon, 8 Jun 2020 19:09:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:54010 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728197AbgFHXIg (ORCPT ); Mon, 8 Jun 2020 19:08:36 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DBD0920890; Mon, 8 Jun 2020 23:08:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591657715; bh=lpX2+wur1t1gEsxx2uAp+EdCAOVN3IOjp4QxKK+GMt4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cMFxXh4XMeVV2ADCYMblsHnOVD8Tt3lmB7/dOPaAEoubIf5/QAG8P7TH4gBlAuOVR ImrkkZGr3V6b35EcXo2MhJFigkhfeiuK9OTV/aE0ds89JaFxJmWkgQj4cgRSiA/Ywh yW93W5prYv0rYMiDVEJuFAaQK80MR9APcY6q8IHQ= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Philipp Zabel , Laurent Pinchart , Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin , linux-media@vger.kernel.org, devel@driverdev.osuosl.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH AUTOSEL 5.7 110/274] media: imx: utils: fix media bus format enumeration Date: Mon, 8 Jun 2020 19:03:23 -0400 Message-Id: <20200608230607.3361041-110-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200608230607.3361041-1-sashal@kernel.org> References: <20200608230607.3361041-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Philipp Zabel [ Upstream commit 1df2148fdfc036c9350d41ae81b09b3f8897c9b6 ] Iterate over all media bus formats, not just over the first format in each imx_media_pixfmt entry. Before: $ v4l2-ctl -d $(media-ctl -e ipu1_csi0) --list-subdev-mbus-codes 0 ioctl: VIDIOC_SUBDEV_ENUM_MBUS_CODE (pad=0) 0x2006: MEDIA_BUS_FMT_UYVY8_2X8 0x2008: MEDIA_BUS_FMT_YUYV8_2X8 0x1008: MEDIA_BUS_FMT_RGB565_2X8_LE 0x100a: MEDIA_BUS_FMT_RGB888_1X24 0x100d: MEDIA_BUS_FMT_ARGB8888_1X32 0x3001: MEDIA_BUS_FMT_SBGGR8_1X8 0x3013: MEDIA_BUS_FMT_SGBRG8_1X8 0x3002: MEDIA_BUS_FMT_SGRBG8_1X8 0x3014: MEDIA_BUS_FMT_SRGGB8_1X8 0x3007: MEDIA_BUS_FMT_SBGGR10_1X10 0x300e: MEDIA_BUS_FMT_SGBRG10_1X10 0x300a: MEDIA_BUS_FMT_SGRBG10_1X10 0x300f: MEDIA_BUS_FMT_SRGGB10_1X10 0x2001: MEDIA_BUS_FMT_Y8_1X8 0x200a: MEDIA_BUS_FMT_Y10_1X10 After: $ v4l2-ctl -d $(media-ctl -e ipu1_csi0) --list-subdev-mbus-codes 0 ioctl: VIDIOC_SUBDEV_ENUM_MBUS_CODE (pad=0) 0x2006: MEDIA_BUS_FMT_UYVY8_2X8 0x200f: MEDIA_BUS_FMT_UYVY8_1X16 0x2008: MEDIA_BUS_FMT_YUYV8_2X8 0x2011: MEDIA_BUS_FMT_YUYV8_1X16 0x1008: MEDIA_BUS_FMT_RGB565_2X8_LE 0x100a: MEDIA_BUS_FMT_RGB888_1X24 0x100c: MEDIA_BUS_FMT_RGB888_2X12_LE 0x100d: MEDIA_BUS_FMT_ARGB8888_1X32 0x3001: MEDIA_BUS_FMT_SBGGR8_1X8 0x3013: MEDIA_BUS_FMT_SGBRG8_1X8 0x3002: MEDIA_BUS_FMT_SGRBG8_1X8 0x3014: MEDIA_BUS_FMT_SRGGB8_1X8 0x3007: MEDIA_BUS_FMT_SBGGR10_1X10 0x3008: MEDIA_BUS_FMT_SBGGR12_1X12 0x3019: MEDIA_BUS_FMT_SBGGR14_1X14 0x301d: MEDIA_BUS_FMT_SBGGR16_1X16 0x300e: MEDIA_BUS_FMT_SGBRG10_1X10 0x3010: MEDIA_BUS_FMT_SGBRG12_1X12 0x301a: MEDIA_BUS_FMT_SGBRG14_1X14 0x301e: MEDIA_BUS_FMT_SGBRG16_1X16 0x300a: MEDIA_BUS_FMT_SGRBG10_1X10 0x3011: MEDIA_BUS_FMT_SGRBG12_1X12 0x301b: MEDIA_BUS_FMT_SGRBG14_1X14 0x301f: MEDIA_BUS_FMT_SGRBG16_1X16 0x300f: MEDIA_BUS_FMT_SRGGB10_1X10 0x3012: MEDIA_BUS_FMT_SRGGB12_1X12 0x301c: MEDIA_BUS_FMT_SRGGB14_1X14 0x3020: MEDIA_BUS_FMT_SRGGB16_1X16 0x2001: MEDIA_BUS_FMT_Y8_1X8 0x200a: MEDIA_BUS_FMT_Y10_1X10 0x2013: MEDIA_BUS_FMT_Y12_1X12 [laurent.pinchart@ideasonboard.com: Decrement index to replace loop counter k] [laurent.pinchart@ideasonboard.com: Return directly from within the loops] Fixes: e130291212df5 ("[media] media: Add i.MX media core driver") Signed-off-by: Philipp Zabel Signed-off-by: Laurent Pinchart Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/staging/media/imx/imx-media-utils.c | 22 +++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/drivers/staging/media/imx/imx-media-utils.c b/drivers/staging/media/imx/imx-media-utils.c index 39469031e510..00a71f01786c 100644 --- a/drivers/staging/media/imx/imx-media-utils.c +++ b/drivers/staging/media/imx/imx-media-utils.c @@ -269,6 +269,7 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index, for (i = 0; i < ARRAY_SIZE(pixel_formats); i++) { const struct imx_media_pixfmt *fmt = &pixel_formats[i]; enum codespace_sel fmt_cs_sel; + unsigned int j; fmt_cs_sel = (fmt->cs == IPUV3_COLORSPACE_YUV) ? CS_SEL_YUV : CS_SEL_RGB; @@ -278,15 +279,24 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index, (!allow_bayer && fmt->bayer)) continue; - if (index == 0) { - if (fourcc) - *fourcc = fmt->fourcc; - if (code) - *code = fmt->codes[0]; + if (fourcc && index == 0) { + *fourcc = fmt->fourcc; return 0; } - index--; + if (!code) { + index--; + continue; + } + + for (j = 0; j < ARRAY_SIZE(fmt->codes) && fmt->codes[j]; j++) { + if (index == 0) { + *code = fmt->codes[j]; + return 0; + } + + index--; + } } return -EINVAL; -- 2.25.1