Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp501953pxb; Thu, 9 Sep 2021 06:00:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwCnKKYsdV4fcUKNdqrABXtI58OHQDwuLV4bsYkH3XD0uz4cfjiY+IqWuvPolGQQD1wp+qV X-Received: by 2002:a17:906:c05a:: with SMTP id bm26mr3273433ejb.498.1631192448895; Thu, 09 Sep 2021 06:00:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631192448; cv=none; d=google.com; s=arc-20160816; b=pcg9+42qAG09P4umh5yp937DVG84pzMgBfrbm0l4SMJC7vV1M0ok3PPlGV8vPuEHca dL8b763A6n92Zu7+n1P1b3l23TqqaE7w7ahKKfJcDjEmYMYd6ELDajRB2aILaHtPY6al 8T8ElLmYQTFKxccn7Gp4xGxGu2F8Az8ar+OMrq6ghgcIaRprwKQNFOYFZnI44Sfyk1MO 2e9IX0VxZppyFk43MCfrc3T/D4EmtGWXEizYcXUTF0jPmpz6fGF+Qplx3ddrXbo3QpNP 849dsAnoFMrOKvqtGS214S6Ki+ZfbiAfnFqS7YIem+rSoOjj8NrDwABW91gPXCg94s8Q X1qA== 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=cW3nhDyc9ImepJqH0wTI28BP44EjUa8REaQZd63mkNA=; b=Bx5XPcUdRO5qEbsTxvNVZsyp3+EdxM+rpjLJvJnHQ7SgkaqX93/Y9ixvNtV75lGokW 0hnSNZSahfParBUQs28a189SvQ0EA2HaRenr5CQLQ9exlyjyuUEQU2s9ldz+tQJDD+7I 1w8CdAeR2fbQXCCON5fTEBoYoNBg+k6QdVezUpkajJMAULu+OMF8F4DK6NiMcOk3HvlX lxUHvqLD6DF0+5Nq7+lfBe+b+n+qlFgYf0eUZ/Cz2au5k9uAvE89bxtaJFSANuOvCUby GD8mrakguLUfm9R1i3fHrdAx1gQZrORbfwE0JgIPQTioI0IWk6hbx01usT5vDMStMrT/ c5OQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NensyPIa; 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 qf26si119199ejc.664.2021.09.09.06.00.21; Thu, 09 Sep 2021 06:00:48 -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=k20201202 header.b=NensyPIa; 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 S1355226AbhIIM57 (ORCPT + 99 others); Thu, 9 Sep 2021 08:57:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:56650 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347679AbhIIMlS (ORCPT ); Thu, 9 Sep 2021 08:41:18 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D52756103D; Thu, 9 Sep 2021 11:55:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631188511; bh=gB9z9wL68N4zA6j+tsmo/QkfIMZQNo6VHD+mttTBms0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NensyPIafXteNXueRBM+VClI41yH2+GUfgIny9Ak/qMTQYi75B7eelyZ7c6ZZJfwY mQoBgtP7RpluGtKgDyNDOc5JIhFZ9wttYF6ABRGVIzeNG+RldzKoOvOZXfYYyvFl1u CnNnvEsvacul6iKcjgqpuvkNvfS6ceywA3hbuPvmysdE7UlA9+rVNhxV5QDZs/fP9D LLXwapiPYLyT7IBu5dUUeT60+hx2gIvpZKOyM1qnveF+SwfW8b7SdESkOecDqzc8Py +D7AVxmw29rAaKVglmNsRf14K4d1Dzc5UpnU6KbcPrCgH+UeQkv1yMmE1E6f5hATK+ /mYa0PClEt/Ww== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Mauro Carvalho Chehab , Sasha Levin , linux-media@vger.kernel.org Subject: [PATCH AUTOSEL 5.4 003/109] media: dib8000: rewrite the init prbs logic Date: Thu, 9 Sep 2021 07:53:20 -0400 Message-Id: <20210909115507.147917-3-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210909115507.147917-1-sashal@kernel.org> References: <20210909115507.147917-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 8db11aebdb8f93f46a8513c22c9bd52fa23263aa ] The logic at dib8000_get_init_prbs() has a few issues: 1. the tables used there has an extra unused value at the beginning; 2. the dprintk() message doesn't write the right value when transmission mode is not 8K; 3. the array overflow validation is done by the callers. Rewrite the code to fix such issues. This should also shut up those smatch warnings: drivers/media/dvb-frontends/dib8000.c:2125 dib8000_get_init_prbs() error: buffer overflow 'lut_prbs_8k' 14 <= 14 drivers/media/dvb-frontends/dib8000.c:2129 dib8000_get_init_prbs() error: buffer overflow 'lut_prbs_2k' 14 <= 14 drivers/media/dvb-frontends/dib8000.c:2131 dib8000_get_init_prbs() error: buffer overflow 'lut_prbs_4k' 14 <= 14 drivers/media/dvb-frontends/dib8000.c:2134 dib8000_get_init_prbs() error: buffer overflow 'lut_prbs_8k' 14 <= 14 Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/dvb-frontends/dib8000.c | 58 +++++++++++++++++++-------- 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/drivers/media/dvb-frontends/dib8000.c b/drivers/media/dvb-frontends/dib8000.c index 082796534b0a..bb02354a48b8 100644 --- a/drivers/media/dvb-frontends/dib8000.c +++ b/drivers/media/dvb-frontends/dib8000.c @@ -2107,32 +2107,55 @@ static void dib8000_load_ana_fe_coefs(struct dib8000_state *state, const s16 *an dib8000_write_word(state, 117 + mode, ana_fe[mode]); } -static const u16 lut_prbs_2k[14] = { - 0, 0x423, 0x009, 0x5C7, 0x7A6, 0x3D8, 0x527, 0x7FF, 0x79B, 0x3D6, 0x3A2, 0x53B, 0x2F4, 0x213 +static const u16 lut_prbs_2k[13] = { + 0x423, 0x009, 0x5C7, + 0x7A6, 0x3D8, 0x527, + 0x7FF, 0x79B, 0x3D6, + 0x3A2, 0x53B, 0x2F4, + 0x213 }; -static const u16 lut_prbs_4k[14] = { - 0, 0x208, 0x0C3, 0x7B9, 0x423, 0x5C7, 0x3D8, 0x7FF, 0x3D6, 0x53B, 0x213, 0x029, 0x0D0, 0x48E + +static const u16 lut_prbs_4k[13] = { + 0x208, 0x0C3, 0x7B9, + 0x423, 0x5C7, 0x3D8, + 0x7FF, 0x3D6, 0x53B, + 0x213, 0x029, 0x0D0, + 0x48E }; -static const u16 lut_prbs_8k[14] = { - 0, 0x740, 0x069, 0x7DD, 0x208, 0x7B9, 0x5C7, 0x7FF, 0x53B, 0x029, 0x48E, 0x4C4, 0x367, 0x684 + +static const u16 lut_prbs_8k[13] = { + 0x740, 0x069, 0x7DD, + 0x208, 0x7B9, 0x5C7, + 0x7FF, 0x53B, 0x029, + 0x48E, 0x4C4, 0x367, + 0x684 }; static u16 dib8000_get_init_prbs(struct dib8000_state *state, u16 subchannel) { int sub_channel_prbs_group = 0; + int prbs_group; - sub_channel_prbs_group = (subchannel / 3) + 1; - dprintk("sub_channel_prbs_group = %d , subchannel =%d prbs = 0x%04x\n", sub_channel_prbs_group, subchannel, lut_prbs_8k[sub_channel_prbs_group]); + sub_channel_prbs_group = subchannel / 3; + if (sub_channel_prbs_group >= ARRAY_SIZE(lut_prbs_2k)) + return 0; switch (state->fe[0]->dtv_property_cache.transmission_mode) { case TRANSMISSION_MODE_2K: - return lut_prbs_2k[sub_channel_prbs_group]; + prbs_group = lut_prbs_2k[sub_channel_prbs_group]; + break; case TRANSMISSION_MODE_4K: - return lut_prbs_4k[sub_channel_prbs_group]; + prbs_group = lut_prbs_4k[sub_channel_prbs_group]; + break; default: case TRANSMISSION_MODE_8K: - return lut_prbs_8k[sub_channel_prbs_group]; + prbs_group = lut_prbs_8k[sub_channel_prbs_group]; } + + dprintk("sub_channel_prbs_group = %d , subchannel =%d prbs = 0x%04x\n", + sub_channel_prbs_group, subchannel, prbs_group); + + return prbs_group; } static void dib8000_set_13seg_channel(struct dib8000_state *state) @@ -2409,10 +2432,8 @@ static void dib8000_set_isdbt_common_channel(struct dib8000_state *state, u8 seq /* TSB or ISDBT ? apply it now */ if (c->isdbt_sb_mode) { dib8000_set_sb_channel(state); - if (c->isdbt_sb_subchannel < 14) - init_prbs = dib8000_get_init_prbs(state, c->isdbt_sb_subchannel); - else - init_prbs = 0; + init_prbs = dib8000_get_init_prbs(state, + c->isdbt_sb_subchannel); } else { dib8000_set_13seg_channel(state); init_prbs = 0xfff; @@ -3004,6 +3025,7 @@ static int dib8000_tune(struct dvb_frontend *fe) unsigned long *timeout = &state->timeout; unsigned long now = jiffies; + u16 init_prbs; #ifdef DIB8000_AGC_FREEZE u16 agc1, agc2; #endif @@ -3302,8 +3324,10 @@ static int dib8000_tune(struct dvb_frontend *fe) break; case CT_DEMOD_STEP_11: /* 41 : init prbs autosearch */ - if (state->subchannel <= 41) { - dib8000_set_subchannel_prbs(state, dib8000_get_init_prbs(state, state->subchannel)); + init_prbs = dib8000_get_init_prbs(state, state->subchannel); + + if (init_prbs) { + dib8000_set_subchannel_prbs(state, init_prbs); *tune_state = CT_DEMOD_STEP_9; } else { *tune_state = CT_DEMOD_STOP; -- 2.30.2