All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oliver Hartkopp <socketcan@hartkopp.net>
To: YueHaibing <yuehaibing@huawei.com>,
	davem@davemloft.net, mkl@pengutronix.de
Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
	linux-can@vger.kernel.org
Subject: Re: [PATCH] can: gw: Fix error path of cgw_module_init
Date: Thu, 16 May 2019 18:24:40 +0200	[thread overview]
Message-ID: <5e833f8b-537b-f4b0-4d7d-489936026cca@hartkopp.net> (raw)
In-Reply-To: <20190516155435.42376-1-yuehaibing@huawei.com>



On 16.05.19 17:54, YueHaibing wrote:
> This patch fix error path for cgw_module_init
> to avoid possible crash if some error occurs.
> 
> Fixes: c1aabdf379bc ("can-gw: add netlink based CAN routing")
> Signed-off-by: YueHaibing <yuehaibing@huawei.com>

Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>

Thanks!

> ---
>   net/can/gw.c | 46 +++++++++++++++++++++++++++++++---------------
>   1 file changed, 31 insertions(+), 15 deletions(-)
> 
> diff --git a/net/can/gw.c b/net/can/gw.c
> index 53859346..8b53ec7 100644
> --- a/net/can/gw.c
> +++ b/net/can/gw.c
> @@ -1046,32 +1046,48 @@ static __init int cgw_module_init(void)
>   	pr_info("can: netlink gateway (rev " CAN_GW_VERSION ") max_hops=%d\n",
>   		max_hops);
>   
> -	register_pernet_subsys(&cangw_pernet_ops);
> +	ret = register_pernet_subsys(&cangw_pernet_ops);
> +	if (ret)
> +		return ret;
> +
> +	ret = -ENOMEM;
>   	cgw_cache = kmem_cache_create("can_gw", sizeof(struct cgw_job),
>   				      0, 0, NULL);
> -
>   	if (!cgw_cache)
> -		return -ENOMEM;
> +		goto out_cache_create;
>   
>   	/* set notifier */
>   	notifier.notifier_call = cgw_notifier;
> -	register_netdevice_notifier(&notifier);
> +	ret = register_netdevice_notifier(&notifier);
> +	if (ret)
> +		goto out_register_notifier;
>   
>   	ret = rtnl_register_module(THIS_MODULE, PF_CAN, RTM_GETROUTE,
>   				   NULL, cgw_dump_jobs, 0);
> -	if (ret) {
> -		unregister_netdevice_notifier(&notifier);
> -		kmem_cache_destroy(cgw_cache);
> -		return -ENOBUFS;
> -	}
> -
> -	/* Only the first call to rtnl_register_module can fail */
> -	rtnl_register_module(THIS_MODULE, PF_CAN, RTM_NEWROUTE,
> -			     cgw_create_job, NULL, 0);
> -	rtnl_register_module(THIS_MODULE, PF_CAN, RTM_DELROUTE,
> -			     cgw_remove_job, NULL, 0);
> +	if (ret)
> +		goto out_rtnl_register1;
> +
> +	ret = rtnl_register_module(THIS_MODULE, PF_CAN, RTM_NEWROUTE,
> +				   cgw_create_job, NULL, 0);
> +	if (ret)
> +		goto out_rtnl_register2;
> +	ret = rtnl_register_module(THIS_MODULE, PF_CAN, RTM_DELROUTE,
> +				   cgw_remove_job, NULL, 0);
> +	if (ret)
> +		goto out_rtnl_register2;
>   
>   	return 0;
> +
> +out_rtnl_register2:
> +	rtnl_unregister_all(PF_CAN);
> +out_rtnl_register1:
> +	unregister_netdevice_notifier(&notifier);
> +out_register_notifier:
> +	kmem_cache_destroy(cgw_cache);
> +out_cache_create:
> +	unregister_pernet_subsys(&cangw_pernet_ops);
> +
> +	return ret;
>   }
>   
>   static __exit void cgw_module_exit(void)
> 

  reply	other threads:[~2019-05-16 16:24 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-16 15:54 [PATCH] can: gw: Fix error path of cgw_module_init YueHaibing
2019-05-16 15:54 ` YueHaibing
2019-05-16 16:24 ` Oliver Hartkopp [this message]
2019-05-17 10:40 ` Marc Kleine-Budde
2019-05-18  9:35   ` [PATCH v2] " YueHaibing
2019-05-18  9:35     ` YueHaibing

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5e833f8b-537b-f4b0-4d7d-489936026cca@hartkopp.net \
    --to=socketcan@hartkopp.net \
    --cc=davem@davemloft.net \
    --cc=linux-can@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=netdev@vger.kernel.org \
    --cc=yuehaibing@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.