Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp513161pxb; Thu, 9 Sep 2021 06:12:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyECruJSyKN+TkAsIiPZJmqJWZoAgNgO/fB8eYQNCU9TTCr+qWBI63XdvQ+XdfIF7B+yCxu X-Received: by 2002:a6b:18f:: with SMTP id 137mr2590447iob.214.1631193135408; Thu, 09 Sep 2021 06:12:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631193135; cv=none; d=google.com; s=arc-20160816; b=nC9BL/hLsfi8fR84/2b8hKjpfS3ojyhD0fZTV1fFXCtCf6k1+4XJY2TUECSMRa8zxR mZiG7t1HN1CC3gBduKlu7oI3aaK7I6pJ+wFEgcd9RQ/xsOlswRxfVJQhD5YZQ+rK1WbK uj5m9ZRWlHssOq+Vuvae6lWySuuQP8+dXT71OR7sLXWd8mqpULodgEL305LwZCmwuoPR jumBJFYxYJYyQ8Eq2Hy5Wu0rIsBdi9+4SWpsOf5wYFcpiHjMCr9pHnnROV+GDIvzWmXM 9sPiNiFpoXoHF9BVmOq5aGsD20oAQZ8s0RZMjkfbh6EwHAUA7/VyzHwrZsAs+7yPcLtg Hyiw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=6AIvEYaJr1+xcX4HXti4YdiMqepzbIds9bzMVlwlG1M=; b=cJ1Y62ll8wMKNX6fSG2xP7eeI+L86UvVvOzCbMoYGvTbni6U6TjhjkfBZNGDjhrdqF cg9Uq3xZ86o9Y2Yqxs75ZSYnRb5PVat2ujasMFdZIbBoXuird8ucXWHrHyYVhtGqbwoc 1CHbnwfjlZT+JHeyy4FWih7oPWISQ29QCfwfzoEZeLyUB5TlR41L4+BwbrH7jE9TcL/i Jw+/cKQNJXIWxkyzczapri7rNbIYMPjeGYAHSE6BGnI5p1JgznwjyDQixbu1XXt1XLdh TfvDOlVgb0Jo78gAtBWiAJZrhhX7XX025tWorxaGcU1YKWlyOXZaxA3cM4tGujkNUEmm jLLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZpyY3tNv; 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 a94si1645739jai.31.2021.09.09.06.12.00; Thu, 09 Sep 2021 06:12:15 -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=ZpyY3tNv; 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 S1354295AbhIINKh (ORCPT + 99 others); Thu, 9 Sep 2021 09:10:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:43552 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357129AbhIIM7j (ORCPT ); Thu, 9 Sep 2021 08:59:39 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7498763266; Thu, 9 Sep 2021 11:59:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631188742; bh=2vG7DtQbD1gqmqerqzkJ5XkSDU3JxYEJsQMutIDaoXY=; h=From:To:Cc:Subject:Date:From; b=ZpyY3tNvtGuJwXMDuqR52ON38tGnKHfdUh5FXmg2KurGpKzoMZOD1JCT9lareSnpn maltTWEUEHNoeQOChTvp4CNtUcpGyZoRp+d/pED2M8pSDJtmNLkvgp6Galjbg014JY vRo9nxPnInvNCjbDKK80PjT/NME4egOAR7Mp1v6yaz0Lzuam/FAg3isOWZwCl09COm bokCupYTnVwBa2E5jM66i8sca10EUMtfKFMeEQp02ezpscgK9xI+DaMdrrptb8Mo4+ qWshxITMvHLo+iK5oyKKlN60mzpSYE3j6tdpTt3vrQG2/NoIjcW4LGjyWhW7/rVXBp orv4KKGH6AMNQ== 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 4.14 01/59] media: dib8000: rewrite the init prbs logic Date: Thu, 9 Sep 2021 07:58:02 -0400 Message-Id: <20210909115900.149795-1-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 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 5d9381509b07..59ab01dc62b1 100644 --- a/drivers/media/dvb-frontends/dib8000.c +++ b/drivers/media/dvb-frontends/dib8000.c @@ -2110,32 +2110,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) @@ -2412,10 +2435,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; @@ -3007,6 +3028,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 @@ -3305,8 +3327,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