Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2091991pxk; Sat, 19 Sep 2020 12:31:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxiN5Dzom12YnFYZgvoOndV3bVKaKyJOHxlAw5G1lIjdRZdNUzh3Ll1Yg0/uOwFLwtjf/FE X-Received: by 2002:a50:93e2:: with SMTP id o89mr44913619eda.378.1600543872791; Sat, 19 Sep 2020 12:31:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600543872; cv=none; d=google.com; s=arc-20160816; b=dXH2KzW+cs9dOc7hyXomNsHtW6N5EZYRpGG4ZWp6r1z1t4b9tvlwQ02l2mrDfBidJd ceUFOyIT726mB2ikMq5qDvNFI8s0r0cTDyKFmqJzmONne2yaKDt1ImhbUMbNqpeoJK2L tLVU14o+Vd895650+6e2OfKpMgJvoyxFmT8s2TF7Zze4ba4Ts0iVDoyOp5zze52bSbvD ls9NNVWGcng8/z3rCRZ/2LEpve5QRR9QH23T5iiJuEfExCEmoLyK2RHw30UmxFU3P0/f cgIXePOcf4Tpv/NCfaTh8L/BgUp6zIoD+QMdpz8lamqALaosoq3uWHqFaWzwY7779eov P9cw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from :dkim-signature; bh=6bE1UCN2SxEtk5wLlW6eDkNj/1eK18tXtibVyotZ7CQ=; b=e/zozOmimsaMxsyEWUs5CdVF3ISQgTf18ON2A0KD+mFNzqk1TWKoj+6PXAMMhV5Cuf D8CDSiQmk395t2hdV+JVFU+nW5Y8Lq0Rj8DFnjlUm3YTy6j+3DBcIlr/lyoW12RPd6Oe VX2NBqLgBKtGQVvO8NQilBaRlIABFuUi7Z/eI/u2/oHkWEFWpVszsw9tDsClD7WGqKUf YvHCTEXnQRe9MFBp8ilm4SQtdwoAgMJR/KqLEZKk1zijWUsKycwXslDzdBX9r0oZtiQt 2TslyF9GeOhdAyxLDxr4LNOXgG9UG+sLNfhDIyWemWv4KZ13Z/1BH1mXVYZUVDO5WBFm XrGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=Qf5i6Pqw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r4si5019941ejy.388.2020.09.19.12.30.48; Sat, 19 Sep 2020 12:31:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=Qf5i6Pqw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726621AbgIST3q (ORCPT + 99 others); Sat, 19 Sep 2020 15:29:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726511AbgIST3q (ORCPT ); Sat, 19 Sep 2020 15:29:46 -0400 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8B0BC0613CE; Sat, 19 Sep 2020 12:29:45 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id o5so8826043wrn.13; Sat, 19 Sep 2020 12:29:45 -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=6bE1UCN2SxEtk5wLlW6eDkNj/1eK18tXtibVyotZ7CQ=; b=Qf5i6PqwPm10hX6K72w6i3Ahe+JswP51uGU2ZDhEeloC8zDHKKHbTwO6Oa5pTuCoMO lOPJGpLpgSFa59xdGiw42TqlQdRFGFaYuYbmloe5jp/f4rfBe+bIqnpOEpuwoWpRlurZ HWa5NXPcJ5w1Cyd+tGdMpZ1rT+SIjERTam/2P1MkRvXBPXPxhIwhDqGZdZhxmkduQCsV KMoSYloh1ZHbmWyO+3qbiVZiQbsIenoWoQ5zy67rXJyWijVkDZyeBUx5O6WZLQZ8usV9 l/miRQdSM5uvCUx0AwDI5t6k2A6R4w531OvHKxQ8aSwVewKcKoAb93DIO/66PQyQLHjR 15CQ== 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=6bE1UCN2SxEtk5wLlW6eDkNj/1eK18tXtibVyotZ7CQ=; b=N+ZLiTX0JcB4SAQVpkE9+QK0TK/EmuMaOK9IZUQD2SErshSH+0MaiGuvV1y+T63ADK w5Gd/gHKKahBl4UCwjifIGAPzamaMO6bPnf7nXKCXoWQjIG8R/+3OFetZfKMnplgOFXP 0QvGpbwZYU/57fCota/Qe5pxpZJXToU/EN0xm+urIarWdWQ68LZH/VBeh0wBmWn2aPn0 G9G40e1AOBSDXoFCxK1jEDRw9yOn2vBafJWCH2ayuyuS5Il/VIKO+eh/PT/IXa7eSlkq xGXxjKlQoleDQYsC2Z75xiaL98NAYczJS7eJ8YjmbBzOEQI4uX+T84kFHBrH/3hzk0ZG m5ew== X-Gm-Message-State: AOAM533sQ9i9PEY+pSltQOY5XCsFSX2/rAM5hyZn4PekzBk+Nli7SJsC dAqFxg/11z+0k3CdVDlQlJP3srv9fEs= X-Received: by 2002:adf:fc0a:: with SMTP id i10mr43825459wrr.111.1600543784422; Sat, 19 Sep 2020 12:29:44 -0700 (PDT) Received: from localhost.localdomain (92.40.169.140.threembb.co.uk. [92.40.169.140]) by smtp.gmail.com with ESMTPSA id h2sm12642069wrp.69.2020.09.19.12.29.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Sep 2020 12:29:43 -0700 (PDT) From: Alex Dewar Cc: Alex Dewar , Sean Wang , Andrew Lunn , Vivien Didelot , Florian Fainelli , "David S. Miller" , Jakub Kicinski , Matthias Brugger , Russell King , Landen Chao , netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] net: dsa: mt7530: Add some return-value checks Date: Sat, 19 Sep 2020 20:28:10 +0100 Message-Id: <20200919192809.29120-1-alex.dewar90@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <1600327978.11746.22.camel@mtksdccf07> References: <1600327978.11746.22.camel@mtksdccf07> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In mt7531_cpu_port_config(), if the variable port is neither 5 nor 6, then variable interface will be used uninitialised. Change the function to return -EINVAL in this case. As the return value of mt7531_cpu_port_config() is never checked (even though it returns an int) add a check in the correct place so that the error can be passed up the call stack. Now that we correctly handle errors thrown in this function, also check the return value of mt7531_mac_config() in case an error occurs here. Also add misisng checks to mt7530_setup() and mt7531_setup(), which are another level further up the call stack. Fixes: c288575f7810 ("net: dsa: mt7530: Add the support of MT7531 switch") Addresses-Coverity: 1496993 ("Uninitialized variables") Signed-off-by: Alex Dewar --- v2: - fix typo in commit message - split variable declarations onto multiple lines (Gustavo) - add additional checks for mt753*_setup (Landen) drivers/net/dsa/mt7530.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index 61388945d316..cb3efa7de7a8 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -945,10 +945,14 @@ static int mt753x_cpu_port_enable(struct dsa_switch *ds, int port) { struct mt7530_priv *priv = ds->priv; + int ret; /* Setup max capability of CPU port at first */ - if (priv->info->cpu_port_config) - priv->info->cpu_port_config(ds, port); + if (priv->info->cpu_port_config) { + ret = priv->info->cpu_port_config(ds, port); + if (ret) + return ret; + } /* Enable Mediatek header mode on the cpu port */ mt7530_write(priv, MT7530_PVC_P(port), @@ -1631,9 +1635,11 @@ mt7530_setup(struct dsa_switch *ds) mt7530_rmw(priv, MT7530_PCR_P(i), PCR_MATRIX_MASK, PCR_MATRIX_CLR); - if (dsa_is_cpu_port(ds, i)) - mt753x_cpu_port_enable(ds, i); - else + if (dsa_is_cpu_port(ds, i)) { + ret = mt753x_cpu_port_enable(ds, i); + if (ret) + return ret; + } else mt7530_port_disable(ds, i); /* Enable consistent egress tag */ @@ -1785,9 +1791,11 @@ mt7531_setup(struct dsa_switch *ds) mt7530_set(priv, MT7531_DBG_CNT(i), MT7531_DIS_CLR); - if (dsa_is_cpu_port(ds, i)) - mt753x_cpu_port_enable(ds, i); - else + if (dsa_is_cpu_port(ds, i)) { + ret = mt753x_cpu_port_enable(ds, i); + if (ret) + return ret; + } else mt7530_port_disable(ds, i); /* Enable consistent egress tag */ @@ -2276,6 +2284,7 @@ mt7531_cpu_port_config(struct dsa_switch *ds, int port) struct mt7530_priv *priv = ds->priv; phy_interface_t interface; int speed; + int ret; switch (port) { case 5: @@ -2293,6 +2302,8 @@ mt7531_cpu_port_config(struct dsa_switch *ds, int port) priv->p6_interface = interface; break; + default: + return -EINVAL; } if (interface == PHY_INTERFACE_MODE_2500BASEX) @@ -2300,7 +2311,9 @@ mt7531_cpu_port_config(struct dsa_switch *ds, int port) else speed = SPEED_1000; - mt7531_mac_config(ds, port, MLO_AN_FIXED, interface); + ret = mt7531_mac_config(ds, port, MLO_AN_FIXED, interface); + if (ret) + return ret; mt7530_write(priv, MT7530_PMCR_P(port), PMCR_CPU_PORT_SETTING(priv->id)); mt753x_phylink_mac_link_up(ds, port, MLO_AN_FIXED, interface, NULL, -- 2.28.0