On 10/11/2024 19:26, Sergey Ryazanov wrote:
On 29.10.2024 12:47, Antonio Quartulli wrote:
+static bool ovpn_socket_hold(struct ovpn_socket *sock)
+{
+ return kref_get_unless_zero(&sock->refcount);
Why do we need to wrap this kref acquiring call into the function. Why we cannot simply call kref_get_unless_zero() from ovpn_socket_get()?
Generally I prefer to keep the API among objects consistent.
In this specific case, it means having hold() and put() helpers in order to avoid calling kref_* functions directly in the code.
This is a pretty simple case because hold() is called only once, but I still like to be consistent.
+int ovpn_udp_socket_attach(struct socket *sock, struct ovpn_struct *ovpn)
+{
+ struct ovpn_socket *old_data;
+ int ret = 0;
+
+ /* sanity check */
+ if (sock->sk->sk_protocol != IPPROTO_UDP) {
The function will be called only for a UDP socket. The caller makes sure this is truth. So, why do we need this check?
To avoid this function being copied/called somewhere else in the future and we forget about this critical assumption.
Indeed it's a just sanity check.
+ DEBUG_NET_WARN_ON_ONCE(1);
+ return -EINVAL;
+ }