mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Re: 回复: Re: [PATCH net v2] phonet: check register_netdevice_notifier() error in phonet_device_init()
       [not found] <3v5ygapsdjgl-3v61zwni6m6e@nsmail8.2--kylin--1>
@ 2026-07-17 13:56 ` Andrew Lunn
  0 siblings, 0 replies; only message in thread
From: Andrew Lunn @ 2026-07-17 13:56 UTC (permalink / raw)
  To: 何敏红
  Cc: courmisch, davem, edumazet, kuba, pabeni, horms,
	remi.denis-courmont, netdev, linux-kernel

On Fri, Jul 17, 2026 at 02:55:54PM +0800, 何敏红 wrote:
>  
> 
> Hi Andrew,
> 
> Thanks for the review.
> 
> > Think about what happens when phonet_netlink_register() fails.
> 
> I checked that path. By the time phonet_netlink_register() runs,
> pernet, the proc entry and the netdevice notifier have all been
> registered successfully. On failure, rtnl_register_many() already
> unwinds any partially registered handlers, and phonet_device_exit()
> then tears down the notifier/pernet/proc that were set up. So this is
> not the same issue as calling unregister_netdevice_notifier() for a
> notifier that never got registered.

int __init phonet_device_init(void)
{
        int err = register_pernet_subsys(&phonet_net_ops);
        if (err)
                return err;

        proc_create_net("pnresource", 0, init_net.proc_net, &pn_res_seq_ops,
                        sizeof(struct seq_net_private));
        register_netdevice_notifier(&phonet_device_notifier);
        err = phonet_netlink_register();
        if (err)
                phonet_device_exit();

If we get here, phonet_netlink_register() failed.

What exactly does phonet_netlink_register() do:

int __init phonet_netlink_register(void)
{
	return rtnl_register_many(phonet_rtnl_msg_handlers);
}

And what does phonet_device_exit() do?

void phonet_device_exit(void)
{
        rtnl_unregister_all(PF_PHONET);
        unregister_netdevice_notifier(&phonet_device_notifier);
        unregister_pernet_subsys(&phonet_net_ops);
        remove_proc_entry("pnresource", init_net.proc_net);
}

So it tries to unregister something which was not registered. That is
generally a bad idea.

The general pattern in the Linux kernel is that on error, you
carefully unwind everything which succeeded so far. Often you do that
at the end, with a series of goto statements and labels.

Calling the "mirror" function on error does not work, since that
function assumes everything went correctly in its peer.

	Andrew

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-07-17 13:57 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <3v5ygapsdjgl-3v61zwni6m6e@nsmail8.2--kylin--1>
2026-07-17 13:56 ` 回复: Re: [PATCH net v2] phonet: check register_netdevice_notifier() error in phonet_device_init() Andrew Lunn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®