@@ -629,30 +629,20 @@ static int cp210x_read_reg_block(struct usb_serial_port *port, u8 req,
629
629
{
630
630
struct usb_serial * serial = port -> serial ;
631
631
struct cp210x_port_private * port_priv = usb_get_serial_port_data (port );
632
- void * dmabuf ;
633
632
int result ;
634
633
635
- dmabuf = kmalloc (bufsize , GFP_KERNEL );
636
- if (!dmabuf )
637
- return - ENOMEM ;
638
634
639
- result = usb_control_msg (serial -> dev , usb_rcvctrlpipe (serial -> dev , 0 ),
640
- req , REQTYPE_INTERFACE_TO_HOST , 0 ,
641
- port_priv -> bInterfaceNumber , dmabuf , bufsize ,
642
- USB_CTRL_GET_TIMEOUT );
643
- if (result == bufsize ) {
644
- memcpy (buf , dmabuf , bufsize );
645
- result = 0 ;
646
- } else {
635
+ result = usb_control_msg_recv (serial -> dev , 0 , req ,
636
+ REQTYPE_INTERFACE_TO_HOST , 0 ,
637
+ port_priv -> bInterfaceNumber , buf , bufsize ,
638
+ USB_CTRL_SET_TIMEOUT , GFP_KERNEL );
639
+ if (result ) {
647
640
dev_err (& port -> dev , "failed get req 0x%x size %d status: %d\n" ,
648
641
req , bufsize , result );
649
- if (result >= 0 )
650
- result = - EIO ;
642
+ return result ;
651
643
}
652
644
653
- kfree (dmabuf );
654
-
655
- return result ;
645
+ return 0 ;
656
646
}
657
647
658
648
/*
@@ -670,31 +660,19 @@ static int cp210x_read_u8_reg(struct usb_serial_port *port, u8 req, u8 *val)
670
660
static int cp210x_read_vendor_block (struct usb_serial * serial , u8 type , u16 val ,
671
661
void * buf , int bufsize )
672
662
{
673
- void * dmabuf ;
674
663
int result ;
675
664
676
- dmabuf = kmalloc (bufsize , GFP_KERNEL );
677
- if (!dmabuf )
678
- return - ENOMEM ;
679
-
680
- result = usb_control_msg (serial -> dev , usb_rcvctrlpipe (serial -> dev , 0 ),
681
- CP210X_VENDOR_SPECIFIC , type , val ,
682
- cp210x_interface_num (serial ), dmabuf , bufsize ,
683
- USB_CTRL_GET_TIMEOUT );
684
- if (result == bufsize ) {
685
- memcpy (buf , dmabuf , bufsize );
686
- result = 0 ;
687
- } else {
665
+ result = usb_control_msg_recv (serial -> dev , 0 , CP210X_VENDOR_SPECIFIC ,
666
+ type , val , cp210x_interface_num (serial ), buf , bufsize ,
667
+ USB_CTRL_GET_TIMEOUT , GFP_KERNEL );
668
+ if (result ) {
688
669
dev_err (& serial -> interface -> dev ,
689
670
"failed to get vendor val 0x%04x size %d: %d\n" , val ,
690
671
bufsize , result );
691
- if (result >= 0 )
692
- result = - EIO ;
672
+ return result ;
693
673
}
694
674
695
- kfree (dmabuf );
696
-
697
- return result ;
675
+ return 0 ;
698
676
}
699
677
700
678
/*
@@ -728,21 +706,13 @@ static int cp210x_write_reg_block(struct usb_serial_port *port, u8 req,
728
706
{
729
707
struct usb_serial * serial = port -> serial ;
730
708
struct cp210x_port_private * port_priv = usb_get_serial_port_data (port );
731
- void * dmabuf ;
732
709
int result ;
733
710
734
- dmabuf = kmemdup (buf , bufsize , GFP_KERNEL );
735
- if (!dmabuf )
736
- return - ENOMEM ;
737
-
738
- result = usb_control_msg (serial -> dev , usb_sndctrlpipe (serial -> dev , 0 ),
739
- req , REQTYPE_HOST_TO_INTERFACE , 0 ,
740
- port_priv -> bInterfaceNumber , dmabuf , bufsize ,
741
- USB_CTRL_SET_TIMEOUT );
742
-
743
- kfree (dmabuf );
744
-
745
- if (result < 0 ) {
711
+ result = usb_control_msg_send (serial -> dev , 0 , req ,
712
+ REQTYPE_HOST_TO_INTERFACE , 0 ,
713
+ port_priv -> bInterfaceNumber , buf , bufsize ,
714
+ USB_CTRL_SET_TIMEOUT , GFP_KERNEL );
715
+ if (result ) {
746
716
dev_err (& port -> dev , "failed set req 0x%x size %d status: %d\n" ,
747
717
req , bufsize , result );
748
718
return result ;
@@ -771,21 +741,12 @@ static int cp210x_write_u32_reg(struct usb_serial_port *port, u8 req, u32 val)
771
741
static int cp210x_write_vendor_block (struct usb_serial * serial , u8 type ,
772
742
u16 val , void * buf , int bufsize )
773
743
{
774
- void * dmabuf ;
775
744
int result ;
776
745
777
- dmabuf = kmemdup (buf , bufsize , GFP_KERNEL );
778
- if (!dmabuf )
779
- return - ENOMEM ;
780
-
781
- result = usb_control_msg (serial -> dev , usb_sndctrlpipe (serial -> dev , 0 ),
782
- CP210X_VENDOR_SPECIFIC , type , val ,
783
- cp210x_interface_num (serial ), dmabuf , bufsize ,
784
- USB_CTRL_SET_TIMEOUT );
785
-
786
- kfree (dmabuf );
787
-
788
- if (result < 0 ) {
746
+ result = usb_control_msg_send (serial -> dev , 0 , CP210X_VENDOR_SPECIFIC ,
747
+ type , val , cp210x_interface_num (serial ), buf , bufsize ,
748
+ USB_CTRL_SET_TIMEOUT , GFP_KERNEL );
749
+ if (result ) {
789
750
dev_err (& serial -> interface -> dev ,
790
751
"failed to set vendor val 0x%04x size %d: %d\n" , val ,
791
752
bufsize , result );
@@ -950,29 +911,21 @@ static int cp210x_get_tx_queue_byte_count(struct usb_serial_port *port,
950
911
{
951
912
struct usb_serial * serial = port -> serial ;
952
913
struct cp210x_port_private * port_priv = usb_get_serial_port_data (port );
953
- struct cp210x_comm_status * sts ;
914
+ struct cp210x_comm_status sts ;
954
915
int result ;
955
916
956
- sts = kmalloc (sizeof (* sts ), GFP_KERNEL );
957
- if (!sts )
958
- return - ENOMEM ;
959
-
960
- result = usb_control_msg (serial -> dev , usb_rcvctrlpipe (serial -> dev , 0 ),
961
- CP210X_GET_COMM_STATUS , REQTYPE_INTERFACE_TO_HOST ,
962
- 0 , port_priv -> bInterfaceNumber , sts , sizeof (* sts ),
963
- USB_CTRL_GET_TIMEOUT );
964
- if (result == sizeof (* sts )) {
965
- * count = le32_to_cpu (sts -> ulAmountInOutQueue );
966
- result = 0 ;
967
- } else {
917
+ result = usb_control_msg_recv (serial -> dev , 0 , CP210X_GET_COMM_STATUS ,
918
+ REQTYPE_INTERFACE_TO_HOST , 0 ,
919
+ port_priv -> bInterfaceNumber , & sts , sizeof (sts ),
920
+ USB_CTRL_GET_TIMEOUT , GFP_KERNEL );
921
+ if (result ) {
968
922
dev_err (& port -> dev , "failed to get comm status: %d\n" , result );
969
- if (result >= 0 )
970
- result = - EIO ;
923
+ return result ;
971
924
}
972
925
973
- kfree (sts );
926
+ * count = le32_to_cpu (sts . ulAmountInOutQueue );
974
927
975
- return result ;
928
+ return 0 ;
976
929
}
977
930
978
931
static bool cp210x_tx_empty (struct usb_serial_port * port )
0 commit comments