On 2024-05-30 at 15:00:40, D. Wythe (alibuda@xxxxxxxxxxxxxxxxx) wrote: > From: "D. Wythe" <alibuda@xxxxxxxxxxxxxxxxx> > > + > +int __init smc_inet_init(void) > +{ > + int rc; > + > + rc = proto_register(&smc_inet_prot, 1); > + if (rc) { > + pr_err("%s: proto_register smc_inet_prot fails with %d\n", __func__, rc); > + return rc; > + } > + /* no return value */ > + inet_register_protosw(&smc_inet_protosw); > + > +#if IS_ENABLED(CONFIG_IPV6) > + rc = proto_register(&smc_inet6_prot, 1); > + if (rc) { > + pr_err("%s: proto_register smc_inet6_prot fails with %d\n", __func__, rc); > + goto out_inet6_prot; > + } > + rc = inet6_register_protosw(&smc_inet6_protosw); > + if (rc) { > + pr_err("%s: inet6_register_protosw smc_inet6_protosw fails with %d\n", > + __func__, rc); > + goto out_inet6_protosw; > + } > +#endif /* CONFIG_IPV6 */ > + > + return rc; > +#if IS_ENABLED(CONFIG_IPV6) Can you combine this #if with above one ? Any way you need this only in case of ipv6. Error handling with #if is an hindrance to a good readability. > +out_inet6_protosw: > + proto_unregister(&smc_inet6_prot); > +out_inet6_prot: > + inet_unregister_protosw(&smc_inet_protosw); > + proto_unregister(&smc_inet_prot); > + return rc; > +#endif /* CONFIG_IPV6 */ > +} > + > +void smc_inet_exit(void) > +{ > +#if IS_ENABLED(CONFIG_IPV6) > + inet6_unregister_protosw(&smc_inet6_protosw); > + proto_unregister(&smc_inet6_prot); > +#endif /* CONFIG_IPV6 */ > + inet_unregister_protosw(&smc_inet_protosw); > + proto_unregister(&smc_inet_prot); > +} > diff --git a/net/smc/smc_inet.h b/net/smc/smc_inet.h > new file mode 100644 > index 00000000..a489c8a > --- /dev/null > +++ b/net/smc/smc_inet.h > @@ -0,0 +1,22 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +/* > + * Shared Memory Communications over RDMA (SMC-R) and RoCE > + * > + * Definitions for the IPPROTO_SMC (socket related) > + > + * Copyright IBM Corp. 2016 > + * Copyright (c) 2024, Alibaba Inc. > + * > + * Author: D. Wythe <alibuda@xxxxxxxxxxxxxxxxx> > + */ > +#ifndef __INET_SMC > +#define __INET_SMC > + > +/* Initialize protocol registration on IPPROTO_SMC, > + * @return 0 on success > + */ > +int smc_inet_init(void); > + > +void smc_inet_exit(void); > + > +#endif /* __INET_SMC */ > -- > 1.8.3.1 >