tls: use fixed size for tls_offload_context_{tx,rx}.driver_state
authorSabrina Dubroca <sd@queasysnail.net>
Mon, 9 Oct 2023 20:50:54 +0000 (22:50 +0200)
committerDavid S. Miller <davem@davemloft.net>
Fri, 13 Oct 2023 10:26:10 +0000 (11:26 +0100)
driver_state is a flex array, but is always allocated by the tls core
to a fixed size (TLS_DRIVER_STATE_SIZE_{TX,RX}). Simplify the code by
making that size explicit so that sizeof(struct
tls_offload_context_{tx,rx}) works.

Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/tls.h
net/tls/tls_device.c

index 28cc40d7b9451193a80a38f4fd5858eb47d1ebeb..962f0c501111bac34781c4419913540c162ea058 100644 (file)
@@ -150,6 +150,7 @@ struct tls_record_info {
        skb_frag_t frags[MAX_SKB_FRAGS];
 };
 
+#define TLS_DRIVER_STATE_SIZE_TX       16
 struct tls_offload_context_tx {
        struct crypto_aead *aead_send;
        spinlock_t lock;        /* protects records list */
@@ -163,17 +164,13 @@ struct tls_offload_context_tx {
        void (*sk_destruct)(struct sock *sk);
        struct work_struct destruct_work;
        struct tls_context *ctx;
-       u8 driver_state[] __aligned(8);
        /* The TLS layer reserves room for driver specific state
         * Currently the belief is that there is not enough
         * driver specific state to justify another layer of indirection
         */
-#define TLS_DRIVER_STATE_SIZE_TX       16
+       u8 driver_state[TLS_DRIVER_STATE_SIZE_TX] __aligned(8);
 };
 
-#define TLS_OFFLOAD_CONTEXT_SIZE_TX                                            \
-       (sizeof(struct tls_offload_context_tx) + TLS_DRIVER_STATE_SIZE_TX)
-
 enum tls_context_flags {
        /* tls_device_down was called after the netdev went down, device state
         * was released, and kTLS works in software, even though rx_conf is
@@ -303,6 +300,7 @@ struct tls_offload_resync_async {
        u32 log[TLS_DEVICE_RESYNC_ASYNC_LOGMAX];
 };
 
+#define TLS_DRIVER_STATE_SIZE_RX       8
 struct tls_offload_context_rx {
        /* sw must be the first member of tls_offload_context_rx */
        struct tls_sw_context_rx sw;
@@ -326,17 +324,13 @@ struct tls_offload_context_rx {
                        struct tls_offload_resync_async *resync_async;
                };
        };
-       u8 driver_state[] __aligned(8);
        /* The TLS layer reserves room for driver specific state
         * Currently the belief is that there is not enough
         * driver specific state to justify another layer of indirection
         */
-#define TLS_DRIVER_STATE_SIZE_RX       8
+       u8 driver_state[TLS_DRIVER_STATE_SIZE_RX] __aligned(8);
 };
 
-#define TLS_OFFLOAD_CONTEXT_SIZE_RX                                    \
-       (sizeof(struct tls_offload_context_rx) + TLS_DRIVER_STATE_SIZE_RX)
-
 struct tls_record_info *tls_get_record(struct tls_offload_context_tx *context,
                                       u32 seq, u64 *p_record_sn);
 
index fe52765beaee29a8a0a34256bf6c2d753ee070a0..f01543557a60692436e1ee61eb90191032a2ddb6 100644 (file)
@@ -1038,7 +1038,7 @@ static struct tls_offload_context_tx *alloc_offload_ctx_tx(struct tls_context *c
        struct tls_offload_context_tx *offload_ctx;
        __be64 rcd_sn;
 
-       offload_ctx = kzalloc(TLS_OFFLOAD_CONTEXT_SIZE_TX, GFP_KERNEL);
+       offload_ctx = kzalloc(sizeof(*offload_ctx), GFP_KERNEL);
        if (!offload_ctx)
                return NULL;
 
@@ -1225,7 +1225,7 @@ int tls_set_device_offload_rx(struct sock *sk, struct tls_context *ctx)
                goto release_lock;
        }
 
-       context = kzalloc(TLS_OFFLOAD_CONTEXT_SIZE_RX, GFP_KERNEL);
+       context = kzalloc(sizeof(*context), GFP_KERNEL);
        if (!context) {
                rc = -ENOMEM;
                goto release_lock;