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 8FABAC77B73 for ; Mon, 22 May 2023 08:40:22 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 500B284663; Mon, 22 May 2023 10:40:20 +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="ibXi2UoZ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 634D18467C; Mon, 22 May 2023 10:40:19 +0200 (CEST) Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) (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 4023984660 for ; Mon, 22 May 2023 10:40:15 +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 [46.8.172.200]) (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 790186603292; Mon, 22 May 2023 09:40:14 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1684744814; bh=A28Vv78QbCzArZrPEDPG6wLLI3jcPLr4RShqMAHhL0s=; h=From:To:Cc:Subject:Date:From; b=ibXi2UoZzx7BSnLsyMI87X/bKhTU4t4pGJNjVDlKBprPBvsKvA2KDTKtkysmoCccE KbjD8xsQgBAxTcsnJhL1+zO+K9kQ2K6V/Po8AFLHpreiFV8bmqFnvB6abe6uFgujHE DvLw3LlSuNi42R9vsIo0pNpuI+9tBKcsdzah9Txwks5xQtc8okrkLwO3HOldFxejUG TRDKgGonXf10x7Laa6xXhJxgoDAimC8Nar59YhT9o5+z5DnktWyHJsJgiRoKlL8INB qzXLg8yzTSw7UD68A368zxFjTbHEv6Msj0LnNO8qurjGnrZpg9Qnk3nnBlkdTnLOcn O1lS+LPwhh/Bw== From: Eugen Hristev To: u-boot@lists.denx.de, jagan@edgeble.ai, kever.yang@rock-chips.com Cc: Eugen Hristev Subject: [PATCH] phy: rockchip: inno-usb2: fix phy reg=0 case Date: Mon, 22 May 2023 11:39:58 +0300 Message-Id: <20230522083958.10829-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 The support for #address-cells=2 has a loophole: if the reg is actually 0, but the #address-cells is actually 1, like in such case below: syscon { #address-cells = <1>; phy { reg = <0 0x10>; }; }; then the second u32 of the 'reg' is the size, not the address. The code should check for the parent's #address-cells value, and not assume that if the first u32 is 0, then the #address-cells is 2, and the reg property is something like reg = <0 0xff00 0x10>; Fixed this by looking for the #address-cells value and retrieving the reg address only if this is ==2. To avoid breaking anything I also kept the check `if reg==0` as some DT's may have a wrong #address-cells as parent and even if this commit is correct, it might break the existing wrong device-trees. Fixes: d538efb9adcf ("phy: rockchip: inno-usb2: Add support #address_cells = 2") Signed-off-by: Eugen Hristev --- drivers/phy/rockchip/phy-rockchip-inno-usb2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c index 22e2797eea28..e5e02b6765b1 100644 --- a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c +++ b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c @@ -186,7 +186,7 @@ static int rockchip_usb2phy_probe(struct udevice *dev) } /* support address_cells=2 */ - if (reg == 0) { + if (dev_read_addr_cells(dev) == 2 && reg == 0) { if (ofnode_read_u32_index(dev_ofnode(dev), "reg", 1, ®)) { dev_err(dev, "%s must have reg[1]\n", ofnode_get_name(dev_ofnode(dev))); -- 2.34.1