From patchwork Fri Sep 8 13:28:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fei Shao X-Patchwork-Id: 13377470 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EDF2DEE7FF2 for ; Fri, 8 Sep 2023 13:29:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=yGQBW3WVM3v/VRaUoknjKbkXa+UEQhsPPPLE7vwMdNU=; b=mJ6R3cTgq7Vceo x6Dh/GOBnXM3URWFY1KauRd+tpnJ+mhP3OoKhvlWOyVhBpn0UhLM4vtcktvBqmHtrqHOYcom9VWzx nE4jRxdML0H3muuIfANdGrz21wyi/eMXaunvWoINriVe7o2qngrJa42bd+jwuyiYYWhS1nrsJ6xgM 7MxagKOtQQnahB0uR8T7NTpfJ0ekMMyds8b5DiI43YPkEDMn1GhwwM6ynnY2PHL8EdpQqLKTTLFb6 qrWYBNaGe87Jrf9jqjeUDgrcjlT8GeTW48sz9HUXofHenRhYpu1nJ3Jt6a/8Gh09cy36XUNMXDG2C Rb9Yntn59UQ9asa7lDFw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qebXv-00DqZx-1Z; Fri, 08 Sep 2023 13:29:15 +0000 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qebXq-00DqXI-2o for linux-arm-kernel@lists.infradead.org; Fri, 08 Sep 2023 13:29:12 +0000 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1c0db66af1bso15365135ad.2 for ; Fri, 08 Sep 2023 06:29:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1694179748; x=1694784548; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=8fTqSPosGVFRSuNbuDzcDh8MPrifrDs8eg/tRpTv6/E=; b=MCw9whvhDlFuJeDiCwQGR3whMxH7TGN3cJRSksw2pd1kfpnjL4TyhHQQpnr9Nhwp/d giaDfbI/AhfQIVwRSUX8y6qXSXs3C+L/xcYcnf0qS4RsuMIFVZk6trnEKOnQ9dvRehqU sT1ZPRKRulHKJxvfv0JvEdDv49v3Cr46zkMzk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694179748; x=1694784548; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=8fTqSPosGVFRSuNbuDzcDh8MPrifrDs8eg/tRpTv6/E=; b=hDV3tLH02DlNNG6GaqN5YLQZITc9LdAEj6Iu3WHszIzDZtMGRky2jrXOxQpSu2tzoF ZxYTMJpFQjblKRfYTopvYXBqsvwXBehDP/eSgoP2/WmzwPBKvuQopOvljbc3XzjDtbmO CvU5QHM/2bqqDJAMUKmLgmjXlyTYQl4n8O5NaqMAV84yamQkQeAL3f3lsjprM3yQs9/O JriTrUjtv5Mol5lvFhe9z3uXXBQHWe2E4DZlwKfOKMp3B5fysqNJy+AE/0cXuJVkbd29 O4Dp3uIkAY1XYPDpNHKTwzjjmMnu7BiR4lrgZg88cSOImkZ9vErQmwXs28FwJlB9T6Vu yipA== X-Gm-Message-State: AOJu0YzKKoC+P3Ywb3m8OySmtsyYS4D1jATyA29HjmiiDnXkhAfCSFwg K6TvtcZlgv9lQ7e4/UlXyz8U5w== X-Google-Smtp-Source: AGHT+IHWCBplIrjcCzuUpgb9NC4rnhznC4Bx+ZzE6bt7VuZlgtVVJg0EhVEiMWW50/fNxqh+vxaWSQ== X-Received: by 2002:a17:902:ce82:b0:1bd:c7e2:462 with SMTP id f2-20020a170902ce8200b001bdc7e20462mr3029639plg.11.1694179747803; Fri, 08 Sep 2023 06:29:07 -0700 (PDT) Received: from fshao-p620.tpe.corp.google.com ([2401:fa00:1:10:2f7e:9c4:ed14:b826]) by smtp.gmail.com with ESMTPSA id o12-20020a170902778c00b001bc6536051bsm1562560pll.184.2023.09.08.06.29.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 06:29:07 -0700 (PDT) From: Fei Shao To: Hans Verkuil , Mauro Carvalho Chehab Cc: linux-mediatek@lists.infradead.org, Fei Shao , AngeloGioacchino Del Regno , Bin Liu , Matthias Brugger , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org Subject: [PATCH] media: mtk-jpegenc: Fix bug in JPEG encode quality selection Date: Fri, 8 Sep 2023 21:28:04 +0800 Message-ID: <20230908132839.2034566-1-fshao@chromium.org> X-Mailer: git-send-email 2.42.0.283.g2d96d420d3-goog MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230908_062910_905702_A3241D09 X-CRM114-Status: GOOD ( 15.10 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The driver uses the upper-bound approach to decide the target JPEG encode quality, but there's a logic bug that if the desired quality is higher than what the driver can support, the driver falls back to using the worst quality. Fix the bug by assuming using the best quality in the beginning, and with trivial refactor to avoid long lines. Fixes: 45f13a57d813 ("media: platform: Add jpeg enc feature") Signed-off-by: Fei Shao Reviewed-by: Chen-Yu Tsai --- drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c index 2bbc48c7402c..f8fa3b841ccf 100644 --- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c +++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c @@ -127,6 +127,7 @@ void mtk_jpeg_set_enc_params(struct mtk_jpeg_ctx *ctx, void __iomem *base) u32 img_stride; u32 mem_stride; u32 i, enc_quality; + u32 nr_enc_quality = ARRAY_SIZE(mtk_jpeg_enc_quality); value = width << 16 | height; writel(value, base + JPEG_ENC_IMG_SIZE); @@ -157,8 +158,8 @@ void mtk_jpeg_set_enc_params(struct mtk_jpeg_ctx *ctx, void __iomem *base) writel(img_stride, base + JPEG_ENC_IMG_STRIDE); writel(mem_stride, base + JPEG_ENC_STRIDE); - enc_quality = mtk_jpeg_enc_quality[0].hardware_value; - for (i = 0; i < ARRAY_SIZE(mtk_jpeg_enc_quality); i++) { + enc_quality = mtk_jpeg_enc_quality[nr_enc_quality - 1].hardware_value; + for (i = 0; i < nr_enc_quality; i++) { if (ctx->enc_quality <= mtk_jpeg_enc_quality[i].quality_param) { enc_quality = mtk_jpeg_enc_quality[i].hardware_value; break;