Subject: Re: [PATCH v14 net-next 3/5] psp: add a new netdev event for dev unregister

From: Jakub Kicinski <[email-masked]>
Date: Wed, 13 May 2026 18:41:55 -0700

On Thu,  7 May 2026 21:26:08 -0700 Wei Wang wrote:
> +static int psp_netdev_event(struct notifier_block *nb, unsigned long event,
> +			    void *ptr)
> +{
> +	struct net_device *dev = netdev_notifier_info_to_dev(ptr);
> +	struct psp_dev *psd;
> +
> +	if (event != NETDEV_UNREGISTER)
> +		return NOTIFY_DONE;
> +
> +	rcu_read_lock();
> +	psd = rcu_dereference(dev->psp_dev);
> +	if (psd && psp_dev_tryget(psd)) {
> +		rcu_read_unlock();
> +		mutex_lock(&psd->lock);

Let's check here if psp_dev_is_registered(psd) before
calling the notify. The list should be empty on a dead device
so psp_dev_disassoc_one() is fine, but it will be easy to forget
and add some code that doesn't expect dead devices in notify.

> +		psp_nl_notify_dev(psd, PSP_CMD_DEV_CHANGE_NTF);
> +		psp_dev_disassoc_one(psd, dev);
> +		mutex_unlock(&psd->lock);
> +		psp_dev_put(psd);
> +	} else {
> +		rcu_read_unlock();
> +	}
> +
> +	return NOTIFY_DONE;
> +}
> +
> +static struct notifier_block psp_netdev_notifier = {
> +	.notifier_call = psp_netdev_event,
> +};
> +
> +static DEFINE_MUTEX(psp_notifier_lock);
> +static bool psp_notifier_registered;
> +
> +/*
> + * psp_attach_netdev_notifier() - register netdev notifier on first use
> + *
> + * Register the netdevice notifier when the first device association
> + * is created. In many installations no associations will be created and
> + * the notifier won't be needed.
> + *
> + * Must be called without psd->lock held, due to lock ordering:
> + * rtnl_lock -> psd->lock (the notifier callback runs under rtnl_lock
> + * and takes psd->lock).
> + */

This is so almost kdoc :) Either remove the top line with the function
name, or add Returns: and make it a real kdoc (slight preference towards
former)

> +int psp_attach_netdev_notifier(void)