Re: [PATCH] appletalk: Correctly handle return value of register_snap_client
From: YueHaibing
Date:  Wed Mar 06 2019 - 21:09:32 EST
On 2019/3/7 2:17, David Miller wrote:
> 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.
Thanks, will fix this.
> 
> 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.
> 
> .
>