Re: [PATCH 1/2] netxen: unregister notifiers if PCI registration fails

From: Jacob Keller

Date: Wed Jul 29 2026 - 19:11:07 EST


On 7/27/2026 8:20 PM, Can Peng wrote:
> netxen_init_module() registers the netdevice and inetaddr notifiers before
> registering the PCI driver. If pci_register_driver() fails, the function
> returns the error directly and leaves both notifiers registered.
>

I'm curious why it registers the netdevice and inetaddr notifiers first
before the PCI driver? I guess it doesn't really matter which order but
you'd want to change the teardown order in remove if you switched it.
> That leaves notifier callbacks installed for a module that failed to load.
> Mirror the module exit path on this failure and unregister the notifiers
> before returning the error.
>
> Fixes: 6598b169b856 ("netxen: enable ip addr hashing")
> Signed-off-by: Can Peng <pengcan@xxxxxxxxxx>
> ---

Reviewed-by: Jacob Keller <jacob.e.keller@xxxxxxxxx>

> .../net/ethernet/qlogic/netxen/netxen_nic_main.c | 13 ++++++++++++-
> 1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c b/drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c
> index 5ee2bd9d6886..67d9bf69f8f2 100644
> --- a/drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c
> +++ b/drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c
> @@ -3447,13 +3447,24 @@ static struct pci_driver netxen_driver = {
>
> static int __init netxen_init_module(void)
> {
> + int ret;
> +
> printk(KERN_INFO "%s\n", netxen_nic_driver_string);
>
> #ifdef CONFIG_INET
> register_netdevice_notifier(&netxen_netdev_cb);
> register_inetaddr_notifier(&netxen_inetaddr_cb);
> #endif
> - return pci_register_driver(&netxen_driver);
> +
> + ret = pci_register_driver(&netxen_driver);
> +#ifdef CONFIG_INET
> + if (ret) {
> + unregister_inetaddr_notifier(&netxen_inetaddr_cb);
> + unregister_netdevice_notifier(&netxen_netdev_cb);
> + }
> +#endif

Normally i'd suggest a goto cleanup error pattern, but this is a small
function without much worth to do that.

Reviewed-by: Jacob Keller <jacob.e.keller@xxxxxxxxx>

> +
> + return ret;
> }
>
> module_init(netxen_init_module);