From patchwork Thu Mar 13 07:18:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matti Vaittinen X-Patchwork-Id: 14014488 Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) (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 31A5B1FC102; Thu, 13 Mar 2025 07:18:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741850292; cv=none; b=qNnScgHGMafg+1wN2pfDJms+HMhFGxLXw7astKoDViekbwATKndA2gO+ERuz4rC4ef7cFCQvLlgCjw52QrU2F7UwNhqjB7JIhtNSmbcOsCWRYL8qv/KkLnTry0O7PL9gqXns0LldjPiDPoAT/a8JU1tujcjeNiyVoQaTaDA4hsk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741850292; c=relaxed/simple; bh=f8ZnW3oO3kWzj9xDjSgBVqOoaNahbzAF5dOy2Fh++kE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=oVorPt4uc3x1c08OM6oBTjNEcBSr2UO1F4Xs1BPCC3nQX7QVQTbjleldMw3OU7AZ5nQfnWmXGs7amE1aGCsoqWi5nUG5r51eVyj2R4YwPLEQ/rvSO96m9mRFc1QE2KD4MhHiCo9m5KAW5nNrBLP+l10tQtPLtbAql6WVGCu4Us4= 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=Zfb6fPLd; arc=none smtp.client-ip=209.85.208.178 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="Zfb6fPLd" Received: by mail-lj1-f178.google.com with SMTP id 38308e7fff4ca-30bf8f5dde5so6069751fa.2; Thu, 13 Mar 2025 00:18:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741850288; x=1742455088; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=S6OQ0UScw9oWVqgjbWQLTmLI2FDlmbWiio4NLFE3cNQ=; b=Zfb6fPLdyWsgy1t5Y/eO1r5/A06bq2hp8VOMJIU5fmNwt/B8Y8SeVl/9sQMqqd1zj0 VHDfDfkjxxZDxgvXzazHml91PErt1jn8HSDEpaqP/Wu8M5hXV9EVD7NZKLXp0oSdBab3 3R/ahYxMeSf6Zjwgln2uD3DX4Zd/pcl3tdFCR0MQPVFoYoZrMqtYNz/3ifLUNPtDEE7H bteRFVnT8QfeLE8nEltIHgj2umFlV91h8By9EiWm5wS4ooP4tstKkdS9TAWnBDZDo9xo /xUNJtR0uFQw8Rw3LnE7gawSbMl2S4jPrKOB6zD4YhECBxOoPrdkhvuG0v7VsvDbdCSK hj4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741850288; x=1742455088; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=S6OQ0UScw9oWVqgjbWQLTmLI2FDlmbWiio4NLFE3cNQ=; b=tzLAe3OW7xZQ8P6KHicmLhB0/cPei8msdiOqySh5mgJzCBN9EUjUU8N0fAf7JiRT09 h/EbaOLc58OX32m5zmd+YZk68nlGu3yaiKlNGDB908p3Jex6nknwC756UrSMYLlk/IAd o8n2w3zkG441JJ/f8mCBFKemSbugI9u2CnSRabWUNsAXBgm2dr2p91A8HPbHrvITgN8r BTLaTIP91uKB3J5nhHlUHqjlb5M71q5CsZ4ctwGpRcE+5T27uO0FFTBdDeHim/rPat74 SyhOgLF9zPwofftBF1N43oO6wBTxmLqvRaTEFDHzm6Zq1+tQVRf1lxv+w34vWxKCRK9v xDNA== X-Forwarded-Encrypted: i=1; AJvYcCUdkldFZTMi99oZoa8BNn5u8isniCS2PwsLQMYLhF5XmwjVMiykb3RTilHSK0X1Y8Kp1ZAE1BHojPIS@vger.kernel.org, AJvYcCUsNu88Q407USJEz9E0680I7sUZjlKmoykPLn82oEEGOSN1LxBx72EjF39bD8rfKMIjenh2P5uzbQ2pGZXH@vger.kernel.org, AJvYcCWOrQy7APWxJMyFW3XSNKtwMyCH0FLeV+gzMNyFuGa2dzJS6D55xRXfN7bVR0FrjXdnMlwF9tSk@vger.kernel.org, AJvYcCWiivILHNU8zeS0bDwS7OiqlcSqqBRqEW2/RyXoyRiqm9Lf9/iVSfFBWNPK+VqFIGrdAP3eXj4JuDAGgQ==@vger.kernel.org, AJvYcCX+azUwH93afWtLXG9nKsBSac7CI5VofXysAo+61HqCykWMc/+0vlVIInl7KTftM6Jhwiit78Z3++KV@vger.kernel.org X-Gm-Message-State: AOJu0Yw64XQeeDrxt3ytSp1VgVYwTmRyaryGT6GKtmlY+GhDWy/90R0P KNyL8QpihnKiKUtJ16Dam/Z+fYqwDQ88+MvwLcjeMpfrpjFVKeWe X-Gm-Gg: ASbGncv8SlMMltFNNhJN8DDFgYHU56z9L+R15QYgzliObLny+qon8UQEaWtV7YoSiZs zARsMY3V+RkS1is2o/KwhiN3vGeHW2EBjiLKlTazBPLFwRSIoUUBI9QCE7BQr79tzZAgHLNwwAI pyalNydcRSpsckR/8zfcMiXWdFzzfBbLhf2cV8l4KzYa/ogDUceQQ16W5a9QQOiTXunh5l0KyUE GSKYtpFUKw9HhWVMpiqkTQ2TXogdMf1OMhZ2pHkfW9IDVjYLRSybC+de4gaq98+XEp5Ble1BPT2 lL0a9/LtJ1LSeDqBC3hn/TiGEDqRirt78Kl/o+/QpSJfTTgLzBw= X-Google-Smtp-Source: AGHT+IHzZv16Eu3w2zLkjkG+6Z49HMA0c9ugl4Tm5n7/tbL2xQpVPA78kgBBEziTb7/bu9L9u95PWQ== X-Received: by 2002:a05:6512:3da3:b0:545:8a1:536e with SMTP id 2adb3069b0e04-54990e2be7bmr8687493e87.6.1741850288124; Thu, 13 Mar 2025 00:18:08 -0700 (PDT) Received: from mva-rohm ([2a10:a5c0:800d:dd00:8fdf:935a:2c85:d703]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-549ba885982sm117495e87.192.2025.03.13.00.18.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Mar 2025 00:18:05 -0700 (PDT) Date: Thu, 13 Mar 2025 09:18:00 +0200 From: Matti Vaittinen To: Matti Vaittinen , Matti Vaittinen Cc: Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Matti Vaittinen , Claudiu Manoil , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v7 02/10] property: Add functions to iterate named child Message-ID: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: There are a few use-cases where child nodes with a specific name need to be parsed. Code like: fwnode_for_each_child_node() if (fwnode_name_eq()) ... can be found from a various drivers/subsystems. Adding a macro for this can simplify things a bit. In a few cases the data from the found nodes is later added to an array, which is allocated based on the number of found nodes. One example of such use is the IIO subsystem's ADC channel nodes, where the relevant nodes are named as channel[@N]. Add helpers for iterating and counting device's sub-nodes with certain name instead of open-coding this in every user. Suggested-by: Jonathan Cameron Signed-off-by: Matti Vaittinen Reviewed-by: Andy Shevchenko --- Revision history: v6 => v7: - Improve kerneldoc - Inline device_get_named_child_node_count() and change it to call fwnode_get_named_child_node_count() inside - Fix indentiation of the new macros v5 => v6: - Add helpers to also iterate through the nodes. v4 => v5: - Use given name instead of string 'channel' when counting the nodes - Add also fwnode_get_child_node_count_named() as suggested by Rob. v3 => v4: - New patch as suggested by Jonathan, see discussion in: https://lore.kernel.org/lkml/20250223161338.5c896280@jic23-huawei/ --- drivers/base/property.c | 27 +++++++++++++++++++++++++++ include/linux/property.h | 24 ++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/drivers/base/property.c b/drivers/base/property.c index c1392743df9c..83fa0d0ee1f5 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -945,6 +945,33 @@ unsigned int device_get_child_node_count(const struct device *dev) } EXPORT_SYMBOL_GPL(device_get_child_node_count); +/** + * fwnode_get_named_child_node_count - number of child nodes with given name + * @fwnode: Node which child nodes are counted. + * @name: String to match child node name against. + * + * Scan child nodes and count all the nodes with a specific name. Potential + * 'number' -ending after the 'at sign' for scanned names is ignored. + * E.g.:: + * device_get_named_child_node_count(dev, "channel"); + * would match all the nodes:: + * channel { }, channel@0 {}, channel@0xabba {}... + * + * Return: the number of child nodes with a matching name for a given device. + */ +unsigned int fwnode_get_named_child_node_count(const struct fwnode_handle *fwnode, + const char *name) +{ + struct fwnode_handle *child; + unsigned int count = 0; + + fwnode_for_each_named_child_node(fwnode, child, name) + count++; + + return count; +} +EXPORT_SYMBOL_GPL(fwnode_get_named_child_node_count); + bool device_dma_supported(const struct device *dev) { return fwnode_call_bool_op(dev_fwnode(dev), device_dma_supported); diff --git a/include/linux/property.h b/include/linux/property.h index e214ecd241eb..7411dfdaadc0 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -167,10 +167,18 @@ struct fwnode_handle *fwnode_get_next_available_child_node( for (child = fwnode_get_next_child_node(fwnode, NULL); child; \ child = fwnode_get_next_child_node(fwnode, child)) +#define fwnode_for_each_named_child_node(fwnode, child, name) \ + fwnode_for_each_child_node(fwnode, child) \ + if (!fwnode_name_eq(child, name)) { } else + #define fwnode_for_each_available_child_node(fwnode, child) \ for (child = fwnode_get_next_available_child_node(fwnode, NULL); child;\ child = fwnode_get_next_available_child_node(fwnode, child)) +#define fwnode_for_each_available_named_child_node(fwnode, child, name) \ + fwnode_for_each_available_child_node(fwnode, child) \ + if (!fwnode_name_eq(child, name)) { } else + struct fwnode_handle *device_get_next_child_node(const struct device *dev, struct fwnode_handle *child); @@ -178,11 +186,19 @@ struct fwnode_handle *device_get_next_child_node(const struct device *dev, for (child = device_get_next_child_node(dev, NULL); child; \ child = device_get_next_child_node(dev, child)) +#define device_for_each_named_child_node(dev, child, name) \ + device_for_each_child_node(dev, child) \ + if (!fwnode_name_eq(child, name)) { } else + #define device_for_each_child_node_scoped(dev, child) \ for (struct fwnode_handle *child __free(fwnode_handle) = \ device_get_next_child_node(dev, NULL); \ child; child = device_get_next_child_node(dev, child)) +#define device_for_each_named_child_node_scoped(dev, child, name) \ + device_for_each_child_node_scoped(dev, child) \ + if (!fwnode_name_eq(child, name)) { } else + struct fwnode_handle *fwnode_get_named_child_node(const struct fwnode_handle *fwnode, const char *childname); struct fwnode_handle *device_get_named_child_node(const struct device *dev, @@ -210,6 +226,14 @@ int fwnode_irq_get_byname(const struct fwnode_handle *fwnode, const char *name); unsigned int device_get_child_node_count(const struct device *dev); +unsigned int fwnode_get_named_child_node_count(const struct fwnode_handle *fwnode, + const char *name); +static inline unsigned int device_get_named_child_node_count(const struct device *dev, + const char *name) +{ + return fwnode_get_named_child_node_count(dev_fwnode(dev), name); +} + static inline int device_property_read_u8(const struct device *dev, const char *propname, u8 *val) { From patchwork Thu Mar 13 07:20:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matti Vaittinen X-Patchwork-Id: 14014489 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.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 CB81C1FBE8C; Thu, 13 Mar 2025 07:20:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741850420; cv=none; b=YZ/bIMrmNdSMOQ3l1uuRz11aohm12ISZ7aLWF0qduid7PaO/TLs6x0swbq2Qwbg+DBSMulOpDdewnO5eCyj9xh8LQ5bJB05tXIIMyQeMOS0YYzs3/MCd80WFMW01wqI4xcHvsV67G8tN9qDJ/fVySnDYuegoVaeKCNX7MvKSRu4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741850420; c=relaxed/simple; bh=8+5R8oAkf2w0knV/jkn16g5f4JhtDgvTITUpMQVzAQM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=AFRZEU7l7baI3r9cm1r0Lm/SBrR6E113Kote7mzuN3HF/KV6N/BETYzLffnFJGZ0SkRuwQGuhPDf7jcCW9RsxWTCNVnvrBF7F0bPndfYhvFwKaRp4UgbgOMNeseZpPhG/ILmUPlTSrM0wWq3V8XCZ9+CRUDv78RlFA+ELHic8aQ= 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=TFAARaF2; arc=none smtp.client-ip=209.85.167.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="TFAARaF2" Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-54957f0c657so596071e87.0; Thu, 13 Mar 2025 00:20:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741850417; x=1742455217; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=3DI6EVYpCVvB4/qiCa4qjIWIjpDvbPkgz7MveeCW3mw=; b=TFAARaF2J4gp1tSsDYzTHHIHBFggJLRxOP/xoT3OdOC4BZQbvFOTzTmLvNVLHWjkYX tousdCXreQcYFj+YjsxEcwY0MoczJEVmFCjNiThJ5jmH922102ExavnixkozE7aQwiRc NeyTcTLNkPrC5Qot9JsNBwG/M/Sb04foo/O+U01lyWl7qUx5WprEvbXZT6/v4MWnz7cf NOYAkElkmPBrJa1Rzk+Stmz6Hy48SZR6jMT1kES15gjcCT4LflnkK+At0xT0JtZQJXCd wsmU/KBgNbGlb3QxzPswzBRflN0/7qGq1jFD+W1GL0MqMp5LeFo5GIca+hXfjmqb7Tvw 8m/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741850417; x=1742455217; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=3DI6EVYpCVvB4/qiCa4qjIWIjpDvbPkgz7MveeCW3mw=; b=C6Po9zTO1AdHP9YqgWCongIm5ztEMsPbuPmyUSZzIrBdvrJ7jftGY7yvhWRzWFFLC6 Pej/fTOtmCp6O2fwytVgfhSMjQCfe9i+ifC4BZ95JUSvuzhWHQ95emEko08TgdH/n6Qh wG9qMyQvG0M23+Y+ZvNoYqoLW/YHrF0k2C3EG32AsGBansqSXAnHnJrjqMDSqIAPjEII su9ytGg/LB9d+owt6cL6EL8tlrv5nm5G4e6FqUZDSWo/saWNH5Iw0wnbpNVybPUn+CQN fR2krbovEwhhn4QUDoIgH1u7AHG99hoFC3hVay/k3Nt1tKoF0RZY4yICuIwskbSOcuYR 8mqw== X-Forwarded-Encrypted: i=1; AJvYcCUxla5F1mQHU2MMKyDlJg88uaJHKCY5/423BDUqNuZtkhH7ZObSkrjvmwaSVD/njHp54T/uPV8g@vger.kernel.org, AJvYcCX9orGci0wuK4eqBHbwps2oB/Rkw9tzNeKJSXqCdTj2ewlzhA6Rj5EdytWpyNCy5+GVNDxQkmOeWvyHF4BG@vger.kernel.org, AJvYcCXoM8pmmA02beO9qWYlNAbMdA6WiNiBg/ayh3DBp0HvpqC8LZu1UtJeRiNXCXSkM26KGqGcdeEXHc6M@vger.kernel.org X-Gm-Message-State: AOJu0YzFXknmt5ExoB4jYx7TX5pFyoAoq1GnxgdweOIKT5A1oIYz1MVX ldXcwthyxboIjdooFMiLOSPGHKYz1C2/AU449B0wpJ4wK7A3K/Ap X-Gm-Gg: ASbGncv2278sJc1ZzTYEGA0aUlYMQID41zRhgijEoGldgxqABzsKgVd2cqwssNscSjT MY4eltNl8osCDPOGvmWyf7AZd4VEdVp6XAFUk32ELLuX0CCA2HeX9Djh73AUzAQkZYx9pxw4mMw SfqU6JWc8LuCID3NESHTgjh42oWsmZbJLx+55lHc6aRRWI+4iosx0rBjrN0HYngF9IkG+myO5Kh QO54/vtVcs372K0B8ubDR1aAiJzXpEdijH/1s+5L1FiRd0sGfwSqAO9E/fvgr5C9SfCZzU8YrpS 2mVO2roasalZoh92UBuYvylADRHDentlu8b4Snx643VcpcnY1Zg= X-Google-Smtp-Source: AGHT+IEvKiFXV8bl8B8NCAsPn4Q3j9WyAgKXI6XenFkBx9F27xE0i3dUdEtsIDU3jwE38eBjv4GKFQ== X-Received: by 2002:a05:6512:3a91:b0:545:81b:1516 with SMTP id 2adb3069b0e04-549ba402659mr516598e87.15.1741850416733; Thu, 13 Mar 2025 00:20:16 -0700 (PDT) Received: from mva-rohm ([2a10:a5c0:800d:dd00:8fdf:935a:2c85:d703]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-549ba864defsm119636e87.144.2025.03.13.00.20.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Mar 2025 00:20:14 -0700 (PDT) Date: Thu, 13 Mar 2025 09:20:10 +0200 From: Matti Vaittinen To: Matti Vaittinen , Matti Vaittinen Cc: Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Claudiu Manoil , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v7 net-next 09/10] net: gianfar: Use device_get_child_node_count_named() Message-ID: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Patchwork-Delegate: kuba@kernel.org We can avoid open-coding the loop construct which counts firmware child nodes with a specific name by using the newly added device_get_child_node_count_named(). The gianfar driver has such open-coded loop. Replace it with the device_get_child_node_count_named(). Suggested-by: Andy Shevchenko Signed-off-by: Matti Vaittinen Reviewed-by: Andy Shevchenko --- Revision history: v6 =>: - No changes v5 (RFC) => v6: - Drop RFC - Adapt to changed function name. It's fair to tell the pros and cons of this patch. The simplification is there, but it's not a big one. It comes with a cost of getting the property.h included in this driver which currently uses exclusively the of_* APIs. NOTE: This patch depends on the patch: [2/10] "property: Add functions to iterate named child" Compile-tested only! --- drivers/net/ethernet/freescale/gianfar.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/drivers/net/ethernet/freescale/gianfar.c b/drivers/net/ethernet/freescale/gianfar.c index 435138f4699d..d4ee0fc843be 100644 --- a/drivers/net/ethernet/freescale/gianfar.c +++ b/drivers/net/ethernet/freescale/gianfar.c @@ -97,6 +97,7 @@ #include #include #include +#include #include "gianfar.h" @@ -571,18 +572,6 @@ static int gfar_parse_group(struct device_node *np, return 0; } -static int gfar_of_group_count(struct device_node *np) -{ - struct device_node *child; - int num = 0; - - for_each_available_child_of_node(np, child) - if (of_node_name_eq(child, "queue-group")) - num++; - - return num; -} - /* Reads the controller's registers to determine what interface * connects it to the PHY. */ @@ -654,8 +643,10 @@ static int gfar_of_init(struct platform_device *ofdev, struct net_device **pdev) num_rx_qs = 1; } else { /* MQ_MG_MODE */ /* get the actual number of supported groups */ - unsigned int num_grps = gfar_of_group_count(np); + unsigned int num_grps; + num_grps = device_get_named_child_node_count(&ofdev->dev, + "queue-group"); if (num_grps == 0 || num_grps > MAXGROUPS) { dev_err(&ofdev->dev, "Invalid # of int groups(%d)\n", num_grps);