From nobody Thu Nov 28 15:35:59 2024 Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ADE4417332B; Mon, 30 Sep 2024 20:38:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727728720; cv=none; b=bqH+4XokN8Qcq4Zr5b0LK0QryqQbhzrKDzQ4i1OypUamly850BNrK1TRDKA4OAphBgzhWb6VlCh5CF28VqsxPob2MV5lgawwthK6VSiVbT3oXlOSe6RBudP93atk8Ge/AROSNLFoWiIyscvr7P2RE2IWjTIRlApKRxyuoq+r8j8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727728720; c=relaxed/simple; bh=SdWNxiW1a33gv3dEjg3cIUhOf0p4uT9vq1QQloiGxG8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=OWTqOZoqYBo4L3eDmcY6X+N+X4qwQfc5+9y6piREU1h+7p4wu4MrGl1Fsnb94PMyQZJz/kNFzwcEwyH4wU5X/1/KuU5x/wOyCJfbPRMLe+EM4oToxSiO6SKVkuNBxpkDCXGMr/U2CHeh9sq6IKHzjjrJQ9vkyodG2DU31x8hWsQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=fgMRwd6n; arc=none smtp.client-ip=209.85.218.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fgMRwd6n" Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-a7aa086b077so708930866b.0; Mon, 30 Sep 2024 13:38:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727728717; x=1728333517; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=9sqtZ/31Yy7RoVK60NTWtW6OUtzrXK53h8wt43cKuCI=; b=fgMRwd6nqyr21nIKVjgZw7TgI2LKTIsvp1SUWTL2uRa+i5wVJChOx8DA4dE6xvV2qa C8oiEqLTkJkXEbP9yiniXz1aKNnYIJ8HvBu6qBgQ2qxWI7RgZss3cjdpXSLMgwfJ+CN1 l4jT234ttJs4iefhOGhUuu3Xe8oRWhSOU+3vZm/FTiD95qc+iYHgHPqTWU1mwXzJHwFq H1kcdl/9itApDjqRqQui9T+Wk3lwE5wBPRAzwAVr9AKfa02G9brJSQ0/GJ6FfN8lWoy+ znSD8GP4IOHgHYCUyR57CtSJwHQDvyahv3E5cEbKaQLw/XbrFGxbGMYUzHqRc93K29wc Kh7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727728717; x=1728333517; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9sqtZ/31Yy7RoVK60NTWtW6OUtzrXK53h8wt43cKuCI=; b=s2YTRWH+g8NOZ88fsc32PePXxF7COwIrJoZwrXCRb0VXF2bpFcQI+sxAPJIYpGf9nq uVUfCApJjKEjfRaXGUzNsxN7c5piEss8NWjmKdzqNUG9HVrbNR3eoXHx8QgH5O+5g1et u6WkT+3t/6UCTkie3j8xdgf90AxH9DviktdjArXrF2NRz3J00F2Ouq0NagAW2d4FhBHL IvpLsDqddU8pwq46YK234j4yAEOwE3aW3FHdNgaysEt+xAQOCjOmAnY1ey/BfmjCJ1/3 6RpMHbAnwnpd41WLzagfIEsW3jOBDjtJp7tlcdkR7xmGALRpSr6s721qQZd0h2Kdai1/ A1vA== X-Forwarded-Encrypted: i=1; AJvYcCXte43i4VQy0MpHMzvr4N5pjdpL+77rntmkY87sd8o4zNqPWHWL8bitWT+AcNKDaBUeOK8ur/FX1Q/Lf84=@vger.kernel.org X-Gm-Message-State: AOJu0YzjqBmEBU7P7LrKzT9NeAKmYamuEnnLMZJqXfY5SedVCWlau4x6 Vo26SEHaABWT8+Yf4758cbbDpLRx3NZwPVUNzP7I0gNw7jM55EWj X-Google-Smtp-Source: AGHT+IEquB9BgPn6UkBLsFnpdYfXV0HugFG/eBiP5JqRfWauAgzX5a+NF1CFFpH6b/LoBa2HU1++nQ== X-Received: by 2002:a17:907:1b20:b0:a91:15ba:7a66 with SMTP id a640c23a62f3a-a93c4a8509emr1610620566b.44.1727728716891; Mon, 30 Sep 2024 13:38:36 -0700 (PDT) Received: from [127.0.1.1] (2a02-8389-41cf-e200-91b0-e3db-0523-0d17.cable.dynamic.v6.surfer.at. [2a02:8389:41cf:e200:91b0:e3db:523:d17]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a93c27c7184sm581377566b.83.2024.09.30.13.38.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 13:38:36 -0700 (PDT) From: Javier Carrasco Date: Mon, 30 Sep 2024 22:38:25 +0200 Subject: [PATCH net-next v2 1/2] net: mdio: thunder: switch to scoped device_for_each_child_node() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240930-net-device_for_each_child_node_scoped-v2-1-35f09333c1d7@gmail.com> References: <20240930-net-device_for_each_child_node_scoped-v2-0-35f09333c1d7@gmail.com> In-Reply-To: <20240930-net-device_for_each_child_node_scoped-v2-0-35f09333c1d7@gmail.com> To: Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Yisen Zhuang , Salil Mehta Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Javier Carrasco X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1727728713; l=1729; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=SdWNxiW1a33gv3dEjg3cIUhOf0p4uT9vq1QQloiGxG8=; b=45LeRA8UfOrDXpe+wp+NdkpEjwZlKJ86yPRj0AEvP0w/PAKOtmgz3UD6Vt/vYL7ycCKjMMoHU Ciu4jOhlSrnCw2EYytKpnuq7NQvaRmcGU57xCu8HfhhZYQBZSNdppT1 X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= There has already been an issue with the handling of early exits from device_for_each_child() in this driver, and it was solved with commit b1de5c78ebe9 ("net: mdio: thunder: Add missing fwnode_handle_put()") by adding a call to fwnode_handle_put() right after the loop. That solution is valid indeed, but if a new error path with a 'return' is added to the loop, this solution will fail. A more secure approach is using the scoped variant of the macro, which automatically decrements the refcount of the child node when it goes out of scope, removing the need for explicit calls to fwnode_handle_put(). Signed-off-by: Javier Carrasco --- drivers/net/mdio/mdio-thunder.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/net/mdio/mdio-thunder.c b/drivers/net/mdio/mdio-thunde= r.c index 6067d96b2b7b..1e1aa72b1eff 100644 --- a/drivers/net/mdio/mdio-thunder.c +++ b/drivers/net/mdio/mdio-thunder.c @@ -23,7 +23,6 @@ static int thunder_mdiobus_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) { struct device_node *node; - struct fwnode_handle *fwn; struct thunder_mdiobus_nexus *nexus; int err; int i; @@ -54,7 +53,7 @@ static int thunder_mdiobus_pci_probe(struct pci_dev *pdev, } =20 i =3D 0; - device_for_each_child_node(&pdev->dev, fwn) { + device_for_each_child_node_scoped(&pdev->dev, fwn) { struct resource r; struct mii_bus *mii_bus; struct cavium_mdiobus *bus; @@ -106,7 +105,6 @@ static int thunder_mdiobus_pci_probe(struct pci_dev *pd= ev, if (i >=3D ARRAY_SIZE(nexus->buses)) break; } - fwnode_handle_put(fwn); return 0; =20 err_release_regions: --=20 2.43.0 From nobody Thu Nov 28 15:35:59 2024 Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com [209.85.208.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5341B1A0BF2; Mon, 30 Sep 2024 20:38:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727728722; cv=none; b=Yu9DGwwPBVtH0dMbpk/ZzoZSpT3wO139ciSIE034M7emdghb7CalOIobVoQhIk5KZypjL4zGmiMdkwupqXC5f3L1kGdhTuvOiGmQ16NYzyramqQ0iLbcD67Y9knU9UdvVk1w85Oks9rAJl6yHxvpbNuJLU3NR/qpkQxmGOCBK6s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727728722; c=relaxed/simple; bh=lhqM/tDLilNDAvkZ6CHklg9+gI1AjLbN06Lfvf4DrMk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=K/vH/MhFgp6dKU7MecpybsID6k8AZmIjbWMd6/MI2RozMSh2/VW/Xr8l9zLGYzsUlXwTT3xTx5d2Sh2ktc8NdjuKISWdhBPl1H3qrJRBajULfyY6Rfw00u+QtAFx6RrOUBKMFFI22yq6Xc4NsxLpAl0bXGS7GLsYEFoRi62jyuY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Oa7ljYPA; arc=none smtp.client-ip=209.85.208.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Oa7ljYPA" Received: by mail-ed1-f45.google.com with SMTP id 4fb4d7f45d1cf-5c876ed9c93so4765417a12.2; Mon, 30 Sep 2024 13:38:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727728719; x=1728333519; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=JWhma+jLayTPmmZHGcFdQytW18t1cDxz6kIrXu2ao2w=; b=Oa7ljYPAYnVRPPsrv1ynkiL5onfm//PmUiK4v4zYlzfqev1HIE/ZmdeH+5BgDF6GzN rJGwlVWp+ZxLTPNGDeAUprEhvA6ij2bcroojXzWaIRCZ+7AtySNG47Kf7Qr4v3K3n93H bzBFi839uu3xQHU27/LgOudr7ResrlB8J7pjFNbYFqpZRrEMCJ/+OkbzgzORX/L93czk aP/vXQ6ZCVG7nOyFSrv8LmIuWnG8aA9UeiauRoGNCFI8PMne10ZKQOE0yaQXCc2zYked 6E+R2B4nxbvIcpJyUqLl1nMYLLQj4hyCKjmsqmwpYfFRGli/nFfuRhwFrokaKBoFjkye j7kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727728719; x=1728333519; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JWhma+jLayTPmmZHGcFdQytW18t1cDxz6kIrXu2ao2w=; b=L4Ptmcn9b2DMge5EwxttyRe3uk2DAHY7CHp0RnCyZ+tkegT5vh7ChYWsdWBY3/oRkM NVR/cBn0ItITVcHteTyZ/Cw4WGwCpp8yN86Vm8r+oBhkjnhcrYsACCFyMvRKiT221hLP SCyoTjN2OzRS4h/YwzKkuW4LPP+fx/3E9+7tf0umFEaMOZf91o9IZfXUYMEdF5xgkGVL Wn9T4i46Q78mpLigM/ytM7obtX7XbvVblU2QyfNbtjenMSty72D4s3c40H7R+JT3Jjdq Px+AGkSLbWApMWT03iLHQomn6SdJQVWwDnriCwmlLFRFBa867Cy6qn7irk5fh19etG1K 0qCQ== X-Forwarded-Encrypted: i=1; AJvYcCWAsNF86h/5dxQQLTriTJCdjVzxpfM3f+ufpsGcGrkoiVwvTYHYaGKj9HtUB+we57nr3FmCLIAD3ukOEVk=@vger.kernel.org X-Gm-Message-State: AOJu0YyXG2H/q/ZAv/Wsm4HueUZbzFZEdZ/sTAknQUTJNXYtUskbZcfG zGCRZlNmXcGlLE464Bugf2SvepNeiFp4uItU2BFgQdA/GCtk7iv0 X-Google-Smtp-Source: AGHT+IGop0m+RggjK1JOxzT4f9vzcCe1sZPUOGuzSl8pHEqUbxt0f22lqUcYx5bB2PiZqnyPr+ueFw== X-Received: by 2002:a17:907:3eaa:b0:a8a:9054:8391 with SMTP id a640c23a62f3a-a93c48f8884mr1414236466b.5.1727728718475; Mon, 30 Sep 2024 13:38:38 -0700 (PDT) Received: from [127.0.1.1] (2a02-8389-41cf-e200-91b0-e3db-0523-0d17.cable.dynamic.v6.surfer.at. [2a02:8389:41cf:e200:91b0:e3db:523:d17]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a93c27c7184sm581377566b.83.2024.09.30.13.38.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 13:38:38 -0700 (PDT) From: Javier Carrasco Date: Mon, 30 Sep 2024 22:38:26 +0200 Subject: [PATCH net-next v2 2/2] net: hns: hisilicon: hns_dsaf_mac: switch to scoped device_for_each_child_node() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240930-net-device_for_each_child_node_scoped-v2-2-35f09333c1d7@gmail.com> References: <20240930-net-device_for_each_child_node_scoped-v2-0-35f09333c1d7@gmail.com> In-Reply-To: <20240930-net-device_for_each_child_node_scoped-v2-0-35f09333c1d7@gmail.com> To: Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Yisen Zhuang , Salil Mehta Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Javier Carrasco X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1727728713; l=1663; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=lhqM/tDLilNDAvkZ6CHklg9+gI1AjLbN06Lfvf4DrMk=; b=daRt46UBO70zpJYenBxG6RCxSAqWcHCbVboNXmKJYvZn2ABhVBQriAltnyDCgldASb7Oq0Z+Z JJYhnxX2SUQBCQv+/HkxvkIv4W5lCgRRuXhtkXT4mhq/hiuf6KCXWrg X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= Use device_for_each_child_node_scoped() to simplify the code by removing the need for explicit calls to fwnode_handle_put() in every error path. This approach also accounts for any error path that could be added. Signed-off-by: Javier Carrasco --- drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c b/drivers/ne= t/ethernet/hisilicon/hns/hns_dsaf_mac.c index 58baac7103b3..5fa9b2eeb929 100644 --- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c +++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c @@ -1090,28 +1090,24 @@ int hns_mac_init(struct dsaf_device *dsaf_dev) u32 port_id; int max_port_num =3D hns_mac_get_max_port_num(dsaf_dev); struct hns_mac_cb *mac_cb; - struct fwnode_handle *child; =20 - device_for_each_child_node(dsaf_dev->dev, child) { + device_for_each_child_node_scoped(dsaf_dev->dev, child) { ret =3D fwnode_property_read_u32(child, "reg", &port_id); if (ret) { - fwnode_handle_put(child); dev_err(dsaf_dev->dev, "get reg fail, ret=3D%d!\n", ret); return ret; } if (port_id >=3D max_port_num) { - fwnode_handle_put(child); dev_err(dsaf_dev->dev, "reg(%u) out of range!\n", port_id); return -EINVAL; } mac_cb =3D devm_kzalloc(dsaf_dev->dev, sizeof(*mac_cb), GFP_KERNEL); - if (!mac_cb) { - fwnode_handle_put(child); + if (!mac_cb) return -ENOMEM; - } + mac_cb->fw_port =3D child; mac_cb->mac_id =3D (u8)port_id; dsaf_dev->mac_cb[port_id] =3D mac_cb; --=20 2.43.0