From patchwork Fri Apr 19 09:48:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 790740 Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com [209.85.222.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C06DA130E5B for ; Fri, 19 Apr 2024 09:49:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713520190; cv=none; b=HCEglLjgfSkuDVaGnTKCeM9V9badWJfmEO1l3iNxUYMfM6/twWv4AnW0yKZBiLWv7chabBRRzOiDcQwftIpSWMiO7Z2XXjXzjny6F/tsqObOyBm29bWAQoqSPwIB/TdHULvrVqqpI+XffwoVCs+QVP63tlqocTcg10JQWyybOkU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713520190; c=relaxed/simple; bh=o6W/vqiRX5/Lnl4n/KralCP6cqo+hBRj8ijp3AUHwA0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=B9RAyySapB5YI5jVN7ab6/E7n+/OoY+ao8yYTAL1ckRjkjgaz4LRsuS9vr/R+7jQDPJ9d79aGJhfYI0Suemljx1USt+/R9LlGxAWaeu7ws4/sZxPeqxSGNOHeFgXr+LXQNnIxo8YGFOMBIqZ8NZVvrHL8nc+zi8Zvv7JXvWB+gg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=fkTLAX1A; arc=none smtp.client-ip=209.85.222.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="fkTLAX1A" Received: by mail-qk1-f169.google.com with SMTP id af79cd13be357-78f05aec21cso124242585a.0 for ; Fri, 19 Apr 2024 02:49:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1713520188; x=1714124988; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=vmuUSFnHzqjHSVO6x2xCi4IdU77yIJvh23Ivq0XCHvQ=; b=fkTLAX1AOsZvhNrYs4pzfF+g3qT25dJu3IKhvdTzopFrQQoePV4MlxmLj3n3nZ0/HM A7l0a++14xaFQNQnEAjmKloJvPkfU2L2daz89mmVfFFzBle9vRg6UzEB9QPIfjT4DUmG Uac+zlI7rDdDxZMO48Bb7Qyt3lugaJpIeHKbU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713520188; x=1714124988; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vmuUSFnHzqjHSVO6x2xCi4IdU77yIJvh23Ivq0XCHvQ=; b=da1IwQceY0LLv3EARQxsl5ItQ8Nc+MArTIGfKV/of9cl//oK5XDcXLIpnadQZkMvKU d2+5SbN8/LFlH9owWEtm0hQWyJwkdV6FZ/nCJVoQR1BWXCXsBfWIJeB5v4CQLLjBAuFO fZpus+jXEo0PGg4MCcWbcG0+F+zCxOxV6Dgfo2FzOfKIjKgKlsbjqVUziWAR24UXRskG OCkGx23sq7L97KDibB2r+1r7yBogV5x66osgoMKxHJCxARq3X0c/LBfif9l+QlXFjZNY CBRtu3iYO+9kOvBc2v9UQIpTmfOEDjg4okbdJDZpQtp2sPGwJrb9M59tZ3PPviPph0vF x7Aw== X-Forwarded-Encrypted: i=1; AJvYcCXVMzSCIXvXNm7Gny9UmZNNOqKD/RLClIv0r3R0sp8Wwipc835FcFFc29tOVvYztnzylzaJCej/sVO5V17U+sFYte87/9XK0F66J0YaiQ== X-Gm-Message-State: AOJu0Yzsc3ReYw2ggo5TtwO9j1rxqNqJT6JgwB+B+jgI2Z0Tpq5OJbC5 AV/cnI9cHAPLfRvo3z0ZJHFvRdh+qB8R5oUk3j+EI6WuTp6o3WcIddiEwDFc7w== X-Google-Smtp-Source: AGHT+IGwmCCN5wh4NaLa8aArMkOF/G4Igcbkk8uWKtclUOXaJ3Z6Gx5Noog7Zc3uSUISJQ5MgoV6TQ== X-Received: by 2002:ae9:f50d:0:b0:78f:1044:bcc8 with SMTP id o13-20020ae9f50d000000b0078f1044bcc8mr1806809qkg.61.1713520187814; Fri, 19 Apr 2024 02:49:47 -0700 (PDT) Received: from denia.c.googlers.com (114.152.245.35.bc.googleusercontent.com. [35.245.152.114]) by smtp.gmail.com with ESMTPSA id dt14-20020a05620a478e00b0078d735ca917sm1434532qkb.123.2024.04.19.02.49.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 02:49:47 -0700 (PDT) From: Ricardo Ribalda Date: Fri, 19 Apr 2024 09:48:11 +0000 Subject: [PATCH v2 25/26] media: dvb-frontends: tda10048: Fix integer overflow Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240419-fix-cocci-v2-25-2119e692309c@chromium.org> References: <20240419-fix-cocci-v2-0-2119e692309c@chromium.org> In-Reply-To: <20240419-fix-cocci-v2-0-2119e692309c@chromium.org> To: Martin Tuma , Mauro Carvalho Chehab , Laurent Pinchart , Hugues Fruchet , Alain Volmat , Maxime Coquelin , Alexandre Torgue , Paul Kocialkowski , Greg Kroah-Hartman , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Sakari Ailus , Thierry Reding , Jonathan Hunter , Sowjanya Komatineni , Luca Ceresoli , Matthias Brugger , AngeloGioacchino Del Regno , Hans Verkuil , Sergey Kozlov , Abylay Ospan , Ezequiel Garcia , Dmitry Osipenko , Benjamin Mugnier , Sylvain Petinot , Stanimir Varbanov , Vikash Garodia , Bryan O'Donoghue , Bjorn Andersson , Konrad Dybcio Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-staging@lists.linux.dev, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-arm-msm@vger.kernel.org, Ricardo Ribalda , Dan Carpenter X-Mailer: b4 0.12.4 state->xtal_hz can be up to 16M, so it can overflow a 32 bit integer when multiplied by pll_mfactor. Create a new 64 bit variable to hold the calculations. Reported-by: Dan Carpenter Signed-off-by: Ricardo Ribalda --- drivers/media/dvb-frontends/tda10048.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/media/dvb-frontends/tda10048.c b/drivers/media/dvb-frontends/tda10048.c index 5d5e4e9e4422..3e725cdcc66b 100644 --- a/drivers/media/dvb-frontends/tda10048.c +++ b/drivers/media/dvb-frontends/tda10048.c @@ -410,6 +410,7 @@ static int tda10048_set_if(struct dvb_frontend *fe, u32 bw) struct tda10048_config *config = &state->config; int i; u32 if_freq_khz; + u64 sample_freq; dprintk(1, "%s(bw = %d)\n", __func__, bw); @@ -451,9 +452,11 @@ static int tda10048_set_if(struct dvb_frontend *fe, u32 bw) dprintk(1, "- pll_pfactor = %d\n", state->pll_pfactor); /* Calculate the sample frequency */ - state->sample_freq = state->xtal_hz * (state->pll_mfactor + 45); - state->sample_freq /= (state->pll_nfactor + 1); - state->sample_freq /= (state->pll_pfactor + 4); + sample_freq = state->xtal_hz; + sample_freq *= state->pll_mfactor + 45; + do_div(sample_freq, state->pll_nfactor + 1); + do_div(sample_freq, state->pll_pfactor + 4); + state->sample_freq = sample_freq; dprintk(1, "- sample_freq = %d\n", state->sample_freq); /* Update the I/F */