From patchwork Mon Aug 5 14:49:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 817554 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 01A1113BC2F; Mon, 5 Aug 2024 14:50:13 +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=1722869415; cv=none; b=IdPNtiUxue5eB+UZKXv/qai4Njdc8CuHDItxN5jJ2VGtlNWt/VywdvfTekK0d7PXYfCvWlvqdui0ltCbrTseBPzTzJFfo0HjcM1LoZvAQTL2IeaCsZS/MluKK5VVhwKCXDJCXz6bk458iBaiCtVwbYYNcNbZW3OQVonN27mPihk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722869415; c=relaxed/simple; bh=NQLwlzM1GB5s/6zaH5GM8OvbL7Is75uW2H1eYJozVs0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=upPvXPPkb9fgqZmCLjog5gxEmpO1cdTWq3C3STGdC0Tf4t/8NNdhBz1wV4D/6KT27wIP0f+KqHfSGHdWUM/Lz4DlhvN0prKb9/fj+h5Nps70GHo2tzTXB8MXi0N2bU/joUn5N6x23bl4j3TNBz9uwgph3IRpeew1nQEHzRHK8o0= 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=RAigkIgp; 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="RAigkIgp" Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-a7ab63a388bso674774366b.1; Mon, 05 Aug 2024 07:50:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722869412; x=1723474212; 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=y/Pf1euXJ7YiFp6MxoAI1+nAX1xEOLbJWGLNA7qyCg8=; b=RAigkIgpjMpibE7alcLDvb2wEgrQWYkM7fVUPKcCIWHyDyQe3R3v3jK8mX/ZnRQN3A pVD/NzpqTi8FtdCNmVCPbrIxS2yiPNHFUg57kcgiIKVmg24xipTL5177wc5UAepZnwCH 0BVxrYfyARsS2RxtBzJvyVJII+VTibdZ/AeTtat1NC1lplqhW7KxB7kQLTodLVNrsDHw oyWMjfywAUSU2XxKSDtp9UMYZhfDhH6C8GbX/N4n7w+09mU3Ilk8vXWyAV/vaJcCXuUA a/4c9KcInisTb/UTMFxuoFJjdQYnuEuNVRXK2da5Zeo83md0HDcH+cjPgAQkxBngh8Yr V+Ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722869412; x=1723474212; 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=y/Pf1euXJ7YiFp6MxoAI1+nAX1xEOLbJWGLNA7qyCg8=; b=LJEnixIf+GGM9yLPier3c/AvrEx1LJDuie7CKrQOvWrBh/v2OKMqZunNbyDI6N6/vg U+KVDALHNO+ss1ZeOWkXIY7ySAZo7RzPhyXCQy5Du57wax6sTPM1XXNI4pYgYmZMT3ku f4QmtepmNALvRVlrzU41clTqu7qRkj7Tp4VxARCVilG07rmaNkT1ZazPG+DqlP5sIl4F TfCO5flaMY10E7O3pwzddPTY3A2NEZvEiQ2UHp4iohT8QaTGFQHEMPUAWrCjR1g9BGz6 xXJ2W9dCsZlgCFidXI6ejMHXuWgx2dt08X4TJmPcVWS6J5qMDv8FeHfXLVdvXLeQQK0P FX5Q== X-Forwarded-Encrypted: i=1; AJvYcCWIxOMUtzEmTwiy1SqASgxuxKsEtAkxkFzmhuxUbWGxJybXZlKHW6Gf3+CGhkQ04baXkPzcF3Hl2AGuqkT9G9BY8Oz6iA6rLfiagnMixVpMrA30xRU1za5qhcWzWppPbZH3VWWM8io4lWLdNw3TgWHaPQR1Gy+yfutxI7MOtRtH6mtzJbZ1LS6HYOIzUk8lQxib4svrJwLjdR0wMlwy X-Gm-Message-State: AOJu0YzcKCK+WOhQldmydWyrYI5h3gtjIXDtpJvoelGfQ6YQoJn1y3Lk VrWYZEnL0BisCrY9z6U5POKCj0j4PJcla2/46cNTHTLOs7vQZMuED5/amNMn X-Google-Smtp-Source: AGHT+IEDbJou22J+zOGy5K2QFRts0CEmsyS1Phed3skqUDq3b6QGzQ9H+yC1KwjA8cOMqODaEcnWpw== X-Received: by 2002:aa7:c348:0:b0:5a0:f9f7:6565 with SMTP id 4fb4d7f45d1cf-5b7f40a665cmr10356907a12.21.1722869411474; Mon, 05 Aug 2024 07:50:11 -0700 (PDT) Received: from [127.0.1.1] (91-118-163-37.static.upcbusiness.at. [91.118.163.37]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5b83b82f308sm5004088a12.63.2024.08.05.07.50.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Aug 2024 07:50:10 -0700 (PDT) From: Javier Carrasco Date: Mon, 05 Aug 2024 16:49:44 +0200 Subject: [PATCH v3 1/4] device property: document device_for_each_child_node macro Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240805-device_for_each_child_node-available-v3-1-48243a4aa5c0@gmail.com> References: <20240805-device_for_each_child_node-available-v3-0-48243a4aa5c0@gmail.com> In-Reply-To: <20240805-device_for_each_child_node-available-v3-0-48243a4aa5c0@gmail.com> To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Andy Shevchenko , Jonathan Cameron , Rob Herring , Daniel Scally , Heikki Krogerus , Sakari Ailus , Jean Delvare , Guenter Roeck , Pavel Machek , Lee Jones , Marcin Wojtas , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andreas Kemnade Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-leds@vger.kernel.org, netdev@vger.kernel.org, Javier Carrasco , Jonathan Cameron X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1722869407; l=2059; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=NQLwlzM1GB5s/6zaH5GM8OvbL7Is75uW2H1eYJozVs0=; b=YTm+p+yPM/MLAI5/anEJ/hAw9x6NoZ+VGsIgLGhMXe1qq6uOerpMh1f2KzmuT/PZLTjdft3Bb hTnTMXMbJszCyuwaS7Ys+sTk1rdez/275nQfBN9yZpy03dEgRTz8KFS X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= There have been some misconceptions about this macro, which iterates over available child nodes from different backends. As that is not obvious by its name, some users have opted for the `fwnode_for_each_available_child_node()` macro instead. That requires an unnecessary, explicit access to the fwnode member of the device structure. Passing the device to `device_for_each_child_node()` is shorter, reflects more clearly the nature of the child nodes, and renders the same result. In general, `fwnode_for_each_available_child_node()` should be used whenever the parent node of the children to iterate over is a firmware node, and not the device itself. Document the `device_for_each_child node(dev, child)` macro to clarify its functionality. Suggested-by: Jonathan Cameron Reviewed-by: Jonathan Cameron Signed-off-by: Javier Carrasco --- include/linux/property.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/linux/property.h b/include/linux/property.h index 61fc20e5f81f..da8f1208de38 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -171,6 +171,16 @@ struct fwnode_handle *fwnode_get_next_available_child_node( struct fwnode_handle *device_get_next_child_node(const struct device *dev, struct fwnode_handle *child); +/** + * device_for_each_child_node - iterate over available child nodes of a device + * @dev: Pointer to the struct device + * @child: Pointer to an available child node in each loop iteration + * + * Unavailable nodes are skipped i.e. this macro is implicitly _available_. + * The reference to the child node must be dropped on early exits. + * See fwnode_handle_put(). + * For a scoped version of this macro, use device_for_each_child_node_scoped(). + */ #define device_for_each_child_node(dev, child) \ for (child = device_get_next_child_node(dev, NULL); child; \ child = device_get_next_child_node(dev, child)) From patchwork Mon Aug 5 14:49:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 816892 Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) (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 632DA14AD0C; Mon, 5 Aug 2024 14:50:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722869417; cv=none; b=S8fz6XMQQPNVyLImPbrmdvgLtjJTEeTHwPLSqUfQ8slDvm1zqCYDSQo9CiWsAGiA+MUmzaOv/ah4a9UEFN4hdO9p1SKOahBXIEaj/sAprdkSn5xwHr1ljVB5DOnwa2GJ/o14NnLoKLt85PBxb7YEYDn6cwZZIKSWoG0LOWuqGHA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722869417; c=relaxed/simple; bh=7kg2DOJCEtgdPsOeKLV9ms+2/ZVz5OINInC7YD7FABM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XsZjHRHlZ4ps/IHZbVVgnxiWCSc2OQctIS+QE2D58240zuLEMPhDL2DI3ATQjdWPPapSjOPyT8Sy9nAozbsLAXalgyF8tWYnjRCnKAoe5N2ShZIdtQ1LoITA5Y27G4aASyjpWr3LGrHAhsV9MBHyXAbMrSnRbXgfnGn7dIyHbQ4= 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=OjZfb6Wc; arc=none smtp.client-ip=209.85.208.41 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="OjZfb6Wc" Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-5b8c2a611adso3413870a12.1; Mon, 05 Aug 2024 07:50:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722869413; x=1723474213; 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=y4WMWgX9rgsbhmTu7vAUUT2lJjgAav7/XXIZkFnGczE=; b=OjZfb6Wcy7+jzdowXqxK3wGLaRLoOHyr/qeZ7jwJMYiFkL8q7U2/Wm6ZmK7ut1r871 i3/nx3Umghxsv/8WPC+YfZQGlDfatoTr25rubsNGzExXHciPwB/Xon+GogjDlW/Dsrnk kPpiNdr82JiCiRWzKID6qbYavwDqvZNozbYwnALtEpiDNu25DMkCPKSklx6GEUmBQRCN 0f2zvXAUeh2ArEEoME9t0eHoxrBmvTzlyhObypJi5csxi31ZT/LV1Rj5Fe4uvGpJ6rjX lqZKTYAkR1vbdwOZOqvJCqzwAIJvskYAu4hdUtvKLRZ0NQup40HXmM78x/cMcFW3nUEb ncbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722869413; x=1723474213; 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=y4WMWgX9rgsbhmTu7vAUUT2lJjgAav7/XXIZkFnGczE=; b=vJ8KbDvJipvRM6ujsL4dXgUfVFBnaDn7brZKlbL+HqhGi7g4+vi3fSMZT1FRNJ1qxD FH4QaPPJB9mRT4CvEZargi4TNr4wuEOaxQFW1cCdnchiaVAHwlmLBAll5Rsf1iOrTBlr cH0n0gNAHl3OT3m4PTtKO0apJHYI2bdlk5dcvldMBC6pysByGBlHM5z96YlbRv8jPxOr x9TWAaD9DU68zW3frEK+J01RnfM0Qa0lJXLeOR1Xg8LIo9yzqkV/oCkCKgtQCTvxgGOD FX+QwPNNnKNqfYgXkf7nuvbbiQZRI7WwlEaPrWqs4v3V/kr/tTSoHMEV2mVOKieToJbu jarQ== X-Forwarded-Encrypted: i=1; AJvYcCXtkT3H1VXkzFeLl0ieYWpJFxEBMIJuxoS6ndKcQoMlUrn1yg1xZ2C4Lmu4LPc4ghOreIDhhwks7W4CfsmgmYLmfEsS0dQYR0ZJ464v8PHvhagb1fTiCqHTCYvKrA9AY3TmpVxW7XGsL67L4h4iLlBWVxtXbJPqVUhxGXviIox+SNy2BMm/rQHFDzkws2iSTzeO6H+Xwvqdn4Nw0tF6 X-Gm-Message-State: AOJu0Ywiw9FJc7a/w/utH4rpsRVD/FqSXwGSWPemb/DeTkUT6IQzoiib +0vpeaFl591d6HQwpcFjCdZ7nVF5bAvAuzprOIG700FTi55mcpcg9sap29ZM X-Google-Smtp-Source: AGHT+IGdfYnO2aZpNz0tetKDt/ok3aBPmZNSfSIcOBMQclRRV+msC+93vgDlMfbq4Wu8iCRcKiTLBw== X-Received: by 2002:a05:6402:3588:b0:5bb:8e11:f688 with SMTP id 4fb4d7f45d1cf-5bb8e11f82emr2427451a12.10.1722869413229; Mon, 05 Aug 2024 07:50:13 -0700 (PDT) Received: from [127.0.1.1] (91-118-163-37.static.upcbusiness.at. [91.118.163.37]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5b83b82f308sm5004088a12.63.2024.08.05.07.50.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Aug 2024 07:50:12 -0700 (PDT) From: Javier Carrasco Date: Mon, 05 Aug 2024 16:49:45 +0200 Subject: [PATCH v3 2/4] leds: pca995x: use device_for_each_child_node() to access device child nodes Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240805-device_for_each_child_node-available-v3-2-48243a4aa5c0@gmail.com> References: <20240805-device_for_each_child_node-available-v3-0-48243a4aa5c0@gmail.com> In-Reply-To: <20240805-device_for_each_child_node-available-v3-0-48243a4aa5c0@gmail.com> To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Andy Shevchenko , Jonathan Cameron , Rob Herring , Daniel Scally , Heikki Krogerus , Sakari Ailus , Jean Delvare , Guenter Roeck , Pavel Machek , Lee Jones , Marcin Wojtas , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andreas Kemnade Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-leds@vger.kernel.org, netdev@vger.kernel.org, Javier Carrasco , Jonathan Cameron X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1722869407; l=2071; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=7kg2DOJCEtgdPsOeKLV9ms+2/ZVz5OINInC7YD7FABM=; b=q5g6nykQ9OaDuAHv+zzIBfQXn8CygcT99X05g7rWy9/EpjkKbyLBSp7nJFERHp6rR3EtacTMH z8x4MVdmX6ABlGoPSEQDPikyNvrFcUxmYotzJ9Wy3xm20DRxXgIrk0z X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= The iterated nodes are direct children of the device node, and the `device_for_each_child_node()` macro accounts for child node availability. `fwnode_for_each_available_child_node()` is meant to access the child nodes of an fwnode, and therefore not direct child nodes of the device node. Use `device_for_each_child_node()` to indicate device's direct child nodes. Reviewed-by: Jonathan Cameron Signed-off-by: Javier Carrasco --- drivers/leds/leds-pca995x.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/drivers/leds/leds-pca995x.c b/drivers/leds/leds-pca995x.c index 686b77772cce..83bc9669544c 100644 --- a/drivers/leds/leds-pca995x.c +++ b/drivers/leds/leds-pca995x.c @@ -120,7 +120,7 @@ static const struct regmap_config pca995x_regmap = { static int pca995x_probe(struct i2c_client *client) { struct fwnode_handle *led_fwnodes[PCA995X_MAX_OUTPUTS] = { 0 }; - struct fwnode_handle *np, *child; + struct fwnode_handle *child; struct device *dev = &client->dev; const struct pca995x_chipdef *chipdef; struct pca995x_chip *chip; @@ -129,8 +129,7 @@ static int pca995x_probe(struct i2c_client *client) chipdef = device_get_match_data(&client->dev); - np = dev_fwnode(dev); - if (!np) + if (!dev_fwnode(dev)) return -ENODEV; chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); @@ -144,17 +143,13 @@ static int pca995x_probe(struct i2c_client *client) i2c_set_clientdata(client, chip); - fwnode_for_each_available_child_node(np, child) { + device_for_each_child_node(dev, child) { ret = fwnode_property_read_u32(child, "reg", ®); - if (ret) { - fwnode_handle_put(child); + if (ret) return ret; - } - if (reg < 0 || reg >= PCA995X_MAX_OUTPUTS || led_fwnodes[reg]) { - fwnode_handle_put(child); + if (reg < 0 || reg >= PCA995X_MAX_OUTPUTS || led_fwnodes[reg]) return -EINVAL; - } led = &chip->leds[reg]; led_fwnodes[reg] = child; From patchwork Mon Aug 5 14:49:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 817553 Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (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 B20BB15B104; Mon, 5 Aug 2024 14:50:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722869419; cv=none; b=hhd/MeRV4OoJU/lLf/OuZLDWoqbLgn3W2r9VfFXdJkQysQOL/NcLr8ofrmKVX3hmDPsgMgX1OL7edKlCH1r5tDh6Ewqyb9efLFMntI8hz8mx8ZFgDag/kXFbaN9oXdse5rSUEJ4qk5FURWNICZv6R8ovu6hsYRAtHRGx2joOCgw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722869419; c=relaxed/simple; bh=TXubFA9EPG3koYRbq3Z+pWro6cSdZQFPedoTNgHKsIQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=aBfGW3aPDQWkQCSVpjMIaMOVW0pyqu8E1Kej/leBoNuH/dEvKaeVk10KIFvLLSLN7LhIV+5OYzpoBVaL5EUrmgFHTTj17QDQyP7+92g+TnItYoefXgf9BeuCf5zPVvZaMvmSEJszAkFpFxs9b0R+h54os9GhKF/RHe3MR2A5VOQ= 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=CA2z+YSK; arc=none smtp.client-ip=209.85.167.48 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="CA2z+YSK" Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-52efd530a4eso16375425e87.0; Mon, 05 Aug 2024 07:50:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722869415; x=1723474215; 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=tPSBgbm3jpAmX4JgIT8jji/q0J8YfDHNM8+2dXWfMBo=; b=CA2z+YSK4I89eqiCNkzhQfrRuiTWaDixk9wsdftZW6rxwvYK16jauDpclOJa3fY/E+ S1ujTgLyiPl8jl5yUVn7PK0oH+/gT8z2a1qXZiIp6dJAKYiXwkA1M9Q91lihCsWCmnKn KE75xb3E4YqVwvFw6NypkDjjNdKhV0ig5WUwZfYW6AFj9wSkb6rcruTVye02q/WTM8GK MKVKxsNoti1bjoet+7CSYLX2dOk22vIKzCYBHDeTGQGuC+HjcDq7VDMGNehBaNe2bBxO qfV76KQLX8ikGgmwVdOnIF/OpVlkKZxSCjTG/Us/yMl4uu5BegDrz70yx5CHxbxaDTxO E4Bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722869415; x=1723474215; 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=tPSBgbm3jpAmX4JgIT8jji/q0J8YfDHNM8+2dXWfMBo=; b=W2IBthzwbG7KryPij5PrWO8rX9fi5EQoX4M7nwK+Sau6bvABu/VHLD1VWsDQCiFf5x pVkxRk/sFW5f3NL89O5k+9FBi1juqO4p4tSgWMaoqsIOUGK/14svx8JfL+ZN4Xsd5VT+ J9DRIAdV+bBNqRik/f2ytrOszNMo+QjWd1S8/pDVMAXHdycpcgapgWQaaX8gbnV75WJR kf3iZo7UOrs+sU4CvNfUM2rFCEI5JSltXQJk4RXpS1iOPH52sPySxSxWg9VhqCRPGg5q TxH/01pGYouSlCDbQwdM1APEfCXHZQXqCOpUPLCbCXm4B73CyKSOEMNR9mkM4OWyryD0 vA9A== X-Forwarded-Encrypted: i=1; AJvYcCVmMRmU+zlq7mKKvJMOsAwE1AP24co36Ly9+/u6cvYETXhK9PoczsSgO2jOusTxU4ZmBjyf/ETpom8999SppVJY92uor3PnJD+uwRI8KXsn6IweVKfMIpDZbhTrC8t6d2w6QHSNb+m1F0Z+O2xMzwYvlGgjatQoeQALajvZsrkBZT7PW6QuTTozNawvPy3iDh3WBOnpAOQBY/8c0DrE X-Gm-Message-State: AOJu0Yxl7ol6astPjhS47r+ihErpYB2ks2IfH59RIEDd8WZeNXW3FvDv bwCv7khvE+BJ2CwKZjKShnP07Q0O9j+0+UU5Sc2cMiO8rn66YZVpNDV8Qfwp X-Google-Smtp-Source: AGHT+IHGH9JX2RR9KngT55yV5101rsh+ddZ2QIAfLNa3pkQMsbItoMIF1Z9NpTiCFZd1aGc4XVB13w== X-Received: by 2002:a05:6512:3da8:b0:52f:413:7e8c with SMTP id 2adb3069b0e04-530bb373e93mr8499417e87.14.1722869414972; Mon, 05 Aug 2024 07:50:14 -0700 (PDT) Received: from [127.0.1.1] (91-118-163-37.static.upcbusiness.at. [91.118.163.37]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5b83b82f308sm5004088a12.63.2024.08.05.07.50.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Aug 2024 07:50:14 -0700 (PDT) From: Javier Carrasco Date: Mon, 05 Aug 2024 16:49:46 +0200 Subject: [PATCH v3 3/4] net: mvpp2: use port_count to remove ports Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240805-device_for_each_child_node-available-v3-3-48243a4aa5c0@gmail.com> References: <20240805-device_for_each_child_node-available-v3-0-48243a4aa5c0@gmail.com> In-Reply-To: <20240805-device_for_each_child_node-available-v3-0-48243a4aa5c0@gmail.com> To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Andy Shevchenko , Jonathan Cameron , Rob Herring , Daniel Scally , Heikki Krogerus , Sakari Ailus , Jean Delvare , Guenter Roeck , Pavel Machek , Lee Jones , Marcin Wojtas , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andreas Kemnade Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-leds@vger.kernel.org, netdev@vger.kernel.org, Javier Carrasco X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1722869407; l=2455; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=TXubFA9EPG3koYRbq3Z+pWro6cSdZQFPedoTNgHKsIQ=; b=c3q9MLjk2l9gK8uPqdN47FDouKz245XtE1QkVU7bUIc10J/nfciAxZqoXVodF6xXJEOSjulxq xtZ/XGFpzl+DGZXFlKVUC6pT7IDt5SrTEbcYqoZjzPieWoKRY9wluuG X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= As discussed in [1], there is no need to iterate over child nodes to remove the list of ports. Instead, a loop up to `port_count` ports can be used, and is in fact more reliable in case the child node availability changes. The suggested approach removes the need for the `fwnode` and `port_fwnode` variables in mvpp2_remove() as well. Link: https://lore.kernel.org/all/ZqdRgDkK1PzoI2Pf@shell.armlinux.org.uk/ [1] Suggested-by: Russell King Signed-off-by: Javier Carrasco --- drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c index 0d62a33afa80..0b5b2425de12 100644 --- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c @@ -7655,12 +7655,8 @@ static int mvpp2_probe(struct platform_device *pdev) err_port_probe: fwnode_handle_put(port_fwnode); - i = 0; - fwnode_for_each_available_child_node(fwnode, port_fwnode) { - if (priv->port_list[i]) - mvpp2_port_remove(priv->port_list[i]); - i++; - } + for (i = 0; i < priv->port_count; i++) + mvpp2_port_remove(priv->port_list[i]); err_axi_clk: clk_disable_unprepare(priv->axi_clk); err_mg_core_clk: @@ -7677,18 +7673,13 @@ static int mvpp2_probe(struct platform_device *pdev) static void mvpp2_remove(struct platform_device *pdev) { struct mvpp2 *priv = platform_get_drvdata(pdev); - struct fwnode_handle *fwnode = pdev->dev.fwnode; - int i = 0, poolnum = MVPP2_BM_POOLS_NUM; - struct fwnode_handle *port_fwnode; + int i, poolnum = MVPP2_BM_POOLS_NUM; mvpp2_dbgfs_cleanup(priv); - fwnode_for_each_available_child_node(fwnode, port_fwnode) { - if (priv->port_list[i]) { - mutex_destroy(&priv->port_list[i]->gather_stats_lock); - mvpp2_port_remove(priv->port_list[i]); - } - i++; + for (i = 0; i < priv->port_count; i++) { + mutex_destroy(&priv->port_list[i]->gather_stats_lock); + mvpp2_port_remove(priv->port_list[i]); } destroy_workqueue(priv->stats_queue); @@ -7711,7 +7702,7 @@ static void mvpp2_remove(struct platform_device *pdev) aggr_txq->descs_dma); } - if (is_acpi_node(port_fwnode)) + if (!dev_of_node(&pdev->dev)) return; clk_disable_unprepare(priv->axi_clk); From patchwork Mon Aug 5 14:49:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 816891 Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) (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 4C40D15B153; Mon, 5 Aug 2024 14:50:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722869421; cv=none; b=GMGbLCVaYJ9dukx5HT3nhxVB/l4CLugeNjCiLJ8ZGFr1QAFpUX+RnP680vc+GJm/vQPMAYW4eQPPx76QWC5iTiv1yQHKVKd+G74A6PN9MbZDSOGXanhMNCiWd0Y+nRoSZaHzRtB5E/CAfXnGUPO2Vo5bmGAueVjrHCB1S2ieNDQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722869421; c=relaxed/simple; bh=Gs9fUy9yW4JBBaoGjjHZoItLt9sngv838Y8XASfxmd0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PfPGelbSkakV0eQAzZ1Kz2FWhBfB/dh7stMGqUZ5qnFsqN1Tc63qOHuIybq1imVJaxNz3VqfpihcBDCazay2FC5nqXxXs1w5BONSvIpDoFko2PHJjf2HCV7ZXDSYnzKBT03QvNA3kL1QiG6R9zLzqNe3T3tkEHRiDUI3hTv6nSM= 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=a4ufaUuX; arc=none smtp.client-ip=209.85.208.41 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="a4ufaUuX" Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-5b8c2a611adso3413983a12.1; Mon, 05 Aug 2024 07:50:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722869417; x=1723474217; 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=ni7itzdtEe2jfSTKg6OGqBXNu0xuqssIDqqXlEDVBsA=; b=a4ufaUuX/pM/iqtA6lccvy3jXjNL1tyC/LEcrkqBHJ7Wmi2o4/+N2RP4YoQpSKztHr 4rigSN0vt89qJyA/MAOrUuI+cvtmsIJlB2Ti2uzZgkWWR5w+fW7LhTSkXK56gMvxbu2U OvJ5l/cp/3cgaLeBOEnHywva7aI1tFOfA58K69w4XzETNAg1Hh+hwbfEND6OtvdpTRNu QPB+7oAjyR/a/h0NLoDVEEo5AkImvGAiNyReLA5RKIHTnGZeyAAfmsn0TUb6096HuA1k +7mkME2bBBjlrTIQmjofayPRAMhVSAkDGXlgPoEWK5tSYqy/XgJXzJ7bUWwyWBnHuf8J Nqag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722869417; x=1723474217; 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=ni7itzdtEe2jfSTKg6OGqBXNu0xuqssIDqqXlEDVBsA=; b=ovNEqOASOtivpjQRbw1ySD9+VtUq2eisJZc1eTS8RXCMlSQalY2atqJUGUWMh6FqSb iud9rsXuR+Uf+qH9jaHT4rKpoYuO9lLK6GOWgCRkEKeTURIkoFo5GCBdirtx73VQgVec lI2xWklSz4ujB9RgKK2nWJfcAkrQOuH8kMruN/Ng0qbAWRHIbZ1isGbK1kOJ27hvRgrJ wejomZzSKwLURYVjsQag97/1OI+6YQ7ykGMvx65ggsSGq9BMNfCYpFGC1jcGnCKUXRvP 4HAvtOIZqYw3NKAKLcbC20k4DifwyHLYAKnmrBrGZnveSBCCCpNlUIHu8SAAzYpIpDvi AFqg== X-Forwarded-Encrypted: i=1; AJvYcCUfR/wJ/a+0TaD1Zta2qvB/QSnCEKIWThi0lbHFN3D8d7hvoUaOnf+dzNz4jM227xNn5D//3aVjdFEehQ==@vger.kernel.org, AJvYcCVH1jb5DLipSGrUGX1e3wcGJ6Om2M1ffGq7A6SjFHTD2fZFE8FLYoj7mHEM81bnkWkFAl3PoALI@vger.kernel.org, AJvYcCWtsFdWjuI+r5VoHkFMeSxv2kkO8nxPWjzt6E2mO5MWQfhIQZOjMkAZwVhWrmJ/Ue8vy+jey7b0wBl5eQ==@vger.kernel.org, AJvYcCXZCKIcfE9sYNYYpRA269ttkyB68sJcOoAcsGGPkmK/aO6DSmaL3cQJ6qC3KS2GbSLylFhwTnk6ImHFoV3k@vger.kernel.org X-Gm-Message-State: AOJu0YxhtkiB6rD1e+dR6nYDYar/Q5kzmr5HpnSHcat2rpONPh8LupFj fW2GxuD54Cu7R9sjDNmkMK9lBuuNT09Pd1Yz6CREOPvHf/tuWjfa0bGqud/v X-Google-Smtp-Source: AGHT+IEu7RnD//aEIHLSrf4o/e/BoWMlA3ETDJKKor1UP/ki+rOUQeZH+Has9o+RgFalA/2S8xJoVw== X-Received: by 2002:a50:ee17:0:b0:5a2:a0d9:c1a6 with SMTP id 4fb4d7f45d1cf-5b7f3cc7429mr8033257a12.11.1722869417114; Mon, 05 Aug 2024 07:50:17 -0700 (PDT) Received: from [127.0.1.1] (91-118-163-37.static.upcbusiness.at. [91.118.163.37]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5b83b82f308sm5004088a12.63.2024.08.05.07.50.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Aug 2024 07:50:16 -0700 (PDT) From: Javier Carrasco Date: Mon, 05 Aug 2024 16:49:47 +0200 Subject: [PATCH v3 4/4] net: mvpp2: use device_for_each_child_node() to access device child nodes Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240805-device_for_each_child_node-available-v3-4-48243a4aa5c0@gmail.com> References: <20240805-device_for_each_child_node-available-v3-0-48243a4aa5c0@gmail.com> In-Reply-To: <20240805-device_for_each_child_node-available-v3-0-48243a4aa5c0@gmail.com> To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Andy Shevchenko , Jonathan Cameron , Rob Herring , Daniel Scally , Heikki Krogerus , Sakari Ailus , Jean Delvare , Guenter Roeck , Pavel Machek , Lee Jones , Marcin Wojtas , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andreas Kemnade Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-leds@vger.kernel.org, netdev@vger.kernel.org, Javier Carrasco , Jonathan Cameron X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1722869407; l=2385; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=Gs9fUy9yW4JBBaoGjjHZoItLt9sngv838Y8XASfxmd0=; b=ihHIaYtp6T390sCfrty1YjNtAYZGThIeMtguLLHG6L01jXTjdSZMRrfQVtNCN4wVYLLhSbRXX /RuF4YN2ObTAcdrI40NuECuErDk+DxTOna13wsTN0raOuLMubO8ZQZG X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= The iterated nodes are direct children of the device node, and the `device_for_each_child_node()` macro accounts for child node availability. `fwnode_for_each_available_child_node()` is meant to access the child nodes of an fwnode, and therefore not direct child nodes of the device node. The child nodes within mvpp2_probe are not accessed outside the loops, and the scoped version of the macro can be used to automatically decrement the refcount on early exits. Use `device_for_each_child_node()` and its scoped variant to indicate device's direct child nodes. Reviewed-by: Jonathan Cameron Signed-off-by: Javier Carrasco --- drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c index 0b5b2425de12..216cc7b860d6 100644 --- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c @@ -7417,8 +7417,6 @@ static int mvpp2_get_sram(struct platform_device *pdev, static int mvpp2_probe(struct platform_device *pdev) { - struct fwnode_handle *fwnode = pdev->dev.fwnode; - struct fwnode_handle *port_fwnode; struct mvpp2 *priv; struct resource *res; void __iomem *base; @@ -7591,7 +7589,7 @@ static int mvpp2_probe(struct platform_device *pdev) } /* Map DTS-active ports. Should be done before FIFO mvpp2_init */ - fwnode_for_each_available_child_node(fwnode, port_fwnode) { + device_for_each_child_node_scoped(&pdev->dev, port_fwnode) { if (!fwnode_property_read_u32(port_fwnode, "port-id", &i)) priv->port_map |= BIT(i); } @@ -7614,7 +7612,7 @@ static int mvpp2_probe(struct platform_device *pdev) goto err_axi_clk; /* Initialize ports */ - fwnode_for_each_available_child_node(fwnode, port_fwnode) { + device_for_each_child_node_scoped(&pdev->dev, port_fwnode) { err = mvpp2_port_probe(pdev, port_fwnode, priv); if (err < 0) goto err_port_probe; @@ -7653,8 +7651,6 @@ static int mvpp2_probe(struct platform_device *pdev) return 0; err_port_probe: - fwnode_handle_put(port_fwnode); - for (i = 0; i < priv->port_count; i++) mvpp2_port_remove(priv->port_list[i]); err_axi_clk: