From patchwork Sat Sep 12 21:45:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1362935 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=tk/FdJXC; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BpmRW224pz9sT6 for ; Sun, 13 Sep 2020 07:46:46 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1AA1282317; Sat, 12 Sep 2020 23:46:31 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.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=gmail.com header.i=@gmail.com header.b="tk/FdJXC"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id EF5BA82314; Sat, 12 Sep 2020 23:46:21 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,FREEMAIL_FROM,SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.2 Received: from mail-qt1-x843.google.com (mail-qt1-x843.google.com [IPv6:2607:f8b0:4864:20::843]) (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 D20AC8229B for ; Sat, 12 Sep 2020 23:46:03 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qt1-x843.google.com with SMTP id n10so10727936qtv.3 for ; Sat, 12 Sep 2020 14:46:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=S9vxybhFadf6IDv9nv0XH9aZkuaunoDm0omvyme+V18=; b=tk/FdJXCll0lS2ElkqO+6M6RenGedCtT40HsmLIJETOy7AyrUzr0L8g3hBdWk0Sqj3 pKMWuhg/itwrexwsrxUw1s2vWphbCP2VIEqNGR46xPZU3B5C3xqGY6rpEC98IcffRlrK +2zbwj29vh4s/25WIy6Idb3d8koEFIHrGWf3LCF8TvOUw1Q0ZaM5pxUwCafAFrHKB2Zd n+EPFNus0IOTgjwbHoyEHvPmHKJdwfgRS6PmBtD+ZdTpVo35NFml00Af5eet+4Fgp6Cr UpIPpsH1VXo4t2B1qgsaAtcMfO3R5Jki+ePgyaH3uyke4nhSL8XgCnpzvI3U/tkD5qv/ LSYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=S9vxybhFadf6IDv9nv0XH9aZkuaunoDm0omvyme+V18=; b=Hi2dpq5RHA2xaL8ApOnm9ltgwQr1lzEJQBEUPOJKsoc5mjYxx0Ii0B8+ytcSoNBu4e KFp8O4rOENthj5pSDpJnUDrSO+ASS+KgLqoM3I1oK9ozT2hpU5YvogCTQqf8X3m+e4pF P7QA0ZhHj2xokFpQMsjhMNkaoRPeW6+4racW7pTsQA5ozjXgem0/fDYVqIbD8WDllzaz 182+Ot8npLrRlzQQHSPjgd5MjeCFx5yR8Ksgn2E/IOoQFAz7k1MWoI5cqKGVNm2GezbN aratcMGiNl+nkZ3LZht8AW5Vbo2K5lrF5bKTT/I3J9/ywUqT8gpGZ0dDhHb+5RFoclEt 3o2w== X-Gm-Message-State: AOAM530zDmmYCf1RwhJBxmQIOc9S9CthrVmFFpMMX/BfXEk25K3+BwJq sV2HSZUvLjWGqNow7KNvv7s4YK0RycqI7g== X-Google-Smtp-Source: ABdhPJwAs1zIGDVJKDnWMjp2eUHbFZ218V6wJud1qNBVz9x2XaZzX21JgS+eS52B66D6HHa3ljz9VA== X-Received: by 2002:ac8:fb3:: with SMTP id b48mr7812583qtk.16.1599947162478; Sat, 12 Sep 2020 14:46:02 -0700 (PDT) Received: from godwin.fios-router.home (pool-108-51-35-162.washdc.fios.verizon.net. [108.51.35.162]) by smtp.gmail.com with ESMTPSA id k20sm8745419qtb.34.2020.09.12.14.46.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Sep 2020 14:46:01 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Simon Glass , Heinrich Schuchardt , Joe Hershberger , Sean Anderson Subject: [PATCH 2/3] net: Expose some errors generated in net_init Date: Sat, 12 Sep 2020 17:45:43 -0400 Message-Id: <20200912214544.362594-3-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200912214544.362594-1-seanga2@gmail.com> References: <20200912214544.362594-1-seanga2@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.3 at phobos.denx.de X-Virus-Status: Clean net_init does not always succeed, and there is no existing mechanism to discover errors. This patch allows callers of net_init (such as net_init) to handle errors. The root issue is that eth_get_dev can fail, but net_init_loop doesn't expose that. The ideal way to fix eth_get_dev would be to return an error with ERR_PTR, but there are a lot of callers, and all of them just check if it's NULL. Another approach would be to change the signature to something like int eth_get_dev(struct udevice **pdev) but that would require rewriting all of the many callers. Signed-off-by: Sean Anderson Reviewed-by: Simon Glass --- include/net.h | 2 +- net/eth-uclass.c | 3 +++ net/net.c | 15 +++++++++++---- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/include/net.h b/include/net.h index 1bf9867f8c..b80b13ae7c 100644 --- a/include/net.h +++ b/include/net.h @@ -593,7 +593,7 @@ extern int net_ntp_time_offset; /* offset time from UTC */ #endif /* Initialize the network adapter */ -void net_init(void); +int net_init(void); int net_loop(enum proto_t); /* Load failed. Start again. */ diff --git a/net/eth-uclass.c b/net/eth-uclass.c index 0d9b75a9a2..1f59d24f54 100644 --- a/net/eth-uclass.c +++ b/net/eth-uclass.c @@ -75,6 +75,9 @@ struct udevice *eth_get_dev(void) struct eth_uclass_priv *uc_priv; uc_priv = eth_get_uclass_priv(); + if (!uc_priv) + return NULL; + if (!uc_priv->current) eth_errno = uclass_first_device(UCLASS_ETH, &uc_priv->current); diff --git a/net/net.c b/net/net.c index 28d9eebf9d..3afd0d6fb0 100644 --- a/net/net.c +++ b/net/net.c @@ -353,12 +353,19 @@ void net_auto_load(void) tftp_start(TFTPGET); } -static void net_init_loop(void) +static int net_init_loop(void) { if (eth_get_dev()) memcpy(net_ethaddr, eth_get_ethaddr(), 6); + else + /* + * Not ideal, but there's no way to get the actual error, and I + * don't feel like fixing all the users of eth_get_dev to deal + * with errors. + */ + return -ENONET; - return; + return 0; } static void net_clear_handlers(void) @@ -373,7 +380,7 @@ static void net_cleanup_loop(void) net_clear_handlers(); } -void net_init(void) +int net_init(void) { static int first_call = 1; @@ -396,7 +403,7 @@ void net_init(void) first_call = 0; } - net_init_loop(); + return net_init_loop(); } /**********************************************************************/