From patchwork Sat Jul 6 15:23:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 811339 Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) (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 5891A13AD06; Sat, 6 Jul 2024 15:23:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720279438; cv=none; b=oewNi7Y8jGE87RxobgColeONX187XoI2fI5PRgaSjD/p7CkBakFaKrDj731ew17QVvF4FhLGrBuqrODFXXDmKWojLYdXC33zF2YHoD8awD9dTvCUWqxF0AyrpBrUB6vTeG7VqaGarm5xGltWOEy9OWoaQBVyH9SVRZLIl11cFXw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720279438; c=relaxed/simple; bh=7+6Z0APHavEMWbcX1CrJj4Il3cLB/Qq2MtDoHz0G0Fc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TsTWJmQCIXyIzLCFNsGy7WDrtE03Th69NQSr2NjQYpEZYW/TzcvrNxwnWa8HH6FoeuPEKf/qpV/3OadssU5e81xFg3vaNgRXiVDZ4kq8uvljy0ZS2rap93aQ4rvcU5pmfkyXnNzSw02bRN892dj2IwWDRHGV69RVK5zVcTzUGn0= 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=P0jsVnRS; arc=none smtp.client-ip=209.85.208.172 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="P0jsVnRS" Received: by mail-lj1-f172.google.com with SMTP id 38308e7fff4ca-2ebed33cb65so32579611fa.2; Sat, 06 Jul 2024 08:23:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720279434; x=1720884234; 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=6vonvdo4buTi8Kek3AF2MBmwqbEkxs8m01cZABzJaEc=; b=P0jsVnRSmh4Fdw9M2GU0TpiQV5aQ1IJ/MkbuUF/Uw/yJL3SfuygNVqMp5TYWww8Qvy 0x2RL8VTvNedQ3V8id0LvDiiC7J1E2B62RcfthU59WwYvuUepb/zt0wn4yzr/lo4nnPq fyArHxJZjqEDEPCeofAtC9GDcn7wBBXtQ0V0lrx0TiIZ9/k7/iD310/6PWJud2/XEIox Gku8Ha3koWyCBuDCVJrSVyoikmd7rv0TIvLtcsCq7M1ERTLMzRVjkGd8WD6Dve8obFtK Sjx2rfJEmIZuX0PUYHqQniwWHqhrHIBtkJKEJhB7m4OYC1qyfdMDmRVBgdF/32v/eDSa e+8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720279434; x=1720884234; 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=6vonvdo4buTi8Kek3AF2MBmwqbEkxs8m01cZABzJaEc=; b=b4LspPmTQSODlAyqaja0zqcDGhD/ifFzOjAIIFixX4nIJX8+Cj5JYtlk8JWevSCsPa n7j9bVdAcflj2FjfFnnuGwL0aRnkU+Jctuz5d8raWEWYHJC20XsNGjC9cu661VSn+1Qk lLXCYInKv4n0Rfinq0xa03/YQ3GTrFWKJY6paYRatZ5C/CLvncgSqzYvcyzBsww58BE7 lI4igKcHUfPvKVJOsX61dvPAtA2wIRUDB293uJrhBuF5pRi8wW/oU2SVc6Kr6CJji7IF 2chygIA3/YuqbHrD1Ax+DEN+dkgCv2tnKkT2lrSp4PlajOL96mjy1G3jhh8mkxDCDSKX 1dyg== X-Forwarded-Encrypted: i=1; AJvYcCUgCtL1DPRbg/iTCwBKx191LPi2JMCZlx2+z2S9dadnyq8dxh7qQwGfnlAXkcM4BSz2y/1CrnAWKJ4Mv2rtNuDKfAOxhyg23rDgHwd3EDGCoKyqL59UZO9ny1WqPLZmRIDjIdal+x6bmTGOGEgem8cr4+ESVSgpJQfOk7OxeG6XtiC7vcPf+4Qrc9TYCfIHqr6WahmuolvX0MmO7ILC X-Gm-Message-State: AOJu0YwnqM/sXL9CVFl9sEOIZoteNQhrD0MFFNA+qFgCTs0smcBw1tm4 Q4uaDcunAPs/gwxC7PTuwITsT5RYKH1EjM/re1IgA70bUfOh0AZM X-Google-Smtp-Source: AGHT+IEWCoiG5MnGrUnj5UnoDy02MYCZUmysm6Wu8MxysqIvfh/76n1gkocfimi5zpgGIOZP09yCEQ== X-Received: by 2002:a05:651c:c2:b0:2ec:5621:b9f2 with SMTP id 38308e7fff4ca-2ee8edd33edmr49536161fa.41.1720279434153; Sat, 06 Jul 2024 08:23:54 -0700 (PDT) Received: from [127.0.1.1] (2a02-8389-41cf-e200-d11b-8ec4-ea76-796c.cable.dynamic.v6.surfer.at. [2a02:8389:41cf:e200:d11b:8ec4:ea76:796c]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3679ed376cdsm6421593f8f.114.2024.07.06.08.23.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Jul 2024 08:23:53 -0700 (PDT) From: Javier Carrasco Date: Sat, 06 Jul 2024 17:23:33 +0200 Subject: [PATCH 1/6] 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: <20240706-device_for_each_child_node-available-v1-1-8a3f7615e41c@gmail.com> References: <20240706-device_for_each_child_node-available-v1-0-8a3f7615e41c@gmail.com> In-Reply-To: <20240706-device_for_each_child_node-available-v1-0-8a3f7615e41c@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 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=1720279430; l=2008; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=7+6Z0APHavEMWbcX1CrJj4Il3cLB/Qq2MtDoHz0G0Fc=; b=Y6hFK7KTaGbWVOlWICFvFipwEEBFAf0YclD7EeQp5JBtkmCNbSRA+aUo1WRqLA/jOsQy5Bz9o MGkYVLJqmycBqsIVGJRJOX6UrnjCQKgbRAKXJYxJHkBJEzPzfUA9Ekk 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 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..ba8a3dc54786 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, if found + * + * 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 Sat Jul 6 15:23:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 811049 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (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 B2E5813B585; Sat, 6 Jul 2024 15:23:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720279439; cv=none; b=OFLLtE6+sb8FWlGQKO3BOGOHNKMwSfRoCPs6/KhKSkXDIXcMyegsp1en5ZaTDfwHhYCdg6HNRazFuzatEwEo+UZN91CHc2mWiKi8tno0OuM7FDhbgv1Ehjs7oFpJigfvWaLQAF01ra1jlIYCKdQbBUTSq0d3OCARTGtrGMuwuLU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720279439; c=relaxed/simple; bh=J/DKHnWwklUy1ZaywRXLH+SB/DamAjhdOjVxM8WXYcE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PxsXZpiMBwHD07FKZ50yiwq3qB73CNbqJe1f2Gj/1FUz4V52JaB7rYwDEQb66h7OC7QpcQMTXrJAbgxpok9eR7S5UF0/vCqyC7UkPhpdLdOsiPtcHBWGEA/2yrpBPYLul3r3g80/0v3JMD2zZho3JwigNwfYMFy5AdaCC84PDeg= 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=RZiJI74o; arc=none smtp.client-ip=209.85.221.53 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="RZiJI74o" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-36798e62aeeso1631334f8f.1; Sat, 06 Jul 2024 08:23:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720279436; x=1720884236; 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=5WklQuGWTyUZGXjSt3Sj1gy49uGRkFZnR7/Z3/DZXyU=; b=RZiJI74o3iY5geJR7evAximq6eFELX+dVBz6/+m7LyeXk+6GpunIHxXaiJ4YqwymeW vI/jgJVqsWc/x6sbNAE8yNJ1WCMwS14wY5BXvG+raWivbWRbnelr5DnBPuouilxNwgZu ItIh+OiZOWo5uvZjuHD8F4aoaejgdUbXiVK0AULj9G8ff1BgtyYoHrMEWFppcNaoPPLq eHi1AxaVVY493z5+24NZr1efPj64Ra4PwaYyTUd5HXWN0fiSY8VhIt0STVg44SYejtwQ DuYN6FYOE5Fd6UoiFgIv8Vt+LLXY9G5XsyRsc30xITdYb+KA87bcFuOdiMfvLOYfcvYl xnYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720279436; x=1720884236; 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=5WklQuGWTyUZGXjSt3Sj1gy49uGRkFZnR7/Z3/DZXyU=; b=vBdbrAl0buPNgK7VFpNV0jEEOHvQZ2vcUIrX4W5nYk+0gIQZHaj01nkyDdy1KA/bAQ Lyu9SHNe6potJ0GD3v8jPlH44zhFhSGUVNbdSxsY0Zv0F4z2dNnR3MJILnRSgPVXIeg1 y4NIKxMsI9Rl6W1np4se+a50SH+7Ce0naRPYqUBXWeH2CDOSYhkz9k2E0n626DUtqELw Hb2l8A8kgxSqPtv9DCFMnTXYMxh7ngsCqallVtjb03lBiRNuM4I5cZcCrGkFnbmwOTHI FM2fQMbzDrhUoiFPYcpjUVPG3NImLsGr9i77lduL1PKlDvYEqN3R4vwkg8CQnlqKBnA4 BcMw== X-Forwarded-Encrypted: i=1; AJvYcCWwrY0bf77nr0KcScgr0xUZrTcCgWCrQRrZunBw04Im5CdvHxtHHiWEloEVElHrr2hFf9Giv9qbwR6aj+wTglek6S+PEZlnjZqQvLyHdk0BRMZLzw3Y46wUYMbgcwtaettUobb7KLWdeUZb1sAhmFgoupwoBSyaUZay0hc4HnOWYm8xk7tRgyL9r8Fs9Law7NTsR9itiR4AZ3BWhZlp X-Gm-Message-State: AOJu0Yw6038dz6UN8GS2eG5EfidVYJfzFqCLVVZrQ0PUngwxEmb2mopj Aibx95Zze4BJtRX6q3MVg0GA0ormQX6A0li7Dk0KSp/Z2xbBy3SJ X-Google-Smtp-Source: AGHT+IFmo8jZVBKEzOMMJzT8ULSphrmfgsUFkXzLGQBqQAyu2DhNTZpcNQriljIov4bBp75pXtmMLg== X-Received: by 2002:a5d:664b:0:b0:364:3ba5:c5af with SMTP id ffacd0b85a97d-3679de96b30mr5176147f8f.61.1720279436002; Sat, 06 Jul 2024 08:23:56 -0700 (PDT) Received: from [127.0.1.1] (2a02-8389-41cf-e200-d11b-8ec4-ea76-796c.cable.dynamic.v6.surfer.at. [2a02:8389:41cf:e200:d11b:8ec4:ea76:796c]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3679ed376cdsm6421593f8f.114.2024.07.06.08.23.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Jul 2024 08:23:55 -0700 (PDT) From: Javier Carrasco Date: Sat, 06 Jul 2024 17:23:34 +0200 Subject: [PATCH 2/6] hwmon: (ltc2992) use device_for_each_child_node_scoped() to access child nodes Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240706-device_for_each_child_node-available-v1-2-8a3f7615e41c@gmail.com> References: <20240706-device_for_each_child_node-available-v1-0-8a3f7615e41c@gmail.com> In-Reply-To: <20240706-device_for_each_child_node-available-v1-0-8a3f7615e41c@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 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=1720279430; l=1901; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=J/DKHnWwklUy1ZaywRXLH+SB/DamAjhdOjVxM8WXYcE=; b=fPXEHlwcpK9k22fEHLCAEULQo4I96aPEgd/oDAs8po1HIlTQCq5s1WW+OkVtaPet8BxeiaRod dNZUWVjlxsJD1xWgPCr1e59DfdQNJP+pFj8c2YXnAGp6xv/9Rg9H5b7 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. In this case, the child nodes are not required outside the loop, and the scoped version of the macro can be used to remove the repetitive `goto put` pattern. Use `device_for_each_child_node_scoped_scoped()` to indicate device's direct child nodes. Signed-off-by: Javier Carrasco Reviewed-by: Jonathan Cameron --- drivers/hwmon/ltc2992.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/drivers/hwmon/ltc2992.c b/drivers/hwmon/ltc2992.c index d4a93223cd3b..541fa09dc6e7 100644 --- a/drivers/hwmon/ltc2992.c +++ b/drivers/hwmon/ltc2992.c @@ -854,33 +854,24 @@ static const struct regmap_config ltc2992_regmap_config = { static int ltc2992_parse_dt(struct ltc2992_state *st) { - struct fwnode_handle *fwnode; - struct fwnode_handle *child; u32 addr; u32 val; int ret; - fwnode = dev_fwnode(&st->client->dev); - - fwnode_for_each_available_child_node(fwnode, child) { + device_for_each_child_node_scoped(&st->client->dev, child) { ret = fwnode_property_read_u32(child, "reg", &addr); - if (ret < 0) { - fwnode_handle_put(child); + if (ret < 0) return ret; - } - if (addr > 1) { - fwnode_handle_put(child); + if (addr > 1) return -EINVAL; - } ret = fwnode_property_read_u32(child, "shunt-resistor-micro-ohms", &val); if (!ret) { - if (!val) { - fwnode_handle_put(child); + if (!val) return dev_err_probe(&st->client->dev, -EINVAL, "shunt resistor value cannot be zero\n"); - } + st->r_sense_uohm[addr] = val; } } From patchwork Sat Jul 6 15:23:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 811338 Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (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 9575D13C8E2; Sat, 6 Jul 2024 15:23:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720279441; cv=none; b=c+NJcwqGPbk9uJGj4g+QiZXH+vIqPg7ArLpbx//oUP6fZkRMPq5reywR8qXBU8jTYGv/f2h7K6muA4dUVHxoh5J/yyLjrnmjRyeH1y9nRip0adDDVO/r0hQHgDbzU3tPHN+/M6QPcbztveOfem7zYOJW3k+C4XVv8cz1KnL1X1A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720279441; c=relaxed/simple; bh=fqZJ701DBgGh6DQqiXNJ/NxMzjiGcQXtbhZJoo4oHkw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GNqNK0scmcqJ1ga7XMAIHPCb7cskWoSFDiEArXp1zeWfhLNR2Gx2Z/OGpyDK9JwkrtGMI8C4jSadkQ3X1bKstEzWyJ2rws7us03R/Ld4snfgn7towgpi8Ubzu6Qp9H0k7K8brRHsJ+g8Bnvk8TZIqIniKKS2LheD+B7GTKA1fY0= 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=ZgDjJOXj; arc=none smtp.client-ip=209.85.221.54 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="ZgDjJOXj" Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-367ac08f80fso797525f8f.1; Sat, 06 Jul 2024 08:23:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720279438; x=1720884238; 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=XNURRg1zXJNR5Gqt2mpwpSYiaUFcsBTrqWCau16CfK0=; b=ZgDjJOXjrZh1nHR042VIlDYWE0gI+IZNbqAn50dc6LczvBa1SyodSNj04q2fmmFhVa KJd5xqBOXL1GO0Onu4GswafqCLfD76urJnbbs+6SgzAEprRGWFRQQBbzxvWbo0juvI/a H05+gkP0t/QjcHUjJT3XwiXawBpF/pwqg1T6U0LV6ZlQoCP6QloHAPRmOxyLzaihkFLs DROOww+QpWD3+HyxH8uyGKpOh+ngWLrJbCGZzFP51He4UAI5hrAtDU/fE1EQ/NH62h/k vkqCBxT3wd7uAeL0ti/gJlETpcd4OTb1hC0+T1L18c4ZGZp9May/WU8MLxVUG4BN0w+W 8nSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720279438; x=1720884238; 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=XNURRg1zXJNR5Gqt2mpwpSYiaUFcsBTrqWCau16CfK0=; b=WfIHtM5/TmYn7Gw4M+enX6/5uLNmrOyI7qr5xs7iqqkEA+dZCkg4P4qhSQ6PbdtQWx oqdAPSekm5Nb3M5ttQxb9GAX+0LSAUltEvwXgzt+veasec2OuAkvYpNJjf6foGG7h+Vw JkuY+LdoJ/hSiZnp0wRx4XFqDbF0++DoqvHp7JdMWxx4DfWZ7Z6SkU0S1627nHIs981s PuIWxISdrhQDjE7dI8/Exnx68ddq1d/bgDasCs/CzoygfZl6uI5xTklSjFZ7C9qaffIc n6m3GNudsQKN4pYaFmLlLx7QjHdFhEwNomwRQxMT1fsxUaKbWRJLlqr4BxEmCVsQuSpe c0qg== X-Forwarded-Encrypted: i=1; AJvYcCXsXK9HRm6xnk2dPY5SsEKdzFDtpUSfkxAmxsawWv2C40hnWPnNl7OXvGaMUeVLw99NR2k1H6FVFeIxsVi+BkRalqSV/+ahNbGhfvelv2OhYD838kLxhH0+2U8R2AIg4dL5Zqr1c7dkEz4VWfd3uYX6cjWupbI7/8i2t/l8HiSbZPubI0entBU1cYrOKJRivYilF11lnUBD1ApLlEWR X-Gm-Message-State: AOJu0YwcULgms1t5giz8jnjZJM1H88JLbJLFGaXC2T24Q1LaUk0QoQya ToaOB808jKRTCtUmft3pHS/iNkzGXS+QpsldCF+X0BHFxipCVuHh X-Google-Smtp-Source: AGHT+IEAraam7CVa4mw68xmzTqSt57yaoOsCYGEh2+l2Ul03bC3MBXIPuXXfeNvaHAEWI3IVwZdghw== X-Received: by 2002:adf:f887:0:b0:367:8c22:5b7a with SMTP id ffacd0b85a97d-3679dd2adc6mr5606639f8f.22.1720279437902; Sat, 06 Jul 2024 08:23:57 -0700 (PDT) Received: from [127.0.1.1] (2a02-8389-41cf-e200-d11b-8ec4-ea76-796c.cable.dynamic.v6.surfer.at. [2a02:8389:41cf:e200:d11b:8ec4:ea76:796c]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3679ed376cdsm6421593f8f.114.2024.07.06.08.23.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Jul 2024 08:23:57 -0700 (PDT) From: Javier Carrasco Date: Sat, 06 Jul 2024 17:23:35 +0200 Subject: [PATCH 3/6] leds: bd2606mvv: 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: <20240706-device_for_each_child_node-available-v1-3-8a3f7615e41c@gmail.com> References: <20240706-device_for_each_child_node-available-v1-0-8a3f7615e41c@gmail.com> In-Reply-To: <20240706-device_for_each_child_node-available-v1-0-8a3f7615e41c@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 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=1720279430; l=1637; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=fqZJ701DBgGh6DQqiXNJ/NxMzjiGcQXtbhZJoo4oHkw=; b=dcBAFFldBGqI8x3o514eq/AXVIdyRvFUMSia+cqpFszPq4N2AkkUE2Ds/x7OasYwC3u/+Tth4 YOxArhUD6TJAw2ABLY08LcYEkvRdZqFIhlo9jOuQk0Qntk4Moqsvme3 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. Signed-off-by: Javier Carrasco --- drivers/leds/leds-bd2606mvv.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/leds/leds-bd2606mvv.c b/drivers/leds/leds-bd2606mvv.c index 3fda712d2f80..4f38b7b4d9d1 100644 --- a/drivers/leds/leds-bd2606mvv.c +++ b/drivers/leds/leds-bd2606mvv.c @@ -69,7 +69,7 @@ static const struct regmap_config bd2606mvv_regmap = { static int bd2606mvv_probe(struct i2c_client *client) { - struct fwnode_handle *np, *child; + struct fwnode_handle *child; struct device *dev = &client->dev; struct bd2606mvv_priv *priv; struct fwnode_handle *led_fwnodes[BD2606_MAX_LEDS] = { 0 }; @@ -77,8 +77,7 @@ static int bd2606mvv_probe(struct i2c_client *client) int err, reg; int i; - np = dev_fwnode(dev); - if (!np) + if (!dev_fwnode(dev)) return -ENODEV; priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); @@ -94,7 +93,7 @@ static int bd2606mvv_probe(struct i2c_client *client) i2c_set_clientdata(client, priv); - fwnode_for_each_available_child_node(np, child) { + device_for_each_child_node(dev, child) { struct bd2606mvv_led *led; err = fwnode_property_read_u32(child, "reg", ®); From patchwork Sat Jul 6 15:23:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 811048 Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (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 6CA9613D8B6; Sat, 6 Jul 2024 15:24:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720279443; cv=none; b=aK+JKqM8x04zw2/D2La6zYo/BL1+fgKyw3++YHGwV+j+qA+8W54OUTku4DRHQs7/8gEXSzJVyvpt95dh9lXMy9VQPlnRG5BupqMs1LM26HGwHSTIiO/BWIMe+WXgg9RjuOkeb+sNIGGl1ed4uYp3xIcdXnqNFMrujOWE95xw3RA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720279443; c=relaxed/simple; bh=A8DEj2ZkqU7SP3vJMUJGnKFPlor+UycUMys9QrcisPE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MNS0mjB5AkPUwkixIfA5IaI+sJ9QZgkkpda4vUyq+uMVmfLR3vVfs2C21P6DCia1rUzbXQMd8xQlu+6fxSKOZ7GTeKQzQ9DkVLXScr6sw6wG3nCJ7jSNPXeMi35jZHoOocYws7/0131+Y7HuFKGEA14p5FxLM/zBGamB8gAXXDI= 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=ftLWwh4w; arc=none smtp.client-ip=209.85.221.54 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="ftLWwh4w" Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-367b6e5ffbfso284653f8f.0; Sat, 06 Jul 2024 08:24:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720279440; x=1720884240; 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=Yn6WsK79DmUmiECl4Pth1iGaHBlA8QEqkWn9Q8DE2Gw=; b=ftLWwh4w8cQgNkzCQ7hwlQZwgdFiNLECLzmnnWEa+N+w6wAwsFJ5x/6q8awccRAy3b VkCou93vFY4tqm+EJTS5kn/cHRPAkdSZJqPqZqaDnWPt2LidQR/W8tQrTfR0EJRMzgpx MF4tJpe91PL5o57N6FBfwDS05NC87GF0+DEj/ksbRqaJsH2C3ZUi8c9REP0jHlTwMv1e AUtqyFyClpeGHEY0DAl269SrRkVT5mYXS7xbgYJzPXvRs7txBe8yshqWWXtnf/kQftHG So8GbrAczLv+hNu67kLIbFYiSewC0E18XwBYr/RmlRul26hNRTxv3OVLyi2+FkH8Qnau JpmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720279440; x=1720884240; 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=Yn6WsK79DmUmiECl4Pth1iGaHBlA8QEqkWn9Q8DE2Gw=; b=rZmgMNJ60UcgtK429W9ZDyHLOfDvutxZActQw6siOI6hobPUBMd01JEsSW8cTbwWwT sOAsjMhMRxJj++XtNU9OQtHu0htL5UYloHRcP3eiNaxQcbw4PqgWri2AeXgcjtLzzjBb jxonwn3562gltnwGTfbomPVRi8R7VN08Wgjk9yLizgmAoUMG+Fp48AMlvcAv7igF54yW Mqbr6JvG3h4ABsaAWcfa4t4pZ9d8D8oD2klnP3XBrAfjFdYFlUf24eLrOdFNZcGrgLlj bGnzGuAshfmKGZhKL1+/IUiuuxv36ZA2syMiOxO5LaqJbkwSMIW/AOTK3jvbqtfIsjUS jUuA== X-Forwarded-Encrypted: i=1; AJvYcCWL+gK+LralryUlBdljRpAxRs+5BU2NrQfNI0NtO64eBTjSAM/6IgpzSiCkqELZdXHHRfvo+lZHG6iijfE7WmX+Dl2vNAQJeAg03KQ18L7M0xdLysPmXSqNYOJtOHlGfizAVfqBUtLAwDG+QHMgLdJyAJ9DXNbImm6OeB9snzmV2gAUwiwqCrgVGvVNPT3ACgKKU4SBW/8cISedqckp X-Gm-Message-State: AOJu0Yy/lP3DVLYsDuvfgh0FpLovvaNMNvQSbH2exiDFbpU9oP7zZpE2 rakd53wcj5BEV+wo8KfOw1PSc3qBRtOLQJ1WBE6P7hfHkLKVWecr X-Google-Smtp-Source: AGHT+IEL9TbwlSVtRbY0REhBEkD1pyO6EslQex2SbVP2og0jgwsCSsS4OdNwEJDFMuIpXTxFGIS8JA== X-Received: by 2002:adf:ab13:0:b0:367:9ce9:f05a with SMTP id ffacd0b85a97d-3679dd29521mr4939810f8f.21.1720279439812; Sat, 06 Jul 2024 08:23:59 -0700 (PDT) Received: from [127.0.1.1] (2a02-8389-41cf-e200-d11b-8ec4-ea76-796c.cable.dynamic.v6.surfer.at. [2a02:8389:41cf:e200:d11b:8ec4:ea76:796c]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3679ed376cdsm6421593f8f.114.2024.07.06.08.23.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Jul 2024 08:23:59 -0700 (PDT) From: Javier Carrasco Date: Sat, 06 Jul 2024 17:23:36 +0200 Subject: [PATCH 4/6] leds: is31fl319x: use device_for_each_child_node_scoped() to access child nodes Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240706-device_for_each_child_node-available-v1-4-8a3f7615e41c@gmail.com> References: <20240706-device_for_each_child_node-available-v1-0-8a3f7615e41c@gmail.com> In-Reply-To: <20240706-device_for_each_child_node-available-v1-0-8a3f7615e41c@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 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=1720279430; l=3380; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=A8DEj2ZkqU7SP3vJMUJGnKFPlor+UycUMys9QrcisPE=; b=Fv97yiGs2DQNJVxEW7bimU1F9DZUlPxDGD3VwcD+c9cOUNyxUbaKKLba2vQflBEHAr2/1Kj/D ssB/DIeFTzxC0DuZHk7n39/y72jttF+S0CH/BDWknCECHdtw318LLxM 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. In this case, the child nodes are not required outside the loop, and the scoped version of the macro can be used to remove the repetitive `goto put` pattern. Use `device_for_each_child_node_scoped_scoped()` to indicate device's direct child nodes. Signed-off-by: Javier Carrasco Reviewed-by: Jonathan Cameron --- drivers/leds/leds-is31fl319x.c | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/drivers/leds/leds-is31fl319x.c b/drivers/leds/leds-is31fl319x.c index 5e1a4d39a107..27bfab3da479 100644 --- a/drivers/leds/leds-is31fl319x.c +++ b/drivers/leds/leds-is31fl319x.c @@ -392,7 +392,7 @@ static int is31fl319x_parse_child_fw(const struct device *dev, static int is31fl319x_parse_fw(struct device *dev, struct is31fl319x_chip *is31) { - struct fwnode_handle *fwnode = dev_fwnode(dev), *child; + struct fwnode_handle *fwnode = dev_fwnode(dev); int count; int ret; @@ -404,7 +404,7 @@ static int is31fl319x_parse_fw(struct device *dev, struct is31fl319x_chip *is31) is31->cdef = device_get_match_data(dev); count = 0; - fwnode_for_each_available_child_node(fwnode, child) + device_for_each_child_node_scoped(dev, child) count++; dev_dbg(dev, "probing with %d leds defined in DT\n", count); @@ -414,33 +414,25 @@ static int is31fl319x_parse_fw(struct device *dev, struct is31fl319x_chip *is31) "Number of leds defined must be between 1 and %u\n", is31->cdef->num_leds); - fwnode_for_each_available_child_node(fwnode, child) { + device_for_each_child_node_scoped(dev, child) { struct is31fl319x_led *led; u32 reg; ret = fwnode_property_read_u32(child, "reg", ®); - if (ret) { - ret = dev_err_probe(dev, ret, "Failed to read led 'reg' property\n"); - goto put_child_node; - } + if (ret) + return dev_err_probe(dev, ret, "Failed to read led 'reg' property\n"); - if (reg < 1 || reg > is31->cdef->num_leds) { - ret = dev_err_probe(dev, -EINVAL, "invalid led reg %u\n", reg); - goto put_child_node; - } + if (reg < 1 || reg > is31->cdef->num_leds) + return dev_err_probe(dev, -EINVAL, "invalid led reg %u\n", reg); led = &is31->leds[reg - 1]; - if (led->configured) { - ret = dev_err_probe(dev, -EINVAL, "led %u is already configured\n", reg); - goto put_child_node; - } + if (led->configured) + return dev_err_probe(dev, -EINVAL, "led %u is already configured\n", reg); ret = is31fl319x_parse_child_fw(dev, child, led, is31); - if (ret) { - ret = dev_err_probe(dev, ret, "led %u DT parsing failed\n", reg); - goto put_child_node; - } + if (ret) + return dev_err_probe(dev, ret, "led %u DT parsing failed\n", reg); led->configured = true; } @@ -454,10 +446,6 @@ static int is31fl319x_parse_fw(struct device *dev, struct is31fl319x_chip *is31) } return 0; - -put_child_node: - fwnode_handle_put(child); - return ret; } static inline int is31fl3190_microamp_to_cs(struct device *dev, u32 microamp) From patchwork Sat Jul 6 15:23:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 811337 Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) (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 E478C13F432; Sat, 6 Jul 2024 15:24:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720279445; cv=none; b=glI9oZ/LFiys/+i0UHPeuICDNfTikQ+JfxIYgc8joqFNXBHHc0DL7w9cxa+yj48IEUlgAIzitxeEoUV98CujjfJUMuevRB2JxCF8XZeZmPiCZHUAhiGQeA79M3/oaUaazwj8zMo7hNQ5xxUg2qcYTNDsOoWPHZkwXJ5szBqx+UI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720279445; c=relaxed/simple; bh=K3R8ogK7IVMeFaCChZAZLu9Bvl86iEg/W4IL7S7RZa4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gVn2IYz2OVYuRpQroNKKxtuvntkRps6uOLNhSgMqh64In/hkY5546Gt6r2E2Lj3nj+nA7Lfuhx9mPJ6KBC70uZ5cJeRmQogdCmaNMVQeaKZ0VxFUEile5XdUQopCdP73PY0lILTU39ps0LEgveg8RWbJHz5dvWGTRj4Sw47frhw= 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=E6zzqxGr; arc=none smtp.client-ip=209.85.208.177 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="E6zzqxGr" Received: by mail-lj1-f177.google.com with SMTP id 38308e7fff4ca-2ee910d6a8bso20463901fa.0; Sat, 06 Jul 2024 08:24:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720279442; x=1720884242; 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=miy9Di9xCntCHDeUmGUbX6OsYDKhV54cCzIVatLBuUA=; b=E6zzqxGrsqaQKamuTgqE79s1eguPyuMBbliLAQMtrK+cdwQ6UHyPeTydiMAPp8PA0H SbnlMIBop1ACi3JK5VqeW+65NUJT9kgt6j8tGUPyYDThp4UwWzH6Emzw9mSrGmbYCzQ4 9JESVpwqipu/s/kSWtG3lLgm5+rLnQsdhhMgAM1p5OtHZp/xOQeDcb55hCY5wDZ21BNz XV51Pw0eqD2lduflO/ndccMAUIMNJaJlIFaxH2EDxQCyjLsmfziW59BG4+x4dq2HPFe4 dKYsD4JiXZ56KPK04blRBVl7tN/mnc170j6MvechI9+CkNH28c+UskOjozQfTHBeCums gTow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720279442; x=1720884242; 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=miy9Di9xCntCHDeUmGUbX6OsYDKhV54cCzIVatLBuUA=; b=HWMMCY3SjsB1/bAfnH0IXNOu5A5dgV/+QACR+P+KnlxqKHNSdrg+USXgUay+xi33Fi MqDDBUYTgh6DI/fJnav4w2JuJ9N+r/mj5LE8IFhMoSwmqtVoUkAAc6ruq/QSkUw5TyZB BPz31SugGyLDfPJ3iR7bYgCE+AyfWfWxCnXOI39IoeLw9MBlSox2LVHv6HYirtkfqL+U cy+Z3pDKp20vwphUOVmNmQEfVwC84NiS/YU2QbcuExnDDGxdKu69GWzcdfK6ozXh1ZOK pUFvxO4Ng2geLpfhiTG/zLHEgftpk5qm4pHJjtf+fHK02ncjTwfX+9kUjMGMJjqUypbD 9r7Q== X-Forwarded-Encrypted: i=1; AJvYcCXqsBaCOfzpQhYSvSwf4fUbGglzLb0RL/Fc3JOgbkf5dfVQn4IGF+QlezyOJUKs0SSXYOPFaHZpCenS/fNXeK2SicXkqy6XrBrXwQPsaTBqptCqtum/IDb9il1GdIxaWmjuPAPzpfS7Ufn3o5NcD2GA5lC2DFH6oOc/CBDcF+42iHgUM4B5azp4n5i4d8MZG8V0d2iXETM5XqHNTKDd X-Gm-Message-State: AOJu0YwxgEslYz/WkEGSKfJed+hDKoPhLSidMyj/OdGPH0PvaNmg5jpf JOXw9St6yy1p218WXkdnAoFJ2oTRVqVvJbsKKZX5QzVe+IUtv/kU X-Google-Smtp-Source: AGHT+IEl+fY7kn5+q/a8NpX0f9qd1gxze3aB0YAOzgBJhOMrKDCtNUXcKSAjD3y6X941eQrjNOfHgw== X-Received: by 2002:a2e:b5b7:0:b0:2ec:5364:c791 with SMTP id 38308e7fff4ca-2ee8ed9132bmr46099601fa.17.1720279441709; Sat, 06 Jul 2024 08:24:01 -0700 (PDT) Received: from [127.0.1.1] (2a02-8389-41cf-e200-d11b-8ec4-ea76-796c.cable.dynamic.v6.surfer.at. [2a02:8389:41cf:e200:d11b:8ec4:ea76:796c]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3679ed376cdsm6421593f8f.114.2024.07.06.08.23.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Jul 2024 08:24:01 -0700 (PDT) From: Javier Carrasco Date: Sat, 06 Jul 2024 17:23:37 +0200 Subject: [PATCH 5/6] 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: <20240706-device_for_each_child_node-available-v1-5-8a3f7615e41c@gmail.com> References: <20240706-device_for_each_child_node-available-v1-0-8a3f7615e41c@gmail.com> In-Reply-To: <20240706-device_for_each_child_node-available-v1-0-8a3f7615e41c@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 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=1720279430; l=2009; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=K3R8ogK7IVMeFaCChZAZLu9Bvl86iEg/W4IL7S7RZa4=; b=60bPyJCCQaiTgPKHxfDehXlLgljOBSixt0bYCkeZYlDJfQF/YdKwjI57sn/g7FCDty7e2dKVj FfxuObbdT6uBw7l/xk35X0tnV4cEdh1CNbUN9YsFzXudcztBEIQfWeD 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. 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 78215dff1499..a5b32eaba724 100644 --- a/drivers/leds/leds-pca995x.c +++ b/drivers/leds/leds-pca995x.c @@ -102,7 +102,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; struct pca995x_chip *chip; struct pca995x_led *led; @@ -110,8 +110,7 @@ static int pca995x_probe(struct i2c_client *client) btype = (unsigned long)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); @@ -125,17 +124,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 Sat Jul 6 15:23:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 811047 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (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 6A34E143863; Sat, 6 Jul 2024 15:24:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720279447; cv=none; b=pcVLdQeBNjUQUbD6OJ6nyllE4g1DRI1HcVxTypm1gDAIsX2FwsR7DIzdpC4kDDD0bfQx0wBzk3OEsRptPqC7UmPxknjpYxDqK24ji2SWxBTTmWPmtWuLLx9+eOuMmWZZkeKs3w0gg4neVqEZiH9ARV/OXoWhqxMcyCsYOXMIFDA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720279447; c=relaxed/simple; bh=FqQDDFZRZErZwoVBwncsgkhb9stwS0b2C3AaKUJjEeM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nl7SRTjc6x4QIV7n7p1DQdK3OSNVFQtxc6NkIYNwDkDVGLIPotufthjeUtmjHeHcI1f1gFWmbKWUl6pKtTjx5y5XhDz4Zt/CuNkRQbdr4MknJDfIa7U1nw3VtC4TVVHC14jHe/AmK051xQH1A6x9PbwI4kLw86efmpPO7l0AyvQ= 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=nmTPtclV; arc=none smtp.client-ip=209.85.128.47 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="nmTPtclV" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-4265921b0f6so8161545e9.2; Sat, 06 Jul 2024 08:24:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720279444; x=1720884244; 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=Snaqybo2SQ9uek82H01UqwsbwzQvNpsRmSQLWD2DPEc=; b=nmTPtclVWbXXf9fVkcsiqzpYV0sSMcryc+3JCFktfHhmbTQLTkZ3vFknMLVrF+RA6m wgHSMch4CzE5Qsc8C5O2B3MYWnKQTk78vQnsqgfAjmrmvSp2kU+rTMXPyaUVlmqtWHio HNSSEnD12o/DrA4mRHq3xoKt8SfNVaGzZmfTTH3+RN5abJ8Ft45EDFdFCpHDpSF8Kx9d 6GO2T17GJXXN1ImLepzWRvpC1TQ2sWHJN+YxGXEK342LfQFtwwYfWFvi9vz5CnNDbBw/ e30Sr0zNk3P4zE9YBeuYfjSn9O8udxj0T3hb80VdOwbFSLJQ3iee5JOe4kOk16stov5u TVsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720279444; x=1720884244; 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=Snaqybo2SQ9uek82H01UqwsbwzQvNpsRmSQLWD2DPEc=; b=bjP6taPJPoolTEtyUscs0aaGC7n8qpavgrUz8A6FcWssktdqvROoSs3D8lxNPk3ezT WsybCP7XktSWVRSKx4fB4fH5ND7HC/wLbRJejBLsnlKpdSZMOIi4gnoEABW8FfePS1E6 HDNk72XFJ6JcBD54eOO+DsQ2mp5fCrrd+2OkRbDwoBq6sUlA3klLA/IHe1/4dC9AtMeh Ns0bmcY+zltNzeOBLKbWFs55WLpdSgmY/6ZZh3zWhHEa/7XdpN7Cek/YTRKjebX1FDDZ J5i/no1kJfHTWKdz8Xem80S77nGNv9aWV0aXjobkmGHNTjW/LaN0JkK6eHGAgUR4Shm+ axYw== X-Forwarded-Encrypted: i=1; AJvYcCXTvpEzeoYa0juJ46lywheiX+bejod5ZI4N+EsrM8uRD1yNd8XcQcX+4bFQ6ur1FBz4XUItt1+b8PnvbKRe0FO8JQ2zhVB4BLGcQnZ7S8FGozvsZ1uU3CtQdyFNxXeKNfO5zBsY7WgO/HUEyMg4SKO8xqKRymntWLOrzI9lTHkO2XjKD6Ps3wvmBLeyd0M7/r+ymnY9L57pB2bUUpPO X-Gm-Message-State: AOJu0Yybr2Voiy1Y1JT0PhBdNaSLLzrdALwO6Ib9FeGzP4G7+evej3mI K1D8lPcJVs1xSAczdOJFTk7v3T9d4yEGCgriFogNLJItF7nmxm+c X-Google-Smtp-Source: AGHT+IHcEq8Yc3mYNalQX8RlmIf4m62FTVZhE01QeXRyiVYmbmbL9x/FzVMFnqzIuz8+XRLsKWF+iw== X-Received: by 2002:a05:600c:4fd3:b0:425:672a:766e with SMTP id 5b1f17b1804b1-4264a36eea8mr56784065e9.0.1720279443721; Sat, 06 Jul 2024 08:24:03 -0700 (PDT) Received: from [127.0.1.1] (2a02-8389-41cf-e200-d11b-8ec4-ea76-796c.cable.dynamic.v6.surfer.at. [2a02:8389:41cf:e200:d11b:8ec4:ea76:796c]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3679ed376cdsm6421593f8f.114.2024.07.06.08.24.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Jul 2024 08:24:03 -0700 (PDT) From: Javier Carrasco Date: Sat, 06 Jul 2024 17:23:38 +0200 Subject: [PATCH 6/6] 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: <20240706-device_for_each_child_node-available-v1-6-8a3f7615e41c@gmail.com> References: <20240706-device_for_each_child_node-available-v1-0-8a3f7615e41c@gmail.com> In-Reply-To: <20240706-device_for_each_child_node-available-v1-0-8a3f7615e41c@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 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=1720279430; l=3064; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=FqQDDFZRZErZwoVBwncsgkhb9stwS0b2C3AaKUJjEeM=; b=iYfjox0buokEbZZKDxP8IjBs7/BLHuTRJspiW0SQNWK4kaEyOHbevnTQUZFZMwWBmoXcBYvtO WPOUxSokjULCQwJBFziUXz70jl9I43krYe0vWYwX507MG+hQrbPBtUA 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 lopps, and the socped 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. Signed-off-by: Javier Carrasco Reviewed-by: Jonathan Cameron --- drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c index 9adf4301c9b1..97f1faab6f28 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,10 +7651,8 @@ static int mvpp2_probe(struct platform_device *pdev) return 0; err_port_probe: - fwnode_handle_put(port_fwnode); - i = 0; - fwnode_for_each_available_child_node(fwnode, port_fwnode) { + device_for_each_child_node_scoped(&pdev->dev, port_fwnode) { if (priv->port_list[i]) mvpp2_port_remove(priv->port_list[i]); i++; @@ -7677,13 +7673,12 @@ 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; mvpp2_dbgfs_cleanup(priv); - fwnode_for_each_available_child_node(fwnode, port_fwnode) { + device_for_each_child_node(&pdev->dev, port_fwnode) { if (priv->port_list[i]) { mutex_destroy(&priv->port_list[i]->gather_stats_lock); mvpp2_port_remove(priv->port_list[i]);