Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2895722pxb; Tue, 24 Aug 2021 10:04:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGdaIjxTwZh/SbockFGXeFd8U5hd1yWxEZVH0+LLOwJtTfHhA8Y1w6HkLvLhmuhPb/6Wci X-Received: by 2002:aa7:d592:: with SMTP id r18mr8833340edq.317.1629824686811; Tue, 24 Aug 2021 10:04:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629824686; cv=none; d=google.com; s=arc-20160816; b=V04EaoNHH+8IfDX8DVCdX8I9UHgoMpO9oxeq+fNvNhz1TZoAM+xm/BG5el38Cn0qds OlaAegIzLj6/1mnz/0BoiRzcXqLzc5Hk+X3DHRIqYFpJhYLkjG3bYhONUun/IfMpofAo aFH+9cKGrNNDAjZanzdk5OxwyvQCxnm7+TyAylBAn/C4398FgCm953tZpw7/Wt+JgeHc W8iqgS6z9CTrZolsaN51MLKzITWs0FvzWD5hTHuXabuw+qCxt/ZB2Jpog8u8nCPJPPpa LMruNa36t96A3Qg4gjBQGouFpIBAHgT3e7BxhHj8UR4YVelqpLvxGkrNAatjJOnv9TMG tshA== 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=wvlDG1jLoD4dxIb91hLoPlitwNiuPeZKHs9qT18pl2Y=; b=FeNZR8SKv4YNDQ0vNWN+uDHkrHCUJSyqxLfoP7GObmoM+uJR9l8jNLdOLWxZ40Mrrx KWhW3yG6B3ExxRmc+eyB4jdKdGTQPFhvtP6DnNG+RMxwPQvP1uzUxT8D1TaxLGcI95Lw SiA8d+mAgnJd0zGGg/Ufw1p8ik5ftKLkntua6T2+885FneBHaACCbfW6i0YN4gy5nb3w zJ1lbKqYaoEMoDJ76Yz/Uw4tizrO9ftvkMBEEil51yXXEk8ny7/LZPldi4Khpq4BcMI7 2QRpOZ+t2H0NN+NsODpA6mXpst5ce3yrxGD+CnoE4v4WTbg7IcD3OvP7QgcAi0bhkdpJ NPcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=T6mw5VUF; 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 h17si12336686edb.246.2021.08.24.10.04.22; Tue, 24 Aug 2021 10:04:46 -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=T6mw5VUF; 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 S230488AbhHXRBO (ORCPT + 99 others); Tue, 24 Aug 2021 13:01:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:39380 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238471AbhHXQ6N (ORCPT ); Tue, 24 Aug 2021 12:58:13 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8FA8B61401; Tue, 24 Aug 2021 16:57:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629824233; bh=M+R0hoakc5y3nPgxpjCuU06fRRtzmObweeNz03A9oaQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T6mw5VUFi9JmOvaTuFrRQutWy8e2+EfNPDWEi4MA17f7zf4PWJte0NzWGj0KYzXUM EKIhTWD/SVAuo1W/Rj63VDnnRrytOqi1aFasFOZTIRSaHU3PYknJe/e85eEA0qjU/0 +zTskB4MWqjZHasbFAh0eOrhr+Aab3zi3BN206eie2x8HjVwRGJzE6+npTS1bZC8im 8vPllrkuRmLSFMKaMKpi990eqF3h672Sx1W7VcGxd3K4qEofSagV0bknXueRMUDw/s XLjZv2vgZkSGKaeIkUkorordDrlKouXszf4T0si+10bs7VE1gxKRdcnFgJbS+AWLR+ 2inLBbnlR3r5A== 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.13 066/127] net: mdio-mux: Don't ignore memory allocation errors Date: Tue, 24 Aug 2021 12:55:06 -0400 Message-Id: <20210824165607.709387-67-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210824165607.709387-1-sashal@kernel.org> References: <20210824165607.709387-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.13.13-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-5.13.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 5.13.13-rc1 X-KernelTest-Deadline: 2021-08-26T16:55+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/mdio/mdio-mux.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/drivers/net/mdio/mdio-mux.c b/drivers/net/mdio/mdio-mux.c index 110e4ee85785..d6ed9033339c 100644 --- a/drivers/net/mdio/mdio-mux.c +++ b/drivers/net/mdio/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