@@ -424,18 +424,18 @@ void xfrm_unregister_type_offload(const struct xfrm_type_offload *type,
424424}
425425EXPORT_SYMBOL (xfrm_unregister_type_offload );
426426
427- static const struct xfrm_type_offload *
428- xfrm_get_type_offload (u8 proto , unsigned short family , bool try_load )
427+ void xfrm_set_type_offload (struct xfrm_state * x )
429428{
430429 const struct xfrm_type_offload * type = NULL ;
431430 struct xfrm_state_afinfo * afinfo ;
431+ bool try_load = true;
432432
433433retry :
434- afinfo = xfrm_state_get_afinfo (family );
434+ afinfo = xfrm_state_get_afinfo (x -> props . family );
435435 if (unlikely (afinfo == NULL ))
436- return NULL ;
436+ goto out ;
437437
438- switch (proto ) {
438+ switch (x -> id . proto ) {
439439 case IPPROTO_ESP :
440440 type = afinfo -> type_offload_esp ;
441441 break ;
@@ -449,18 +449,16 @@ xfrm_get_type_offload(u8 proto, unsigned short family, bool try_load)
449449 rcu_read_unlock ();
450450
451451 if (!type && try_load ) {
452- request_module ("xfrm-offload-%d-%d" , family , proto );
452+ request_module ("xfrm-offload-%d-%d" , x -> props .family ,
453+ x -> id .proto );
453454 try_load = false;
454455 goto retry ;
455456 }
456457
457- return type ;
458- }
459-
460- static void xfrm_put_type_offload (const struct xfrm_type_offload * type )
461- {
462- module_put (type -> owner );
458+ out :
459+ x -> type_offload = type ;
463460}
461+ EXPORT_SYMBOL (xfrm_set_type_offload );
464462
465463static const struct xfrm_mode xfrm4_mode_map [XFRM_MODE_MAX ] = {
466464 [XFRM_MODE_BEET ] = {
@@ -609,8 +607,6 @@ static void ___xfrm_state_destroy(struct xfrm_state *x)
609607 kfree (x -> coaddr );
610608 kfree (x -> replay_esn );
611609 kfree (x -> preplay_esn );
612- if (x -> type_offload )
613- xfrm_put_type_offload (x -> type_offload );
614610 if (x -> type ) {
615611 x -> type -> destructor (x );
616612 xfrm_put_type (x -> type );
@@ -784,6 +780,8 @@ void xfrm_dev_state_free(struct xfrm_state *x)
784780 struct xfrm_dev_offload * xso = & x -> xso ;
785781 struct net_device * dev = READ_ONCE (xso -> dev );
786782
783+ xfrm_unset_type_offload (x );
784+
787785 if (dev && dev -> xfrmdev_ops ) {
788786 spin_lock_bh (& xfrm_state_dev_gc_lock );
789787 if (!hlist_unhashed (& x -> dev_gclist ))
@@ -3122,7 +3120,7 @@ u32 xfrm_state_mtu(struct xfrm_state *x, int mtu)
31223120}
31233121EXPORT_SYMBOL_GPL (xfrm_state_mtu );
31243122
3125- int __xfrm_init_state (struct xfrm_state * x , bool init_replay , bool offload ,
3123+ int __xfrm_init_state (struct xfrm_state * x , bool init_replay ,
31263124 struct netlink_ext_ack * extack )
31273125{
31283126 const struct xfrm_mode * inner_mode ;
@@ -3178,8 +3176,6 @@ int __xfrm_init_state(struct xfrm_state *x, bool init_replay, bool offload,
31783176 goto error ;
31793177 }
31803178
3181- x -> type_offload = xfrm_get_type_offload (x -> id .proto , family , offload );
3182-
31833179 err = x -> type -> init_state (x , extack );
31843180 if (err )
31853181 goto error ;
@@ -3229,7 +3225,7 @@ int xfrm_init_state(struct xfrm_state *x)
32293225{
32303226 int err ;
32313227
3232- err = __xfrm_init_state (x , true, false, NULL );
3228+ err = __xfrm_init_state (x , true, NULL );
32333229 if (!err )
32343230 x -> km .state = XFRM_STATE_VALID ;
32353231
0 commit comments