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 1725FC433EF for ; Wed, 9 Feb 2022 15:41:30 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D0AFE83E92; Wed, 9 Feb 2022 16:41:19 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gin.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 872D083D3A; Wed, 9 Feb 2022 16:33:31 +0100 (CET) Received: from good-out-21.clustermail.de (good-out-21.clustermail.de [IPv6:2a02:708:0:30::16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3A15283D3A for ; Wed, 9 Feb 2022 16:33:28 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gin.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=Daniel.Klauer@gin.de Received: from [10.0.0.3] (helo=frontend.clustermail.de) by smtpout-01.clustermail.de with esmtp (Exim 4.94.2) (envelope-from ) id 1nHoyA-00057R-DL for u-boot@lists.denx.de; Wed, 09 Feb 2022 16:33:27 +0100 Received: from [217.6.33.237] (helo=Win2012-02.gin-domain.local) by frontend.clustermail.de with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 (Exim 4.94.2) (envelope-from ) id 1nHoyA-0001ml-Bo for u-boot@lists.denx.de; Wed, 09 Feb 2022 16:33:22 +0100 Received: from daniel-desktop2.fritz.box (10.176.8.31) by Win2012-02.gin-domain.local (10.160.128.12) with Microsoft SMTP Server (TLS) id 15.0.1497.26; Wed, 9 Feb 2022 16:33:21 +0100 From: Daniel Klauer To: Subject: [PATCH 1/2] miiphyutil: Fix inconsistent miiphy_write() error return value Date: Wed, 9 Feb 2022 16:32:56 +0100 Message-ID: <20220209153257.284853-1-daniel.klauer@gin.de> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.176.8.31] X-ClientProxiedBy: Win2012-02.gin-domain.local (10.160.128.12) To Win2012-02.gin-domain.local (10.160.128.12) X-EsetResult: clean, is OK X-EsetId: 37303A29342AAB53617062 X-Mailman-Approved-At: Wed, 09 Feb 2022 16:41:09 +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.5 at phobos.denx.de X-Virus-Status: Clean miiphy_write() should not directly return the error return value from bus->write(), because that is typically a -errno value, while generally miiphy_write() and other miiphy_*() functions return 1 on error. Some miiphy_write() callers only check for > 0 to detect errors. Fix it to match miiphy_read(), which also converts bus->read() failure to "return 1". Signed-off-by: Daniel Klauer --- common/miiphyutil.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/common/miiphyutil.c b/common/miiphyutil.c index 7d4d15ed91..86a27665e3 100644 --- a/common/miiphyutil.c +++ b/common/miiphyutil.c @@ -236,7 +236,7 @@ static struct mii_dev *miiphy_get_active_dev(const char *devname) * This API is deprecated. Use phy_read on a phy_device found via phy_connect * * Returns: - * 0 on success + * 0 on success, 1 on error */ int miiphy_read(const char *devname, unsigned char addr, unsigned char reg, unsigned short *value) @@ -264,18 +264,23 @@ int miiphy_read(const char *devname, unsigned char addr, unsigned char reg, * This API is deprecated. Use phy_write on a phy_device found by phy_connect * * Returns: - * 0 on success + * 0 on success, 1 on error */ int miiphy_write(const char *devname, unsigned char addr, unsigned char reg, unsigned short value) { struct mii_dev *bus; + int ret; bus = miiphy_get_active_dev(devname); - if (bus) - return bus->write(bus, addr, MDIO_DEVAD_NONE, reg, value); + if (!bus) + return 1; - return 1; + ret = bus->write(bus, addr, MDIO_DEVAD_NONE, reg, value); + if (ret < 0) + return 1; + + return 0; } /***************************************************************************** -- 2.32.0