@@ -761,6 +761,17 @@ static void gb_tty_port_shutdown(struct tty_port *port)
761
761
gbphy_runtime_put_autosuspend (gb_tty -> gbphy_dev );
762
762
}
763
763
764
+ static void gb_tty_port_destruct (struct tty_port * port )
765
+ {
766
+ struct gb_tty * gb_tty = container_of (port , struct gb_tty , port );
767
+
768
+ if (gb_tty -> minor != GB_NUM_MINORS )
769
+ release_minor (gb_tty );
770
+ kfifo_free (& gb_tty -> write_fifo );
771
+ kfree (gb_tty -> buffer );
772
+ kfree (gb_tty );
773
+ }
774
+
764
775
static const struct tty_operations gb_ops = {
765
776
.install = gb_tty_install ,
766
777
.open = gb_tty_open ,
@@ -786,6 +797,7 @@ static const struct tty_port_operations gb_port_ops = {
786
797
.dtr_rts = gb_tty_dtr_rts ,
787
798
.activate = gb_tty_port_activate ,
788
799
.shutdown = gb_tty_port_shutdown ,
800
+ .destruct = gb_tty_port_destruct ,
789
801
};
790
802
791
803
static int gb_uart_probe (struct gbphy_device * gbphy_dev ,
@@ -798,39 +810,43 @@ static int gb_uart_probe(struct gbphy_device *gbphy_dev,
798
810
int retval ;
799
811
int minor ;
800
812
801
- gb_tty = kzalloc (sizeof (* gb_tty ), GFP_KERNEL );
802
- if (!gb_tty )
803
- return - ENOMEM ;
804
-
805
813
connection = gb_connection_create (gbphy_dev -> bundle ,
806
814
le16_to_cpu (gbphy_dev -> cport_desc -> id ),
807
815
gb_uart_request_handler );
808
- if (IS_ERR (connection )) {
809
- retval = PTR_ERR (connection );
810
- goto exit_tty_free ;
811
- }
816
+ if (IS_ERR (connection ))
817
+ return PTR_ERR (connection );
812
818
813
819
max_payload = gb_operation_get_payload_size_max (connection );
814
820
if (max_payload < sizeof (struct gb_uart_send_data_request )) {
815
821
retval = - EINVAL ;
816
822
goto exit_connection_destroy ;
817
823
}
818
824
825
+ gb_tty = kzalloc (sizeof (* gb_tty ), GFP_KERNEL );
826
+ if (!gb_tty ) {
827
+ retval = - ENOMEM ;
828
+ goto exit_connection_destroy ;
829
+ }
830
+
831
+ tty_port_init (& gb_tty -> port );
832
+ gb_tty -> port .ops = & gb_port_ops ;
833
+ gb_tty -> minor = GB_NUM_MINORS ;
834
+
819
835
gb_tty -> buffer_payload_max = max_payload -
820
836
sizeof (struct gb_uart_send_data_request );
821
837
822
838
gb_tty -> buffer = kzalloc (gb_tty -> buffer_payload_max , GFP_KERNEL );
823
839
if (!gb_tty -> buffer ) {
824
840
retval = - ENOMEM ;
825
- goto exit_connection_destroy ;
841
+ goto exit_put_port ;
826
842
}
827
843
828
844
INIT_WORK (& gb_tty -> tx_work , gb_uart_tx_write_work );
829
845
830
846
retval = kfifo_alloc (& gb_tty -> write_fifo , GB_UART_WRITE_FIFO_SIZE ,
831
847
GFP_KERNEL );
832
848
if (retval )
833
- goto exit_buf_free ;
849
+ goto exit_put_port ;
834
850
835
851
gb_tty -> credits = GB_UART_FIRMWARE_CREDITS ;
836
852
init_completion (& gb_tty -> credits_complete );
@@ -844,7 +860,7 @@ static int gb_uart_probe(struct gbphy_device *gbphy_dev,
844
860
} else {
845
861
retval = minor ;
846
862
}
847
- goto exit_kfifo_free ;
863
+ goto exit_put_port ;
848
864
}
849
865
850
866
gb_tty -> minor = minor ;
@@ -853,17 +869,14 @@ static int gb_uart_probe(struct gbphy_device *gbphy_dev,
853
869
init_waitqueue_head (& gb_tty -> wioctl );
854
870
mutex_init (& gb_tty -> mutex );
855
871
856
- tty_port_init (& gb_tty -> port );
857
- gb_tty -> port .ops = & gb_port_ops ;
858
-
859
872
gb_tty -> connection = connection ;
860
873
gb_tty -> gbphy_dev = gbphy_dev ;
861
874
gb_connection_set_data (connection , gb_tty );
862
875
gb_gbphy_set_data (gbphy_dev , gb_tty );
863
876
864
877
retval = gb_connection_enable_tx (connection );
865
878
if (retval )
866
- goto exit_release_minor ;
879
+ goto exit_put_port ;
867
880
868
881
send_control (gb_tty , gb_tty -> ctrlout );
869
882
@@ -890,16 +903,10 @@ static int gb_uart_probe(struct gbphy_device *gbphy_dev,
890
903
891
904
exit_connection_disable :
892
905
gb_connection_disable (connection );
893
- exit_release_minor :
894
- release_minor (gb_tty );
895
- exit_kfifo_free :
896
- kfifo_free (& gb_tty -> write_fifo );
897
- exit_buf_free :
898
- kfree (gb_tty -> buffer );
906
+ exit_put_port :
907
+ tty_port_put (& gb_tty -> port );
899
908
exit_connection_destroy :
900
909
gb_connection_destroy (connection );
901
- exit_tty_free :
902
- kfree (gb_tty );
903
910
904
911
return retval ;
905
912
}
@@ -930,15 +937,10 @@ static void gb_uart_remove(struct gbphy_device *gbphy_dev)
930
937
gb_connection_disable_rx (connection );
931
938
tty_unregister_device (gb_tty_driver , gb_tty -> minor );
932
939
933
- /* FIXME - free transmit / receive buffers */
934
-
935
940
gb_connection_disable (connection );
936
- tty_port_destroy (& gb_tty -> port );
937
941
gb_connection_destroy (connection );
938
- release_minor (gb_tty );
939
- kfifo_free (& gb_tty -> write_fifo );
940
- kfree (gb_tty -> buffer );
941
- kfree (gb_tty );
942
+
943
+ tty_port_put (& gb_tty -> port );
942
944
}
943
945
944
946
static int gb_tty_init (void )
0 commit comments