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 phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A5826EB64D9 for ; Thu, 15 Jun 2023 14:59:43 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4E8EE8631F; Thu, 15 Jun 2023 16:59:41 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=collabora.com header.i=@collabora.com header.b="DEqFcYDn"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C8BDA862AA; Thu, 15 Jun 2023 16:59:39 +0200 (CEST) Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 5BEF68631F for ; Thu, 15 Jun 2023 16:59:37 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=eugen.hristev@collabora.com Received: from eugen-station.. (unknown [192.166.149.251]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: ehristev) by madras.collabora.co.uk (Postfix) with ESMTPSA id AE82B6606F73; Thu, 15 Jun 2023 15:59:34 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1686841176; bh=F1L3CARGCBWpqU11kLZAvc0Ih0GpvnVF3E7zx2fevuI=; h=From:To:Cc:Subject:Date:From; b=DEqFcYDnF/S32mmLlN/ZtlwS2CHxKMpSOw+OmD9Nh7f220/kNy+0nSJa4B9DM9oLd 3OAVvhfGyxpTQz+5d0oTTrApj/ORnIdFTwCL/GgzcDXYdyueGwFhZBBqH/cQxmowIQ 6O6Lgz4ore7w2zsHWu4t5G6FMhVsDco0nIpCQc7WxnmZa6jT16d1DtEghaiapi0ptw 7v41f3yTtIp3G2Do5Ug9S0QE6YY1PX2V8Y+c+IrXj3yESkxhfK9r6j12HAiNtXKbrJ 1GLNVLBexPIco6o6CROaU3zzGQMzli+4pyHR4r4Q+WvTIVQ8oVZ2jh5I7C8LctNU1I ekb9tDTPx4e3Q== From: Eugen Hristev To: marex@denx.de, sean.anderson@seco.com, u-boot@lists.denx.de Cc: Eugen Hristev Subject: [PATCH] usb: dwc3: core: fix clk_get_rate returning negative value Date: Thu, 15 Jun 2023 17:59:13 +0300 Message-Id: <20230615145913.182699-1-eugen.hristev@collabora.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Unlike it's Linux counterpart, clk_get_rate can return a negative value, -ve. The driver does not take that into account, stores the rate into an unsigned long, and if clk_get_rate fails, it will take into consideration the actual value and wrongly program the hardware. E.g. on error -2 (no such entry), the rate will be 18446744073709551614 and this will be subsequently used by the driver to program the DWC3 To fix this, exit the function if the value is negative. Fixes: 6bae0eb5b8bd ("usb: dwc3: Calculate REFCLKPER based on reference clock") Signed-off-by: Eugen Hristev --- drivers/usb/dwc3/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 49f6a1900b01..5a8c29424578 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -138,7 +138,7 @@ static void dwc3_ref_clk_period(struct dwc3 *dwc) if (dwc->ref_clk) { rate = clk_get_rate(dwc->ref_clk); - if (!rate) + if (!rate || (long)rate < 0) return; period = NSEC_PER_SEC / rate; } else { -- 2.34.1