Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2665033pxj; Mon, 31 May 2021 07:45:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyf08VWK4qvkRvHqPTuDKLzSVgJeO+1fChNof821wfVOY2ECnzyrNsyTEpAmlH7lyhj6ZhS X-Received: by 2002:a17:906:a88c:: with SMTP id ha12mr23503105ejb.129.1622472349565; Mon, 31 May 2021 07:45:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622472349; cv=none; d=google.com; s=arc-20160816; b=xySngbt6mYgF4QrBIFpnboj6Aqv+Z0HESmkFtEXKFGRbfukdgPkqQ0vsBWFeFk8Zlo 7fh8+jNMZj5URgXpls3ZJKqQXHMNbTUZkPHs/jDxhxUzIkhyDg10PGzr6mnGXWw9BxQj 9uhd9L7EBuumfOaEvygWFH7fZ6yajinGWATZtMtOmsvoI77xB7s+I/mzBpIfYHQ5okP6 RxoZ3OcXUZFv524K+UvEorQopgcBUqG2XePUOW4IhaDydiCoovd7EV+Vrn+DN58MJ/2o 47DKpo0A3SKmME+R96D7bKSWE8dyKDtUeZrWGzBT3lypZjV1TpZRofVzErzkLlp/0UEy mo3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=McPwqAwfsGzd1Soo5m51WD1QB5l8enNFB0ZnlCmF8D4=; b=yUlLw3RoA/3s2BpTSmXlRoKVExPcMI7Q4j2R8ZRgmfOlB6jg+ock/0QEIBwQfCPnCk jRuKn6DFAxuI/zDJesqjGrZeL0iLfIIFdiaxXiutviFlDvAfrBPWD4YLKycVvsRcb9JR n78c/zcBR/FZcJyvJxt5OZchzlE+/Qvuuw5cHe8PGCq3o6iZEyWPXVRbgop4ypck9rew 7wdq7HnM9ejWIoI2KXxSB0zB8n34U7b06w7PctRZh9Bi2H1e+2Q8g/ZDMgm/bEcNuT22 oBzTgJhMLZULbx8s1LxCj0cNXAXh36Ad75rQnx5IMDy8Gp9TTmvil01M7s9JqoM18mNQ HpIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tp4OPbUq; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d6si12781427edt.583.2021.05.31.07.45.26; Mon, 31 May 2021 07:45:49 -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=pass header.i=@linuxfoundation.org header.s=korg header.b=tp4OPbUq; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231609AbhEaOp5 (ORCPT + 99 others); Mon, 31 May 2021 10:45:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:60392 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232421AbhEaN7z (ORCPT ); Mon, 31 May 2021 09:59:55 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id DBC8061402; Mon, 31 May 2021 13:36:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622468176; bh=Ill1eplk4IdYv6idJ17y/9StCsRZ9eo1Srla6Dpkocc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tp4OPbUqRn65BHg2FJanln4P0Q9HWr8z9EU2EObBgtdwiMB0rNyNXgWFuLJ127UjE v2aFPNB29F/7XVBm69l/TGn6wDYrZ+2hzMX0QnwOj/2rYWomB5XuZzi2RrEzzu0kET A8MhdI5eZoCKnOHjP8E/aXrSDR5Kq4f7O6ZuetxM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vladimir Oltean , "David S. Miller" Subject: [PATCH 5.10 117/252] net: dsa: sja1105: add error handling in sja1105_setup() Date: Mon, 31 May 2021 15:13:02 +0200 Message-Id: <20210531130701.963639794@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130657.971257589@linuxfoundation.org> References: <20210531130657.971257589@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vladimir Oltean commit cec279a898a3b004411682f212215ccaea1cd0fb upstream. If any of sja1105_static_config_load(), sja1105_clocking_setup() or sja1105_devlink_setup() fails, we can't just return in the middle of sja1105_setup() or memory will leak. Add a cleanup path. Fixes: 0a7bdbc23d8a ("net: dsa: sja1105: move devlink param code to sja1105_devlink.c") Fixes: 8aa9ebccae87 ("net: dsa: Introduce driver for NXP SJA1105 5-port L2 switch") Signed-off-by: Vladimir Oltean Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/dsa/sja1105/sja1105_main.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) --- a/drivers/net/dsa/sja1105/sja1105_main.c +++ b/drivers/net/dsa/sja1105/sja1105_main.c @@ -2922,13 +2922,13 @@ static int sja1105_setup(struct dsa_swit rc = sja1105_static_config_load(priv, ports); if (rc < 0) { dev_err(ds->dev, "Failed to load static config: %d\n", rc); - return rc; + goto out_ptp_clock_unregister; } /* Configure the CGU (PHY link modes and speeds) */ rc = sja1105_clocking_setup(priv); if (rc < 0) { dev_err(ds->dev, "Failed to configure MII clocking: %d\n", rc); - return rc; + goto out_static_config_free; } /* On SJA1105, VLAN filtering per se is always enabled in hardware. * The only thing we can do to disable it is lie about what the 802.1Q @@ -2949,7 +2949,7 @@ static int sja1105_setup(struct dsa_swit rc = sja1105_devlink_setup(ds); if (rc < 0) - return rc; + goto out_static_config_free; /* The DSA/switchdev model brings up switch ports in standalone mode by * default, and that means vlan_filtering is 0 since they're not under @@ -2958,6 +2958,17 @@ static int sja1105_setup(struct dsa_swit rtnl_lock(); rc = sja1105_setup_8021q_tagging(ds, true); rtnl_unlock(); + if (rc) + goto out_devlink_teardown; + + return 0; + +out_devlink_teardown: + sja1105_devlink_teardown(ds); +out_ptp_clock_unregister: + sja1105_ptp_clock_unregister(ds); +out_static_config_free: + sja1105_static_config_free(&priv->static_config); return rc; }