Netdev List
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: James Hilliard <james.hilliard1@gmail.com>
Cc: Rob Herring <robh@kernel.org>,
	Saravana Kannan <saravanak@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Danilo Krummrich <dakr@kernel.org>,
	Jonathan Corbet <corbet@lwn.net>,
	Shuah Khan <skhan@linuxfoundation.org>,
	Daniel Scally <djrscally@gmail.com>,
	Heikki Krogerus <heikki.krogerus@linux.intel.com>,
	Sakari Ailus <sakari.ailus@linux.intel.com>,
	Len Brown <lenb@kernel.org>, Andrew Lunn <andrew@lunn.ch>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	Russell King <linux@armlinux.org.uk>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Christian Marangi <ansuelsmth@gmail.com>,
	devicetree@vger.kernel.org, linux-doc@vger.kernel.org,
	linux-kernel@vger.kernel.org, driver-core@lists.linux.dev,
	linux-acpi@vger.kernel.org, netdev@vger.kernel.org
Subject: Re: [PATCH net-next v3 1/4] driver core: add fw_devlink supplier-copy helper
Date: Tue, 18 Aug 2026 10:30:04 +0300	[thread overview]
Message-ID: <aoQJ_Ixg9NkTm1aH@ashevche-desk.local> (raw)
In-Reply-To: <20260818-submit-phy-package-fwdevlink-v1-v3-1-40a905ea16b6@gmail.com>

On Tue, Aug 18, 2026 at 12:58:57AM -0600, James Hilliard wrote:
> Some firmware nodes describe resources shared by devices instantiated for
> their children, but the container node itself is never converted to a
> struct device. The firmware parser should retain the topology as
> described, while the framework which creates the children can identify
> the actual consumers.
> 
> Add fw_devlink_copy_suppliers() so such a framework can copy the direct
> supplier links from a container to a real consumer firmware node before
> the consumer is registered. The normal device_add() path then converts
> the copied dependencies into device links at the correct point in device
> registration.
> 
> Leave the source links in place for other children, suppress duplicate
> links and roll back newly allocated links if a copy fails. Skip ignored
> links and clear cycle flags on newly copied links, since cycle
> classification must be recomputed for the new consumer topology. Reject
> calls after the target firmware node has been associated with a device.
> Check that association while holding the fwnode-link lock so a
> concurrent device_add() either observes the copied links or makes the
> helper reject the request.

What is this paragraph about? The workflow?

> Add KUnit coverage for filtering, cycle-flag handling, idempotency, the
> pre-registration contract and conversion into an active device link.

...

> +int fw_devlink_copy_suppliers(struct fwnode_handle *to,
> +			      struct fwnode_handle *from)
> +{
> +	struct list_head *first;
> +	struct fwnode_link *link;
> +	int ret;
> +
> +	if (!to || !from)
> +		return -EINVAL;
> +	if (!fw_devlink_flags || to == from)
> +		return 0;

I think if to == NULL and from == NULL, it's fine to return 0.

	if (to == from)
		return 0;
	if (!to || !from)
		return -EINVAL;
	if (!fw_devlink_flags)
		return 0;

> +	fw_devlink_parse_fwnode(from);
> +
> +	guard(mutex)(&fwnode_link_lock);

+ blank line.

> +	if (READ_ONCE(to->dev))
> +		return -EBUSY;
> +
> +	first = to->suppliers.next;

No, we have list.h and APIs for a reason.

> +	list_for_each_entry(link, &from->suppliers, c_hook) {
> +		u8 flags = link->flags & ~FWLINK_FLAG_CYCLE;
> +
> +		if (flags & FWLINK_FLAG_IGNORE)
> +			continue;
> +
> +		ret = __fwnode_link_add(to, link->supplier, flags);
> +		if (ret)
> +			goto rollback;
> +	}
> +
> +	return 0;
> +
> +rollback:
> +	while (to->suppliers.next != first) {

Same here. I think the above and this needs to be thought through as this looks
like an AI shortcut without thinking of the existing APIs and possible different
(better) implementation.

> +		link = list_first_entry(&to->suppliers, struct fwnode_link,
> +					c_hook);
> +		__fwnode_link_del(link);
> +	}
> +
> +	return ret;
> +}

...

> +++ b/drivers/base/test/fwnode-link-test.c

> +#include <kunit/platform_device.h>
> +#include <kunit/test.h>
> +
> +#include <linux/device.h>
> +#include <linux/fwnode.h>

+ list.h

