[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20250304111453.1688-1-m.masimov@mt-integration.ru>
Date: Tue, 4 Mar 2025 14:14:53 +0300
From: Murad Masimov <m.masimov@...integration.ru>
To: Mauro Carvalho Chehab <mchehab@...nel.org>
CC: Zheyu Ma <zheyuma97@...il.com>, Laurent Pinchart
<laurent.pinchart+renesas@...asonboard.com>, Murad Masimov
<m.masimov@...integration.ru>, "Rob Herring (Arm)" <robh@...nel.org>, Wolfram
Sang <wsa+renesas@...g-engineering.com>, Heiner Kallweit
<hkallweit1@...il.com>, Uwe Kleine-König
<u.kleine-koenig@...gutronix.de>, Fred Richter <frichter@...ppauge.com>,
Michael Ira Krufky <mkrufky@...uxtv.org>, Brad Love <brad@...tdimension.cc>,
<linux-media@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
<lvc-project@...uxtesting.org>
Subject: [PATCH] media: lgdt3306a: handle negative SNR in lgdt3306a_calculate_snr_x100
The lgdt3306a_calculate_snr_x100() function returns value of type u32.
However it is possible that the calculated SNR value is negative, which
may affect the behaviour of the driver. E.g. lgdt3306a_read_snr() assumes
SNR (x10) can be represented as a value of type u16 so passing negative
32-bit values would result in garbage there.
Since the dvb-frontends API only allows unsigned SNR values,
lgdt3306a_calculate_snr_x100() should return 0 if SNR is negative.
The same way calculate_snr() returns 0 on negative SNR in lgdt330x driver.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
Fixes: b63b36fa44d0 ("[media] DVB: add support for LG Electronics LGDT3306A ATSC/QAM-B Demodulator")
Signed-off-by: Murad Masimov <m.masimov@...integration.ru>
---
drivers/media/dvb-frontends/lgdt3306a.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/media/dvb-frontends/lgdt3306a.c b/drivers/media/dvb-frontends/lgdt3306a.c
index 6ab9d4de65ce..e6c3b65157e5 100644
--- a/drivers/media/dvb-frontends/lgdt3306a.c
+++ b/drivers/media/dvb-frontends/lgdt3306a.c
@@ -1500,6 +1500,9 @@ static u32 lgdt3306a_calculate_snr_x100(struct lgdt3306a_state *state)
snr_x100 = log10_x1000((pwr * 10000) / mse) - 3000;
dbg_info("mse=%u, pwr=%u, snr_x100=%d\n", mse, pwr, snr_x100);
+ if ((s32)snr_x100 < 0)
+ return 0;
+
return snr_x100;
}
--
2.39.2
Powered by blists - more mailing lists