Re: [PATCH] appletalk: Correctly handle return value of register_snap_client

From: David Miller
Date: Wed Mar 06 2019 - 13:17:44 EST


From: Yue Haibing <yuehaibing@xxxxxxxxxx>
Date: Wed, 6 Mar 2019 15:27:40 +0800

> @@ -879,15 +879,17 @@ static struct notifier_block aarp_notifier = {
>
> static unsigned char aarp_snap_id[] = { 0x00, 0x00, 0x00, 0x80, 0xF3 };
>
> -void __init aarp_proto_init(void)
> +int __init aarp_proto_init(void)
> {
> aarp_dl = register_snap_client(aarp_snap_id, aarp_rcv);
> - if (!aarp_dl)
> - printk(KERN_CRIT "Unable to register AARP with SNAP.\n");
> + if (!aarp_dl) {
> + pr_crit("Unable to register AARP with SNAP.\n");
> + return -ENOMEM;
> + }
> timer_setup(&aarp_timer, aarp_expire_timeout, 0);
> aarp_timer.expires = jiffies + sysctl_aarp_expiry_time;
> add_timer(&aarp_timer);
> - register_netdevice_notifier(&aarp_notifier);
> + return register_netdevice_notifier(&aarp_notifier);
> }
>

Your error paths in the caller of aarp_proto_init() do not handle the case
where aarp_dl is created by register_netdevice_notifier() fails. You have
to unregister aarp_dl if it is non-NULL.

So your out_dev label path needs to handle aarp_dl if non-NULL.

Probably best is to jump to out_aarp: instead and make aarp_cleanup_module
able to handle partial cleanups.