Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2919511pxb; Tue, 24 Aug 2021 10:36:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5EEcNsh6YeUVPsvPBR2xs5Sl7Mqd8Ek3NFa0yQj1CEULnMHM3ud0rFvdaCCEHllW+HU6U X-Received: by 2002:a17:906:f1ca:: with SMTP id gx10mr42478682ejb.387.1629826571342; Tue, 24 Aug 2021 10:36:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629826571; cv=none; d=google.com; s=arc-20160816; b=QG2XM0FNMALUTAvFnyakcAu/pqyO/PFXZ5pxkUeeMfw6M2Efjhh/nWyUP+Ch1BJ05e gAxEpMDvMEb2xD3wSlLNEsA/UG0L6DtxgFMdFiIzazdQcr77LJwbpgn/u7PvdLEHDN3G bdH3Jz74mLcvbPYRWl0xy3VaaWiH7ARfSXwGZIbzg6bqTIyB77Hu9Q7+I7fUrlBcsH7Q gyClU5ZuhX6F/z3WfY43XzhZUOeX89YA68KoHeWKkC8xFWRYD2m1MphNWb9kwyTFMlsi ijRfIZvzRe8ook4Ihw9HUEj3AN5O3jQStacrhqdrFebSTA8Q819mjtFZUR+aj+amB4Yg q2ZA== 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=ebwa6u5hXoyPREzTZLl32g2B+u8fVUVrs3DNHrWE3r0=; b=IAxFqdQZoR1Q0Vm0hIGq3/L7rEEx86EkHnO9HUYr9TfJ7mZTVvgBSzLJD4v8iVNEEy hHnAbAi7XlslBR6KJiQVsgrfo8pgDqlUyLp+X61vxAqNe44/t1x4U6xKvv2qsebAAoRC DpyRcOdcalX3AruejjP5Ua7zWhQS/nbFjApwKPQQ8PubjdtzQZt2YZYiApwyeJzU8M2D uIr3CLMFeezoQIs3jL5yJzNoe0pWqp1G09lNOrwiKw1IQHAuFHeiip+uhD/WNdGDkFos qTcbRAsBCRUsBQ60me50FwLCkCLcKjMm5PGYybttbixIWIjhaCWL4MA/EyOUzbpZkXw8 TISg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UpCp6zbY; 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 bf22si17443249edb.311.2021.08.24.10.35.47; Tue, 24 Aug 2021 10:36:11 -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=UpCp6zbY; 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 S241972AbhHXReV (ORCPT + 99 others); Tue, 24 Aug 2021 13:34:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:39356 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241888AbhHXRbW (ORCPT ); Tue, 24 Aug 2021 13:31:22 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id DCE5F61B7B; Tue, 24 Aug 2021 17:05:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629824750; bh=h+YeNfH66MeNb6WUgwhqBZ4WAHXSEvz0AE0irN4zS/o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UpCp6zbYHIBTAQ59r7yOTU8PenJZo5I9/1tJ7MRk0NUz97iRVqmz27nKtuy47XYd+ Xy0nzLjnZyeOyDlDhq6jBRg2tq4UNAqiHigkRbSE2AAxzhkIM/fht69KyxEJGacW4S j5o5VPtfvHXSDqby+UGavYmByqo+NzorunW+PLLDq+860o/yRIxZN+MBToo1KbB1q2 kR+jQ2UyHnF4quvSzv119v7Gmqaa5hNdHrV1y5Q54HFqAZvEqtWIRlLl3EHWVEb49t 4ZH5Nf0y4xE/TSsGEMhlffZMG2kyhh16lu6plgeWo8ojNb7/r5yBWB+YyKOFFflGkN on9Ox+U+GBkhA== 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 4.14 54/64] net: mdio-mux: Don't ignore memory allocation errors Date: Tue, 24 Aug 2021 13:04:47 -0400 Message-Id: <20210824170457.710623-55-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210824170457.710623-1-sashal@kernel.org> References: <20210824170457.710623-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.14.245-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-4.14.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 4.14.245-rc1 X-KernelTest-Deadline: 2021-08-26T17:04+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 0a86f1e4c02f..bb7e3f12a003 100644 --- a/drivers/net/phy/mdio-mux.c +++ b/drivers/net/phy/mdio-mux.c @@ -85,6 +85,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), @@ -147,7 +158,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; @@ -155,8 +166,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; @@ -185,6 +195,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: @@ -196,14 +210,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