[Openvpn-devel] ovpn-dco: fix kernel 6.1 compile issue in ovpn_peer_create

Message ID 20221022061619.3923529-1-git@johnthomson.fastmail.com.au
State Changes Requested
Headers show
Series [Openvpn-devel] ovpn-dco: fix kernel 6.1 compile issue in ovpn_peer_create | expand

Commit Message

John Thomson Oct. 21, 2022, 7:16 p.m. UTC
Linux 5.19 replaces netif_tx_napi_add, but maintains a definition to the
new function in: 58caed3dacb4 ("netdev: reshuffle netif_napi_add() APIs
to allow dropping weigh") [0]

Linux 6.1 removes netif_tx_napi_add in c3f760ef1287 ("net: remove
netif_tx_napi_add()") [1]

[0]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=58caed3dacb4354a25a1aa8d2febc3e9648ba1f4
[1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=c3f760ef128789252e7c4f10d3c1721422dceba9

Signed-off-by: John Thomson <git@johnthomson.fastmail.com.au>
---
compile test only, on kernel 6.1rc1
---
 drivers/net/ovpn-dco/peer.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Antonio Quartulli Oct. 21, 2022, 8:01 p.m. UTC | #1
Hi John,

Thanks a lot for your contribution!

However, we can't have #ifs like that in the middle of the code, as this 
code is expected to go upstream (and #ifs on the kernel version are not 
allowed).

The code should always work with the latest kernel version, while any 
magic compatibility trick should be hidden in compat.h (i.e. implement 
netif_napi_add_tx() so that it calls netif_tx_napi_add(..., 
NAPI_POLL_WEIGHT)).

Cheers,

On 22/10/2022 08:16, John Thomson wrote:
> Linux 5.19 replaces netif_tx_napi_add, but maintains a definition to the
> new function in: 58caed3dacb4 ("netdev: reshuffle netif_napi_add() APIs
> to allow dropping weigh") [0]
> 
> Linux 6.1 removes netif_tx_napi_add in c3f760ef1287 ("net: remove
> netif_tx_napi_add()") [1]
> 
> [0]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=58caed3dacb4354a25a1aa8d2febc3e9648ba1f4
> [1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=c3f760ef128789252e7c4f10d3c1721422dceba9
> 
> Signed-off-by: John Thomson <git@johnthomson.fastmail.com.au>
> ---
> compile test only, on kernel 6.1rc1
> ---
>   drivers/net/ovpn-dco/peer.c | 4 ++++
>   1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/net/ovpn-dco/peer.c b/drivers/net/ovpn-dco/peer.c
> index 5838286..c460976 100644
> --- a/drivers/net/ovpn-dco/peer.c
> +++ b/drivers/net/ovpn-dco/peer.c
> @@ -88,8 +88,12 @@ static struct ovpn_peer *ovpn_peer_create(struct ovpn_struct *ovpn, u32 id)
>   	}
>   
>   	/* configure and start NAPI */
> +#if(LINUX_VERSION_CODE < KERNEL_VERSION(5,19,0))
>   	netif_tx_napi_add(ovpn->dev, &peer->napi, ovpn_napi_poll,
>   			  NAPI_POLL_WEIGHT);
> +#else
> +	netif_napi_add_tx(ovpn->dev, &peer->napi, ovpn_napi_poll);
> +#endif
>   	napi_enable(&peer->napi);
>   
>   	dev_hold(ovpn->dev);

Patch

diff --git a/drivers/net/ovpn-dco/peer.c b/drivers/net/ovpn-dco/peer.c
index 5838286..c460976 100644
--- a/drivers/net/ovpn-dco/peer.c
+++ b/drivers/net/ovpn-dco/peer.c
@@ -88,8 +88,12 @@  static struct ovpn_peer *ovpn_peer_create(struct ovpn_struct *ovpn, u32 id)
 	}
 
 	/* configure and start NAPI */
+#if(LINUX_VERSION_CODE < KERNEL_VERSION(5,19,0))
 	netif_tx_napi_add(ovpn->dev, &peer->napi, ovpn_napi_poll,
 			  NAPI_POLL_WEIGHT);
+#else
+	netif_napi_add_tx(ovpn->dev, &peer->napi, ovpn_napi_poll);
+#endif
 	napi_enable(&peer->napi);
 
 	dev_hold(ovpn->dev);