From patchwork Mon Sep 30 20:03:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13816981 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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 33FC71A0BDA; Mon, 30 Sep 2024 20:03:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727726620; cv=none; b=CeWalPZ4lQktRD5xgSmeub+dEEA/hR4kZvjO2ArHS/DRb510kQBfOfteYjXnbN6fW7psDweVAM7hlpEVRchnsEbz/UBEAsHpAmL/upRU+I39FqQI3BvlLDC6chwzxHcujhN/Q/E8ecrUrm5Vcqx9Kej2gTd5pp0RTfpCsVs52YI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727726620; c=relaxed/simple; bh=SdWNxiW1a33gv3dEjg3cIUhOf0p4uT9vq1QQloiGxG8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mQLNu/qLUh5Pw+mwNvRvIfRsjzqw3+XcgXdRxh5HgZqs3HDPyr2Ut3Uai46DteJWbfIt+5xImt4bWxags+qv7geMpvpevVAJ+VRq6/0rCrT0Wda82vXbR8xwma2tbkgh52KUI1TLgq11sJXOPU3kc2Pt2/ZC2Rx3EtM48hRxpv4= 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=V6ZVEI2n; arc=none smtp.client-ip=209.85.128.49 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="V6ZVEI2n" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-42cd74c0d16so44068855e9.1; Mon, 30 Sep 2024 13:03:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727726617; x=1728331417; 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=V6ZVEI2nw8xB0EnEbBEmUP6irDwJdW70k5sjzzlqhwFDcZnbcK7vn46zBI1GCfL16H 28m+Cxa+/UVX3K/x8UgH+Bz51+3PRmTUN/zW7cBICPqwYv4LGKepS/s8RGc7wRIBgy29 E9Sdbd1Vw/SChhw6Hl3R8F33Cn0gLC34xksyiqkTO2Yfw04teUjoXTJhvS9SCwANI225 CBjHjLoOWZO1WBKw90DBuVj3MIleXHbLcqax1ZzIcTY/5KAXdNT+36HFMKkhmpkWskax E92Ckxx0T+FUFwQ28PzsAcnTjiEy0aP5t9dubsVQIiXG+FcXLgIymCttio1sgwy5KX0O q45Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727726617; x=1728331417; 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=Ikdyxv2BE16znmp/Y1LAlpBmvTqDkIKDEP3zbnJixnESdaimGEBB3a0grVQbN46QMV ZPkHbwy4eZFz7hOTMF8YPNtSlwFKHurAG2E3TsHhvxoQnfV8Z3xou2MxsijERDXjT/ij MGvKUDDFK0EizC4ikWUTaxX9hA0efQCHq3c3Av3Odm1AqEwjsppnhEdGvJUwT9Ve8wCm rv35WN7lDRjACWwO85oIDTZzqqfoPbzrtAe0X+eBxD/unA71Nie0NG+UF/kgpZ46ea2N T6JeKRFZ+0uqxC8X8wn1/4BqKfF2MXlhb+3GClS2rjFfdYXzxXSAmBqy1lZP5+d/5Vt0 yvJA== X-Forwarded-Encrypted: i=1; AJvYcCVXxUHNjSOPLvxGroU3Ex7ndCPFT1HtYFUJL2LR7lLEzyCao4hlrT9oHCriVXnzuI0Oj3HFXsmOy3U9tes=@vger.kernel.org X-Gm-Message-State: AOJu0YyHHp6/Cqjnq31pr7pOdb/hpio9H6bEjH7PNgs+dt/43KWeCCuz OjArV1Zi0tL9UOR+ZnEuqYaj+Zkye589MBYYpWxxLvaC8ELSqZNv X-Google-Smtp-Source: AGHT+IHyDpJZAsP9L4afD9qdQC5EpU03DAwOfUju88L+kABFeUBfItj9Qxuyx1WNxS38Wg1b1ZZdGg== X-Received: by 2002:a05:600c:1da6:b0:42c:b187:bde9 with SMTP id 5b1f17b1804b1-42f584a2dd7mr102005795e9.30.1727726616787; Mon, 30 Sep 2024 13:03: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 5b1f17b1804b1-42e96a36760sm162591215e9.30.2024.09.30.13.03.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 13:03:35 -0700 (PDT) From: Javier Carrasco Date: Mon, 30 Sep 2024 22:03:29 +0200 Subject: [PATCH 1/2] net: mdio: switch to scoped device_for_each_child_node() Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240930-net-device_for_each_child_node_scoped-v1-1-bbdd7f9fd649@gmail.com> References: <20240930-net-device_for_each_child_node_scoped-v1-0-bbdd7f9fd649@gmail.com> In-Reply-To: <20240930-net-device_for_each_child_node_scoped-v1-0-bbdd7f9fd649@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=1727726610; l=1729; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=SdWNxiW1a33gv3dEjg3cIUhOf0p4uT9vq1QQloiGxG8=; b=W31MMQTY6MhpSYx2RAf8Jy6ryidrYwcEeuouGExz1hyC5q7/EXiDbtqar3cBPj5VusubJkyiD 7bvWP8CRkZsDdbP7CLklvOL67/k1J8QRg9BPSzyic9DWxZhZ6g8uQsH X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= X-Patchwork-Delegate: kuba@kernel.org 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-thunder.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, } i = 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 *pdev, if (i >= ARRAY_SIZE(nexus->buses)) break; } - fwnode_handle_put(fwn); return 0; err_release_regions: From patchwork Mon Sep 30 20:03:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13816982 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (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 37D531A2541; Mon, 30 Sep 2024 20:03:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727726622; cv=none; b=mdSyP2B85M13+nE3v8VYw3w9hp18HrDH5HMeRtLkMNVNtgSEzmBiiR0Otg8usJ1iNpeGG6lkWvGdq4AB4SnpT0ZT5PQ+GVXT5qB8/fvRHMLH2jcPK9VIqP/xYGHseqg3K8JsMf/NZbf3Rur9AAyYgSjZ6LugZ95B9OuYkrGhHjA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727726622; c=relaxed/simple; bh=lhqM/tDLilNDAvkZ6CHklg9+gI1AjLbN06Lfvf4DrMk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dTeWEn9ge2YJFRR8uFCi9dP51YYQwsFJAFW4xI2wjix/qIVli+iQoE4YJUQtzMAGqQDoNmH8taph9Qj1g7+Xx7DPo+T/QeF2s/isz6DRy/5Plq/GVYpZ4vfFjuDks9SNAgXXszHXQHdkffmMiPB61jxvAk6EbKbLqFnWKGBeXm0= 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=h5vLZMUC; arc=none smtp.client-ip=209.85.128.43 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="h5vLZMUC" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-42cae4eb026so46087025e9.0; Mon, 30 Sep 2024 13:03:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727726619; x=1728331419; 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=h5vLZMUC+WmrSOn86mSr74dz42o+tSBxTPswz+9O+XOLFRIRxGoAKdV1lsb4Ss7PBD sDhiS1l8U8+1OssknTuFDoGfTKdtA2XJZOhXUvrhvNSYmRhG1TA3+RnzRQUPbvgZ1sfc AogVHo0bgRn5MT/SgQCVZ24VIKi7LZmq04BfZJ0LCfon8NFSO2ifK9PWT0Q36nL372bR RYV3VvZgrc+3j+YBQikfmq7ujDfpRvUFia1p1jdXOi5grw8Xjou328S7Mj3nDXcQ9Rj1 +SWmFPgKgyotvVQ2284/h+Vz8Tj0/QcKUHYG4nkntQeeZGMoM5NlQ8leJrkE/CAESlBy a9Cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727726619; x=1728331419; 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=WBHzpRx09FvTpKam3vRzd5THb7pL2OeyCksiLdc/SN4u9QLjp0IlbUu5y0EQocLXsv v4P7BIM/Q6HvMr+EaAjXG938GG5o4qTVxnM0TU9K1oSSPfX5d8WaWcIOanYOUDfdvRq5 EPyaHlKNqfyVOgqzfnTFVN0ygoO275Wz2Fme7aIff2hX/EDFlfYLsI6DGg+46N+EwxRp ciTz7tEgGpXVR5srglVI6CJYhX2vRCcz+zkoQ9m8diK3h6lY3waJ0SmcrjmxOGp2Ex1c Y88fUoLBRd9xK4JPqrcBbEKatW7ctTBhBXbUybiNOJxftCZowe+a5yjILZWo+FDyfO0+ YeVg== X-Forwarded-Encrypted: i=1; AJvYcCWEbTo4EAqXmtsnZc+fKzs+7CNJjzRVevKfi52qJ+XYX/SmaQW7k1VPRr6vukW8KQkKuWX9cxaxjY6jgws=@vger.kernel.org X-Gm-Message-State: AOJu0Yx2e38DxUB27e/a4Gm1pEW4+c71l9/pBmuA9ZLCt2NWT9KMx52B T/dub5E1ALg5NSj3Jg1ZVB29D3htyYePYyWnbJj2RYF82BRoAruj X-Google-Smtp-Source: AGHT+IEqUNBMAM3S1zFrByHB/nKIWJkUcqU5zIeZF7O146DmV4ScmkcieTQGp1+z4zKu48Fsgo7Inw== X-Received: by 2002:a05:600c:45ce:b0:42e:d4a2:ce67 with SMTP id 5b1f17b1804b1-42f5844ab22mr99664855e9.17.1727726619321; Mon, 30 Sep 2024 13:03:39 -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 5b1f17b1804b1-42e96a36760sm162591215e9.30.2024.09.30.13.03.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 13:03:37 -0700 (PDT) From: Javier Carrasco Date: Mon, 30 Sep 2024 22:03:30 +0200 Subject: [PATCH 2/2] net: hns: switch to scoped device_for_each_child_node() Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240930-net-device_for_each_child_node_scoped-v1-2-bbdd7f9fd649@gmail.com> References: <20240930-net-device_for_each_child_node_scoped-v1-0-bbdd7f9fd649@gmail.com> In-Reply-To: <20240930-net-device_for_each_child_node_scoped-v1-0-bbdd7f9fd649@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=1727726610; l=1663; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=lhqM/tDLilNDAvkZ6CHklg9+gI1AjLbN06Lfvf4DrMk=; b=XK7yYIBeqRmZgZ24U7zhUudEoYaOhqyYZ/954XABAmgrtJE0aSA9NZu5MXlngRSSOMCalfeXj 76ua2dduXuNCLezFXqOuqykMLSaJGE1wS5fx3F6Sxj/wGpId1E66ne0 X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= X-Patchwork-Delegate: kuba@kernel.org 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/net/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 = hns_mac_get_max_port_num(dsaf_dev); struct hns_mac_cb *mac_cb; - struct fwnode_handle *child; - device_for_each_child_node(dsaf_dev->dev, child) { + device_for_each_child_node_scoped(dsaf_dev->dev, child) { ret = fwnode_property_read_u32(child, "reg", &port_id); if (ret) { - fwnode_handle_put(child); dev_err(dsaf_dev->dev, "get reg fail, ret=%d!\n", ret); return ret; } if (port_id >= max_port_num) { - fwnode_handle_put(child); dev_err(dsaf_dev->dev, "reg(%u) out of range!\n", port_id); return -EINVAL; } mac_cb = 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 = child; mac_cb->mac_id = (u8)port_id; dsaf_dev->mac_cb[port_id] = mac_cb;