> +#include <linux/platform_device.h>
> +
> +#define FWNODE_LINK_TEST_DRIVER_NAME	"fwnode-link-test"
> +
> +struct fwnode_link_test_context {
> +	struct fwnode_handle consumer;
> +	struct fwnode_handle container;
> +	struct fwnode_handle supplier_a;
> +	struct fwnode_handle supplier_b;
> +};
> +
> +static int fwnode_link_test_probe(struct platform_device *pdev)
> +{
> +	return 0;
> +}
> +
> +static struct platform_driver fwnode_link_test_driver = {
> +	.probe = fwnode_link_test_probe,
> +	.driver = {
> +		.name = FWNODE_LINK_TEST_DRIVER_NAME,
> +	},
> +};
> +
> +static void fwnode_link_test_cleanup(void *data)
> +{
> +	struct fwnode_link_test_context *context = data;
> +
> +	fwnode_links_purge(&context->consumer);
> +	fwnode_links_purge(&context->container);
> +	fwnode_links_purge(&context->supplier_a);
> +	fwnode_links_purge(&context->supplier_b);
> +}
> +
> +static struct fwnode_link_test_context *
> +fwnode_link_test_init(struct kunit *test)
> +{
> +	struct fwnode_link_test_context *context;
> +	int ret;
> +
> +	context = kunit_kzalloc(test, sizeof(*context), GFP_KERNEL);
> +	KUNIT_ASSERT_NOT_NULL(test, context);
> +
> +	fwnode_init(&context->consumer, NULL);
> +	fwnode_init(&context->container, NULL);
> +	fwnode_init(&context->supplier_a, NULL);
> +	fwnode_init(&context->supplier_b, NULL);
> +	ret = kunit_add_action_or_reset(test, fwnode_link_test_cleanup,
> +					context);
> +	KUNIT_ASSERT_EQ(test, ret, 0);
> +
> +	return context;
> +}
> +
> +static struct platform_device *
> +fwnode_link_test_register_pdev(struct kunit *test,
> +			       struct fwnode_handle *fwnode)
> +{
> +	struct platform_device *pdev;
> +	int ret;
> +
> +	pdev = kunit_platform_device_alloc(test, FWNODE_LINK_TEST_DRIVER_NAME,
> +					   PLATFORM_DEVID_AUTO);
> +	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pdev);
> +
> +	device_set_node(&pdev->dev, fwnode);
> +	ret = kunit_platform_device_add(test, pdev);
> +	if (ret) {
> +		KUNIT_FAIL(test, "failed to register platform device: %d", ret);
> +		return NULL;
> +	}
> +
> +	return pdev;
> +}
> +
> +static unsigned int fwnode_supplier_count(struct fwnode_handle *fwnode)
> +{
> +	struct fwnode_link *link;
> +	unsigned int count = 0;
> +
> +	list_for_each_entry(link, &fwnode->suppliers, c_hook)
> +		count++;

We have an existing API for this. I recommend to stop using AI for a moment
and just read the existing code thoroughly (list.h) and see what we have
in the kernel.

> +	return count;
> +}

...

> --- a/include/linux/fwnode.h
> +++ b/include/linux/fwnode.h

> +int fw_devlink_copy_suppliers(struct fwnode_handle *to,
> +			      struct fwnode_handle *from);
>  bool fw_devlink_is_strict(void);

It might be better to split a test into a separate patch. But I don't care
about this much.

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2026-08-18  7:30 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-18  6:58 [PATCH net-next v3 0/4] driver core, net: handle fw_devlink for class devices and PHY packages James Hilliard
2026-08-18  6:58 ` [PATCH net-next v3 1/4] driver core: add fw_devlink supplier-copy helper James Hilliard
2026-08-18  7:30   ` Andy Shevchenko [this message]
2026-08-18  6:58 ` [PATCH net-next v3 2/4] net: mdio: link PHY package suppliers to member PHYs James Hilliard
2026-08-18  7:39   ` Andy Shevchenko
2026-08-18  6:58 ` [PATCH net-next v3 3/4] net: mdio: defer supplier sync during OF population James Hilliard
2026-08-18  6:59 ` [PATCH net-next v3 4/4] driver core: handle managed links for class devices James Hilliard
2026-08-18  7:48   ` Andy Shevchenko
2026-08-18  7:15 ` [PATCH net-next v3 0/4] driver core, net: handle fw_devlink for class devices and PHY packages Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aoQJ_Ixg9NkTm1aH@ashevche-desk.local \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=andrew@lunn.ch \
    --cc=ansuelsmth@gmail.com \
    --cc=corbet@lwn.net \
    --cc=dakr@kernel.org \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=djrscally@gmail.com \
    --cc=driver-core@lists.linux.dev \
    --cc=edumazet@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=hkallweit1@gmail.com \
    --cc=james.hilliard1@gmail.com \
    --cc=kuba@kernel.org \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=rafael@kernel.org \
    --cc=robh@kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    --cc=saravanak@kernel.org \
    --cc=skhan@linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox