@@ -694,27 +694,27 @@ static int uvc_get_vs_probe(const struct device *dev, struct net_buf *const buf,
694
694
const struct usb_setup_packet * const setup )
695
695
{
696
696
struct uvc_data * data = dev -> data ;
697
- size_t size = MIN (sizeof (struct uvc_probe ), net_buf_tailroom (buf ));
697
+ const size_t size = MIN (sizeof (struct uvc_probe ), net_buf_tailroom (buf ));
698
+ struct uvc_probe probe = {0 };
698
699
int ret ;
699
700
700
701
switch (setup -> bRequest ) {
701
702
case UVC_GET_INFO :
702
703
if (size < 1 ) {
703
704
return - ENOTSUP ;
704
705
}
706
+
705
707
net_buf_add_u8 (buf , UVC_INFO_SUPPORTS_GET );
706
708
return 0 ;
707
709
case UVC_GET_LEN :
708
710
if (size < 2 ) {
709
711
return - ENOTSUP ;
710
712
}
713
+
711
714
net_buf_add_le16 (buf , sizeof (struct uvc_probe ));
712
715
return 0 ;
713
716
case UVC_GET_DEF :
714
- if (size < sizeof (struct uvc_probe )) {
715
- return - ENOTSUP ;
716
- }
717
- net_buf_add_mem (buf , & data -> default_probe , sizeof (data -> default_probe ));
717
+ net_buf_add_mem (buf , & data -> default_probe , size );
718
718
return 0 ;
719
719
case UVC_GET_MIN :
720
720
__fallthrough ;
@@ -723,16 +723,12 @@ static int uvc_get_vs_probe(const struct device *dev, struct net_buf *const buf,
723
723
case UVC_GET_MAX :
724
724
__fallthrough ;
725
725
case UVC_GET_CUR :
726
- if (size < sizeof (struct uvc_probe )) {
727
- return - ENOTSUP ;
728
- }
729
-
730
- ret = uvc_get_vs_probe_struct (dev , (struct uvc_probe * )buf -> data , setup -> bRequest );
726
+ ret = uvc_get_vs_probe_struct (dev , & probe , setup -> bRequest );
731
727
if (ret != 0 ) {
732
728
return ret ;
733
729
}
734
730
735
- net_buf_add (buf , sizeof ( struct uvc_probe ) );
731
+ net_buf_add_mem (buf , & probe , size );
736
732
return 0 ;
737
733
default :
738
734
return - EINVAL ;
@@ -742,45 +738,41 @@ static int uvc_get_vs_probe(const struct device *dev, struct net_buf *const buf,
742
738
static int uvc_set_vs_probe (const struct device * dev , const struct net_buf * const buf )
743
739
{
744
740
struct uvc_data * data = dev -> data ;
745
- struct uvc_probe * probe ;
741
+ const size_t size = MIN (sizeof (struct uvc_probe ), net_buf_tailroom (buf ));
742
+ struct uvc_probe probe = {0 };
746
743
struct uvc_probe max = {0 };
747
744
int ret ;
748
745
749
- if (buf -> len != sizeof (* probe )) {
750
- LOG_ERR ("Expected probe message of %u bytes got %u" , sizeof (* probe ), buf -> len );
751
- return - EINVAL ;
752
- }
753
-
754
- probe = (struct uvc_probe * )buf -> data ;
746
+ memcpy (& probe , buf -> data , size );
755
747
756
748
ret = uvc_get_vs_probe_struct (dev , & max , UVC_GET_MAX );
757
749
if (ret != 0 ) {
758
750
return ret ;
759
751
}
760
752
761
- if (probe -> bFrameIndex > max .bFrameIndex ) {
753
+ if (probe . bFrameIndex > max .bFrameIndex ) {
762
754
LOG_WRN ("The bFrameIndex %u requested is beyond the max %u" ,
763
- probe -> bFrameIndex , max .bFrameIndex );
755
+ probe . bFrameIndex , max .bFrameIndex );
764
756
return - ERANGE ;
765
757
}
766
758
767
- if (probe -> bFormatIndex > max .bFormatIndex ) {
759
+ if (probe . bFormatIndex > max .bFormatIndex ) {
768
760
LOG_WRN ("The bFormatIndex %u requested is beyond the max %u" ,
769
- probe -> bFormatIndex , max .bFormatIndex );
761
+ probe . bFormatIndex , max .bFormatIndex );
770
762
return - ERANGE ;
771
763
}
772
764
773
- if (probe -> dwFrameInterval != 0 ) {
774
- data -> video_frmival .numerator = sys_le32_to_cpu (probe -> dwFrameInterval );
765
+ if (probe . dwFrameInterval != 0 ) {
766
+ data -> video_frmival .numerator = sys_le32_to_cpu (probe . dwFrameInterval );
775
767
data -> video_frmival .denominator = USEC_PER_SEC * 100 ;
776
768
}
777
769
778
- if (probe -> bFrameIndex != 0 ) {
779
- data -> frame_id = probe -> bFrameIndex ;
770
+ if (probe . bFrameIndex != 0 ) {
771
+ data -> frame_id = probe . bFrameIndex ;
780
772
}
781
773
782
- if (probe -> bFormatIndex != 0 ) {
783
- data -> format_id = probe -> bFormatIndex ;
774
+ if (probe . bFormatIndex != 0 ) {
775
+ data -> format_id = probe . bFormatIndex ;
784
776
}
785
777
786
778
return 0 ;
0 commit comments