From mboxrd@z Thu Jan 1 00:00:00 1970 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 F39F0C433EF for ; Thu, 20 Jan 2022 23:16:48 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E2D6283906; Fri, 21 Jan 2022 00:16:32 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=sifive.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=sifive.com header.i=@sifive.com header.b="Cv9ilpoG"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9A46383325; Thu, 20 Jan 2022 08:35:28 +0100 (CET) Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 6BF938303A for ; Thu, 20 Jan 2022 08:35:25 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=andy.chiu@sifive.com Received: by mail-pf1-x433.google.com with SMTP id i17so4579097pfk.11 for ; Wed, 19 Jan 2022 23:35:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zZoyQqYl8NIUxU/PgEue4ZWDGtwRrwWhjr7+Dhpbyo0=; b=Cv9ilpoG2gXurR0/5xRjVRzNUKQet/iw1n5Je1rZay01SvZ9wCOXrPNmj6i6+4rmtJ BrA469ESI52UgSsO1nAlNBIxKJURnBqUilzANimRla0i9J1blmp+veK6tvu2FqBWymha Dj9cfTvwMDMHzY7deoUoD8qqlN23lw1Ef2OsM7LVzysY9784MinLXvpp77Eu4miiAIg3 mbu5SE0mCuN0DMpiEOtJkA3kBHksrW5xZrYxQKIPUipugdJ3JarGg8qRiOZuaR4Li9Hl s7EzJ5SSnGB7U9/OSoAXNFnmRHhHYLOi3Y90HMooVDyydVUa4xuiMbwZVJBnor+srW0w 8Xkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zZoyQqYl8NIUxU/PgEue4ZWDGtwRrwWhjr7+Dhpbyo0=; b=SpF1TJdN9XTcrzVF/8AW394707aAPcj9RTN+CSeN+UrvcAMp9ZJ2l6j8A6isj0vgLm zSfOBO0jBgAeoKWPU+wr9YblJK2+DGdxUiJu637+hicYF1Ae1ynIC+aFE91c9XGzFQHt D/Gc0MfwFxSsnxVgvAwJ617ZubFTFrtptl/Q8FGTyYTARFV03lkqPDqfL4Ri5R+Y8esI GnT2B/3rjyfRciFUBRXu/yuWkQ7BnB1uAB/YWN998eS7fFxYUAWnxTUbdvQliWRBjxpY SbRYgVGY1RZd2DgTDUuIDJBAEPs9OHZsU6ro5FnaHHN1yTmoln6RkErnVbmyo7cvgHPb 2ugA== X-Gm-Message-State: AOAM530IxfOC3bG17Oq9a/Til6SGx8Qk3BMZhy4pI6WDQGVQ7XcubKkH 6fkIScGdwuoaJ7X3Do0OKw7sUw== X-Google-Smtp-Source: ABdhPJz789P+OMttCRWiAvNIQbeKHGuenojo8dENT91tqljwC3dZFgoTBzM4LfSgyQf1yWvS10rlPA== X-Received: by 2002:a05:6a00:216f:b0:49f:dcb7:2bf2 with SMTP id r15-20020a056a00216f00b0049fdcb72bf2mr35075093pff.19.1642664123764; Wed, 19 Jan 2022 23:35:23 -0800 (PST) Received: from archlinux.internal.sifive.com (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id k11sm2090796pfu.180.2022.01.19.23.35.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jan 2022 23:35:23 -0800 (PST) From: Andy Chiu To: monstr@monstr.eu Cc: Andy Chiu , Greentime Hu , Joe Hershberger , Ramon Fried , u-boot@lists.denx.de Subject: [PATCH 3/3] net: xilinx: Force a probe failure if it cannot setup phy Date: Thu, 20 Jan 2022 15:34:20 +0800 Message-Id: <20220120073420.1887809-3-andy.chiu@sifive.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220120073420.1887809-1-andy.chiu@sifive.com> References: <20220120073420.1887809-1-andy.chiu@sifive.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Fri, 21 Jan 2022 00:16:27 +0100 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.2 at phobos.denx.de X-Virus-Status: Clean Or we may get load access faults afterward. The `phydev` field on axi-ethernet’s private struct is not set on a failed phy_connect(): axi_emac_probe() => axiemac_phy_init() => priv->phydev = phy_connect() <--- may fail However, all of the following calls on `axi_emac_ops` assume a valid `phydev` pointer. For example: axiemac_start() => setup_phy() => phy_startup() => if (phydev->drv->startup) <--- deref of phydev return phydev->drv->startup(phydev); Thus, it would be better to fail at the driver probe and let u-boot handle the rest (e.g. probe the driver again if needed), rather than having access faults. Signed-off-by: Andy Chiu Reviewed-by: Greentime Hu --- drivers/net/xilinx_axi_emac.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/net/xilinx_axi_emac.c b/drivers/net/xilinx_axi_emac.c index dbda6c70d8..08322aff88 100644 --- a/drivers/net/xilinx_axi_emac.c +++ b/drivers/net/xilinx_axi_emac.c @@ -782,10 +782,16 @@ static int axiemac_setup_emac(struct udevice *dev) ret = mdio_register_seq(priv->bus, dev_seq(dev)); if (ret) - return ret; + goto fail; - axiemac_phy_init(dev); + ret = axiemac_phy_init(dev); + if (ret) + goto fail_free_mdio; +fail_free_mdio: + mdio_unregister(priv->bus); + mdio_free(priv->bus); +fail: return ret; } -- 2.34.1