Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp1413065rdh; Mon, 25 Sep 2023 12:00:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE1/OhyzeIKEcdJ1ZObwSyT7ghLreLpyQPV1C9bSGiCSTerRUEKAg4tWk7nJJU6jdIMWijJ X-Received: by 2002:a05:6359:59e:b0:143:4e76:7e5b with SMTP id ee30-20020a056359059e00b001434e767e5bmr5292794rwb.3.1695668406894; Mon, 25 Sep 2023 12:00:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695668406; cv=none; d=google.com; s=arc-20160816; b=Ax9RyBiN546UhkipY/UajohaWTgBH9YHke0si1aQyB32pbJihhkG9ChiVtutJkEu3k L42C1uXYGQbdx0ZlyzGKVc+VZxpJMySMp+d5VfY0F9/xRd5SMspYvt8VyVbJICeBewey UPfC7mGfZZP0i7mVEwLfM/T01V6xki19GCC8lOxYDDs/BuJUb3ZL5f/YTFlPkMGFH+gA N3IzfbdTot9wcfX3Ge/wrCkgVS6O6USTF3cS7Y4dvw/v751k/z8tyCNxVptmsyvncd9K WGFcNeuw7ZLhZXPL7piiQIMmEr7ueVdFS/aQXRKflg5lq4BNUU1kmPNglLryz23SWouZ ySPQ== 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=379UQYxpAxza5TcrO1uyZtcU91VH4r4NWvGfZfDBNQU=; fh=YrDxnoZE2zu1w4A5O/pMyb6W2NB5EAkKDOR3m7KPwy0=; b=MkjYHL2WONoMYEqwBqRIM+d7mjZKPigbWD+Oa3u7k16brsn0nXsnUkR5ckX3dO32Pk QAiCvnDraUPT3OnA0wR88OyGAmeFMhClvnRo7rJ6dy7wWHfjtBQh3B25TfZVo97tXG/8 SWRrInJ5GzezguqbliUd0YPsOYWYdPtJQonnwAv9//jUnP50v1LOpVsME9sYGQifl+4T wG0ArjM6jmwurAI7vEOGUHh4bjT61r1TY70FWHrPV73AN/06hAfUaFQk8bKeNDof+QmA WcA8iPl8cC0ij+LbgQeSROIh65zvOgJNvYYZ4JBU7zdDO81DjwqwMVnaQCV0yzytDvB0 CorA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MNjcK0yr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id s10-20020a63770a000000b00577561158b3si11225360pgc.411.2023.09.25.12.00.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 12:00:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MNjcK0yr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 7FFDC80E7128; Mon, 25 Sep 2023 08:48:14 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229437AbjIYPsH (ORCPT + 99 others); Mon, 25 Sep 2023 11:48:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232976AbjIYPrf (ORCPT ); Mon, 25 Sep 2023 11:47:35 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA96ACCF for ; Mon, 25 Sep 2023 08:47:23 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-32001d16a14so6465551f8f.1 for ; Mon, 25 Sep 2023 08:47:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695656842; x=1696261642; darn=vger.kernel.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=379UQYxpAxza5TcrO1uyZtcU91VH4r4NWvGfZfDBNQU=; b=MNjcK0yri2jZ4587XZyaCe0i2VJcsGmlGkxv9O1tWNKLVhI2a9UyRG06GaJxFAJyVy KtxwTLJnHu9xUvvOcfUL7bcQZdbAfyo7VFro8XZ8LONc4lAloYqK5Zk/IzOd6CTuQQcv 1B4dDN/kS5e0bjYlgkty0bTvZrxlRtxubsHZxU4zQ2e119cgWDIxtVHwGWp1sZW7mR6J 4nePOLJTyef4s27kNux+p95F9fDEKWFhFdKMmCNAADPqhhdexaPjLHuSVCWlbjzXoh/b Wnh56q6qQW0hiAijH7ReLae6hMo9fna9vq6NWkp3bDuTPnxpTvV3yNqgblUJMXBCdQDI Dz3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695656842; x=1696261642; 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=379UQYxpAxza5TcrO1uyZtcU91VH4r4NWvGfZfDBNQU=; b=R6irbRE2mTCiv1XFnAtv5zSC2psdyVhg5LnQ8isui1Uqk2Pa8blKcJADMsDvm9dnAD cZ9PpHjKjY2bIJusgeZwxXne0c8I1Ij8WpbYKh/Oo/o0dDGYihKlm3M0jjQW7QPfK6of eDo7RsjXyGouqKPAC5A8eHuRhxYf1xRES3GxCi+XSMKYsRS6ZzLQz9prgfMeRXiqfwG0 gY6hRwQsdA75qpUK3VnoHGDKL6ifox6uVnJrwTsU+6rFXfV0vzCflmPNHe2UKDIoOLLx Wd/go1Gx3rsIJLqqdUiR4U/ODEykYl6t9jJla/eV34WOeulRfl8lZmbS/oJAer5w5apF Hasw== X-Gm-Message-State: AOJu0YyhNrt4fL6VvGZXr7uvTp4JVrCcplKHkEjZrYjI+2uhayAb7sV6 Iu8pGaumNKRydCshvLpESLuEGw== X-Received: by 2002:a05:6000:11c6:b0:321:7844:de44 with SMTP id i6-20020a05600011c600b003217844de44mr5532767wrx.45.1695656842188; Mon, 25 Sep 2023 08:47:22 -0700 (PDT) Received: from sagittarius-a.chello.ie (188-141-3-169.dynamic.upc.ie. [188.141.3.169]) by smtp.gmail.com with ESMTPSA id d4-20020adffd84000000b0031f34a395e7sm12077536wrr.45.2023.09.25.08.47.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 08:47:21 -0700 (PDT) From: Bryan O'Donoghue To: linux-arm-msm@vger.kernel.org, linux-media@vger.kernel.org, hverkuil@xs4all.nl, laurent.pinchart@ideasonboard.com, rfoss@kernel.org, todor.too@gmail.com, agross@kernel.org, andersson@kernel.org, konrad.dybcio@linaro.org, mchehab@kernel.org, sakari.ailus@linux.intel.com, andrey.konovalov@linaro.org Cc: linux-kernel@vger.kernel.org, Bryan O'Donoghue Subject: [RESEND PATCH v6 10/17] media: qcom: camss: Untangle if/else spaghetti in camss Date: Mon, 25 Sep 2023 16:47:00 +0100 Message-ID: <20230925154707.837542-11-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230925154707.837542-1-bryan.odonoghue@linaro.org> References: <20230925154707.837542-1-bryan.odonoghue@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 25 Sep 2023 08:48:15 -0700 (PDT) We have a very convoluted if/else legacy here which needs to be rationalised to make it more sustainable. Adding in another Soc or two will make some of these if statements into increasingly large multi-clause behemoths. Introduce switches in the obvious places to despaghetiify. Signed-off-by: Bryan O'Donoghue Acked-by: Konrad Dybcio --- .../media/platform/qcom/camss/camss-csiphy.c | 16 +++++---- drivers/media/platform/qcom/camss/camss-vfe.c | 33 +++++++++++-------- .../media/platform/qcom/camss/camss-video.c | 17 +++++----- 3 files changed, 37 insertions(+), 29 deletions(-) diff --git a/drivers/media/platform/qcom/camss/camss-csiphy.c b/drivers/media/platform/qcom/camss/camss-csiphy.c index 4310a132dcbe2..18f9a4defb2a4 100644 --- a/drivers/media/platform/qcom/camss/camss-csiphy.c +++ b/drivers/media/platform/qcom/camss/camss-csiphy.c @@ -558,19 +558,21 @@ int msm_csiphy_subdev_init(struct camss *camss, csiphy->cfg.combo_mode = 0; csiphy->ops = res->ops; - if (camss->res->version == CAMSS_8x16) { + switch (camss->res->version) { + case CAMSS_8x16: csiphy->formats = csiphy_formats_8x16; csiphy->nformats = ARRAY_SIZE(csiphy_formats_8x16); - } else if (camss->res->version == CAMSS_8x96 || - camss->res->version == CAMSS_660) { + break; + case CAMSS_8x96: + case CAMSS_660: csiphy->formats = csiphy_formats_8x96; csiphy->nformats = ARRAY_SIZE(csiphy_formats_8x96); - } else if (camss->res->version == CAMSS_845 || - camss->res->version == CAMSS_8250) { + break; + case CAMSS_845: + case CAMSS_8250: csiphy->formats = csiphy_formats_sdm845; csiphy->nformats = ARRAY_SIZE(csiphy_formats_sdm845); - } else { - return -EINVAL; + break; } /* Memory */ diff --git a/drivers/media/platform/qcom/camss/camss-vfe.c b/drivers/media/platform/qcom/camss/camss-vfe.c index 4d5c32d3dddbf..db8f68819ded9 100644 --- a/drivers/media/platform/qcom/camss/camss-vfe.c +++ b/drivers/media/platform/qcom/camss/camss-vfe.c @@ -170,7 +170,8 @@ static u32 vfe_src_pad_code(struct vfe_line *line, u32 sink_code, { struct vfe_device *vfe = to_vfe(line); - if (vfe->camss->res->version == CAMSS_8x16) + switch (vfe->camss->res->version) { + case CAMSS_8x16: switch (sink_code) { case MEDIA_BUS_FMT_YUYV8_1X16: { @@ -218,10 +219,11 @@ static u32 vfe_src_pad_code(struct vfe_line *line, u32 sink_code, return sink_code; } - else if (vfe->camss->res->version == CAMSS_8x96 || - vfe->camss->res->version == CAMSS_660 || - vfe->camss->res->version == CAMSS_845 || - vfe->camss->res->version == CAMSS_8250) + break; + case CAMSS_8x96: + case CAMSS_660: + case CAMSS_845: + case CAMSS_8250: switch (sink_code) { case MEDIA_BUS_FMT_YUYV8_1X16: { @@ -281,8 +283,9 @@ static u32 vfe_src_pad_code(struct vfe_line *line, u32 sink_code, return sink_code; } - else - return 0; + break; + } + return 0; } int vfe_reset(struct vfe_device *vfe) @@ -1379,7 +1382,8 @@ int msm_vfe_subdev_init(struct camss *camss, struct vfe_device *vfe, init_completion(&l->output.sof); init_completion(&l->output.reg_update); - if (camss->res->version == CAMSS_8x16) { + switch (camss->res->version) { + case CAMSS_8x16: if (i == VFE_LINE_PIX) { l->formats = formats_pix_8x16; l->nformats = ARRAY_SIZE(formats_pix_8x16); @@ -1387,8 +1391,9 @@ int msm_vfe_subdev_init(struct camss *camss, struct vfe_device *vfe, l->formats = formats_rdi_8x16; l->nformats = ARRAY_SIZE(formats_rdi_8x16); } - } else if (camss->res->version == CAMSS_8x96 || - camss->res->version == CAMSS_660) { + break; + case CAMSS_8x96: + case CAMSS_660: if (i == VFE_LINE_PIX) { l->formats = formats_pix_8x96; l->nformats = ARRAY_SIZE(formats_pix_8x96); @@ -1396,12 +1401,12 @@ int msm_vfe_subdev_init(struct camss *camss, struct vfe_device *vfe, l->formats = formats_rdi_8x96; l->nformats = ARRAY_SIZE(formats_rdi_8x96); } - } else if (camss->res->version == CAMSS_845 || - camss->res->version == CAMSS_8250) { + break; + case CAMSS_845: + case CAMSS_8250: l->formats = formats_rdi_845; l->nformats = ARRAY_SIZE(formats_rdi_845); - } else { - return -EINVAL; + break; } } diff --git a/drivers/media/platform/qcom/camss/camss-video.c b/drivers/media/platform/qcom/camss/camss-video.c index 46a89b5f6c171..a89da5ef47109 100644 --- a/drivers/media/platform/qcom/camss/camss-video.c +++ b/drivers/media/platform/qcom/camss/camss-video.c @@ -1006,7 +1006,8 @@ int msm_video_register(struct camss_video *video, struct v4l2_device *v4l2_dev, mutex_init(&video->lock); - if (video->camss->res->version == CAMSS_8x16) { + switch (video->camss->res->version) { + case CAMSS_8x16: if (is_pix) { video->formats = formats_pix_8x16; video->nformats = ARRAY_SIZE(formats_pix_8x16); @@ -1014,8 +1015,9 @@ int msm_video_register(struct camss_video *video, struct v4l2_device *v4l2_dev, video->formats = formats_rdi_8x16; video->nformats = ARRAY_SIZE(formats_rdi_8x16); } - } else if (video->camss->res->version == CAMSS_8x96 || - video->camss->res->version == CAMSS_660) { + break; + case CAMSS_8x96: + case CAMSS_660: if (is_pix) { video->formats = formats_pix_8x96; video->nformats = ARRAY_SIZE(formats_pix_8x96); @@ -1023,13 +1025,12 @@ int msm_video_register(struct camss_video *video, struct v4l2_device *v4l2_dev, video->formats = formats_rdi_8x96; video->nformats = ARRAY_SIZE(formats_rdi_8x96); } - } else if (video->camss->res->version == CAMSS_845 || - video->camss->res->version == CAMSS_8250) { + break; + case CAMSS_845: + case CAMSS_8250: video->formats = formats_rdi_845; video->nformats = ARRAY_SIZE(formats_rdi_845); - } else { - ret = -EINVAL; - goto error_video_register; + break; } ret = msm_video_init_format(video); -- 2.42.0