Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2907416pxb; Tue, 24 Aug 2021 10:20:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyku8mpirGeqmOMDCmWPzSzCv5Rai+iY1+gKzC61txd0v5YeDgMmWpiWXLzFAGxt8l+aV+b X-Received: by 2002:a92:3012:: with SMTP id x18mr7262125ile.249.1629825600543; Tue, 24 Aug 2021 10:20:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629825600; cv=none; d=google.com; s=arc-20160816; b=uAxdsvUZoKFE98R5s4rwSgM9/I3W8L3OhuAwfIuP7V/JhzdGthfM3qhwbMGSkONAFl dkFvwo1/MnTt9Jcpiq4NRaOjbispwE8lTzlyVJnVULM7GNiMpSqqPIzfaJtFeouQ43ee KPLs8JIfokddJymDVB7xYMl/SBrRicNpLRKNYzfpQr7Orvuvccl23BksxcgOKlL0s+7E PIcYeUOGfHyoD0/Pyn4gj+14g6gxv1xhYD3G7/5CPM8cyG2juOUEpweJSKa2zyGE6lX9 gaPRcdq6xN2FfBiwdPW9i7v2Yw1fwpzBayoX4eHsy6+nuC26Cr82U6268UXFMlGpi1G5 vB2A== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=np9hORp78xx4fX+g8yoDBZAkl58vD8gVeDb3QMetVFM=; b=n1VAfxvNm9nCP5PDJkkObAGAJhdtrcuvJC7K/kPC0NXbJvW8640Ac/Eg2c5l9vWGTi DPOP3x6ZodPj6sRamSv1xiDPWhHG84wX4ysIQ+dwquTtAlhn07UykjKiSyX59IoEvBx8 lhum0RGrcUzgXjpQTaqKJE/8oYHZBC5p57sbhCqgRY11WYXlWfDWXefj/1KWCU/rvwlR u/kmC7jUy5Lr7sARVFmJJXXKD8iycyek9xSkHH1EZ8wEzCM0GtT/jS5zI7V9XSAxn+iV QObKxHQT74Ldo62QA1u7eQtuNJG5ZNmiylB7QWh5vPKpodEv3XD6BSs3LeDTxj/iFL4E b5Pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=WzcKgLBh; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l5si709376jaj.63.2021.08.24.10.19.48; Tue, 24 Aug 2021 10:20:00 -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=@kernel.org header.s=k20201202 header.b=WzcKgLBh; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240051AbhHXRR7 (ORCPT + 99 others); Tue, 24 Aug 2021 13:17:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:56448 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239986AbhHXRPt (ORCPT ); Tue, 24 Aug 2021 13:15:49 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id ADEE961A8C; Tue, 24 Aug 2021 17:01:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629824507; bh=pPm7qFIa8uFuzH1Z2KuX4Sxkam7n7y9z9FcSM0jIv4Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WzcKgLBhqDmT9EnGY6vy3cMO9INj3dBG3WklP8QAK27LnZS242Rie6zwHwRKl8Cjy Z+dC8WKJwtpyVlQcuaZCv/ZC4zk99WEXWEM5lZHdAeb9+3ORRfBZWQ4L3V4xJZUgJ/ 14BUF4pgyRlQmOFA739wS3B57shc4MSafrTxjokAsf+phMz0UQErPic3XS7yKIcBGc xB0dfGY2G7V1Tv/4+RsAtKLEhFWADtmwla3A0ufsFRB08vTpPm66JLusNe+jdNI3sx nfK/cb+GPzhGmKkVgFN8znP/nGL7gSxqj4duMGZO4kyTjixaFDdzb3yAYq6PrcytgG KhIGIpfA+wvcw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Saravana Kannan , Andrew Lunn , Marc Zyngier , Kevin Hilman , "David S . Miller" , Sasha Levin Subject: [PATCH 5.4 40/61] net: mdio-mux: Don't ignore memory allocation errors Date: Tue, 24 Aug 2021 13:00:45 -0400 Message-Id: <20210824170106.710221-41-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210824170106.710221-1-sashal@kernel.org> References: <20210824170106.710221-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.4.143-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-5.4.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 5.4.143-rc1 X-KernelTest-Deadline: 2021-08-26T17:01+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Saravana Kannan [ Upstream commit 99d81e942474cc7677d12f673f42a7ea699e2589 ] If we are seeing memory allocation errors, don't try to continue registering child mdiobus devices. It's unlikely they'll succeed. Fixes: 342fa1964439 ("mdio: mux: make child bus walking more permissive and errors more verbose") Signed-off-by: Saravana Kannan Reviewed-by: Andrew Lunn Acked-by: Marc Zyngier Tested-by: Marc Zyngier Acked-by: Kevin Hilman Tested-by: Kevin Hilman Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/phy/mdio-mux.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/drivers/net/phy/mdio-mux.c b/drivers/net/phy/mdio-mux.c index 6a1d3540210b..c96ef3b3fa3a 100644 --- a/drivers/net/phy/mdio-mux.c +++ b/drivers/net/phy/mdio-mux.c @@ -82,6 +82,17 @@ out: static int parent_count; +static void mdio_mux_uninit_children(struct mdio_mux_parent_bus *pb) +{ + struct mdio_mux_child_bus *cb = pb->children; + + while (cb) { + mdiobus_unregister(cb->mii_bus); + mdiobus_free(cb->mii_bus); + cb = cb->next; + } +} + int mdio_mux_init(struct device *dev, struct device_node *mux_node, int (*switch_fn)(int cur, int desired, void *data), @@ -144,7 +155,7 @@ int mdio_mux_init(struct device *dev, cb = devm_kzalloc(dev, sizeof(*cb), GFP_KERNEL); if (!cb) { ret_val = -ENOMEM; - continue; + goto err_loop; } cb->bus_number = v; cb->parent = pb; @@ -152,8 +163,7 @@ int mdio_mux_init(struct device *dev, cb->mii_bus = mdiobus_alloc(); if (!cb->mii_bus) { ret_val = -ENOMEM; - devm_kfree(dev, cb); - continue; + goto err_loop; } cb->mii_bus->priv = cb; @@ -182,6 +192,10 @@ int mdio_mux_init(struct device *dev, dev_err(dev, "Error: No acceptable child buses found\n"); devm_kfree(dev, pb); + +err_loop: + mdio_mux_uninit_children(pb); + of_node_put(child_bus_node); err_pb_kz: put_device(&parent_bus->dev); err_parent_bus: @@ -193,14 +207,8 @@ EXPORT_SYMBOL_GPL(mdio_mux_init); void mdio_mux_uninit(void *mux_handle) { struct mdio_mux_parent_bus *pb = mux_handle; - struct mdio_mux_child_bus *cb = pb->children; - - while (cb) { - mdiobus_unregister(cb->mii_bus); - mdiobus_free(cb->mii_bus); - cb = cb->next; - } + mdio_mux_uninit_children(pb); put_device(&pb->mii_bus->dev); } EXPORT_SYMBOL_GPL(mdio_mux_uninit); -- 2.30.2