From patchwork Mon Oct 7 08:48:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin Ian King X-Patchwork-Id: 13824369 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 ECD39CFB43F for ; Mon, 7 Oct 2024 08:50:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=yhKs2FfCM3Z7w1CzENDRQ+tMB67rwQA/Uj+rq9gCPhw=; b=qXTTnmGrngxhfDvwcDDVzrEt9J 2N1EvBNPZNFxl30QpHSARVqUhJJqhwJDEnH+U/RLnXdr8ibpornbkBoFMvvTtp6uPVBepGQaWVDN5 2o7D7w7VTk+FZBTq5KTFvA6BDbqbN4X5CHmBL/+x3U7QDLFUw534kouJk9M6Wtc6unzwQqGhVcKHp V+Y4rKD+/3V4OQtNTEjqshEmdwWr0dVyGB3+1Z2xF2Vo8baeDpClOSOq8o9nAJHuRh3qilUFWYZak Z736LaR3B6X7jWDZA5QsxbBjoennckbSac4bpNgpncg/1Wr/13dHOD8BE4z/R8eyj855B9dhy9joL Vbteo2Pw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1sxjRL-00000001ptU-00sm; Mon, 07 Oct 2024 08:50:03 +0000 Received: from mail-ej1-x635.google.com ([2a00:1450:4864:20::635]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1sxjQ4-00000001pj0-0XU8 for linux-arm-kernel@lists.infradead.org; Mon, 07 Oct 2024 08:48:45 +0000 Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-a7a843bef98so560390466b.2 for ; Mon, 07 Oct 2024 01:48:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728290922; x=1728895722; 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=yhKs2FfCM3Z7w1CzENDRQ+tMB67rwQA/Uj+rq9gCPhw=; b=k2ZAE0YQ7TivPdd8P3+gSF0knwOuFwyw8GRDLJB0zyjFMPfJ5junGpf2CNoS0lWhzF kfsriFn3fVZRfYBulduNXduL5sCL+GRp4/MjDGMhxF/+iK9QGVbH/MLA9odtZaKiixUx hzeFf7Q9YM9wm1HpYTTPk44QPDNgDsQFeneUCQib+MAkkrv1rr8JE0g+c7hpNQagO4MI zA0g1KxjiQqDACBamsnqed7eFLkyOsSx7THYeWQqNjCIBk8OweKM4+wAC3uW74piPMlP ub3t8weNiclJJ3s5BDJQpzpt8yjP0rWl/iE9iTCM3MM+ESrfsO/v2LCOnA5fC0Yqc37E OVUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728290922; x=1728895722; 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=yhKs2FfCM3Z7w1CzENDRQ+tMB67rwQA/Uj+rq9gCPhw=; b=DZZSXNkvCg3ZsYVS9HohGCWIptvDd7UZTUuWev0MevNnGlvgzetSnJ4SWLSGmW7XAR 15d7vyDtR9tboUwoJkQootqEIclW+cHqswij23W6hFWmjp91tmlh6xYBkMWlOVlwZ0/N pfD72oX+ViAQ7tGHzMvnWeFaMrl01pS+iJH7jyza20QAVyaCZYtKP8vvknAEo8EsxvSh OJoNljSqNvJ8mlhpJ++fcNqPVFNCxGF8jZS/J+UdYeMMEAz8GRPO1pW8kkWLmyWXqz1x h6PSp+IvI13U7cWxbKIchbWzbJ05fQ5EGBqYDKBTGQBE1xXXTpienJHFaFNr8DDtdtig Vgsw== X-Forwarded-Encrypted: i=1; AJvYcCWcYLN859DVUVmIWfzus7SYF0Dr8shTC8EVAHg9ZCF4KVV3ekri9moKZeP2i+t5BFSCo5QN/vNUMXdpnHkeUIFk@lists.infradead.org X-Gm-Message-State: AOJu0YzgWt2Aq4V20JRC1uuBgEbN+DffwQiF0LdLAgHo7ALBE8/nMm4s 9dAwHMMhQYzItBipsrlukl85qwxNx+bjRhymZaxra3THK5C6Ysyo X-Google-Smtp-Source: AGHT+IHKchNuoOAZZvcCsHWGswmIrcJQuFy0gw3grDmvDHvzW723I7g1EoMwqLb5dtqxi5M6N5tpYA== X-Received: by 2002:a17:907:8b93:b0:a99:5bb3:1237 with SMTP id a640c23a62f3a-a995bb315a1mr139414866b.52.1728290921889; Mon, 07 Oct 2024 01:48:41 -0700 (PDT) Received: from localhost (craw-09-b2-v4wan-169726-cust2117.vm24.cable.virginm.net. [92.238.24.70]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9937615e85sm327739166b.175.2024.10.07.01.48.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Oct 2024 01:48:41 -0700 (PDT) From: Colin Ian King To: Abel Vesa , Peng Fan , Michael Turquette , Stephen Boyd , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , linux-clk@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH][next] clk: imx: pll14xx: Fix potential integer overflow on multiplication Date: Mon, 7 Oct 2024 09:48:40 +0100 Message-Id: <20241007084840.1167527-1-colin.i.king@gmail.com> X-Mailer: git-send-email 2.39.5 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241007_014844_186896_AE429434 X-CRM114-Status: GOOD ( 12.33 ) 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 calculation of fout is using int multiplication and assigning the result to a u64, this can potentially overflow if the int variable mdiv is too large. Fix this by making the 65536 a u64 value to ensure a u64 multiplication is being performed to avoid the overflow. Fixes: 53990cf9d5b4 ("clk: imx: pll14xx: consolidate rate calculation") Signed-off-by: Colin Ian King --- drivers/clk/imx/clk-pll14xx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/clk/imx/clk-pll14xx.c b/drivers/clk/imx/clk-pll14xx.c index d63564dbb12c..2afe361fc711 100644 --- a/drivers/clk/imx/clk-pll14xx.c +++ b/drivers/clk/imx/clk-pll14xx.c @@ -107,7 +107,7 @@ static long pll14xx_calc_rate(struct clk_pll14xx *pll, int mdiv, int pdiv, u64 fout = prate; /* fout = (m * 65536 + k) * Fin / (p * 65536) / (1 << sdiv) */ - fout *= (mdiv * 65536 + kdiv); + fout *= (mdiv * 65536ULL + kdiv); pdiv *= 65536; do_div(fout, pdiv << sdiv);