@@ -399,16 +399,9 @@ static ssize_t iio_show_fixed_type(struct device *dev,
399
399
struct device_attribute * attr ,
400
400
char * buf )
401
401
{
402
- struct iio_dev * indio_dev = dev_to_iio_dev (dev );
403
402
struct iio_dev_attr * this_attr = to_iio_dev_attr (attr );
404
- const struct iio_scan_type * scan_type ;
405
- u8 type ;
406
-
407
- scan_type = iio_get_current_scan_type (indio_dev , this_attr -> c );
408
- if (IS_ERR (scan_type ))
409
- return PTR_ERR (scan_type );
410
-
411
- type = scan_type -> endianness ;
403
+ const struct iio_scan_type * scan_type = & this_attr -> c -> scan_type ;
404
+ u8 type = scan_type -> endianness ;
412
405
413
406
if (type == IIO_CPU ) {
414
407
#ifdef __LITTLE_ENDIAN
@@ -739,20 +732,24 @@ static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
739
732
return sysfs_emit (buf , "%d\n" , iio_buffer_is_active (buffer ));
740
733
}
741
734
742
- static int iio_storage_bytes_for_si (struct iio_dev * indio_dev ,
743
- unsigned int scan_index )
735
+ static unsigned int iio_storage_bytes_for_si (struct iio_dev * indio_dev ,
736
+ unsigned int scan_index )
744
737
{
745
738
const struct iio_chan_spec * ch ;
739
+ const struct iio_scan_type * scan_type ;
746
740
unsigned int bytes ;
747
741
748
742
ch = iio_find_channel_from_si (indio_dev , scan_index );
749
- bytes = ch -> scan_type .storagebits / 8 ;
750
- if (ch -> scan_type .repeat > 1 )
751
- bytes *= ch -> scan_type .repeat ;
743
+ scan_type = & ch -> scan_type ;
744
+ bytes = scan_type -> storagebits / 8 ;
745
+
746
+ if (scan_type -> repeat > 1 )
747
+ bytes *= scan_type -> repeat ;
748
+
752
749
return bytes ;
753
750
}
754
751
755
- static int iio_storage_bytes_for_timestamp (struct iio_dev * indio_dev )
752
+ static unsigned int iio_storage_bytes_for_timestamp (struct iio_dev * indio_dev )
756
753
{
757
754
struct iio_dev_opaque * iio_dev_opaque = to_iio_dev_opaque (indio_dev );
758
755
@@ -770,19 +767,13 @@ static int iio_compute_scan_bytes(struct iio_dev *indio_dev,
770
767
for_each_set_bit (i , mask ,
771
768
indio_dev -> masklength ) {
772
769
length = iio_storage_bytes_for_si (indio_dev , i );
773
- if (length < 0 )
774
- return length ;
775
-
776
770
bytes = ALIGN (bytes , length );
777
771
bytes += length ;
778
772
largest = max (largest , length );
779
773
}
780
774
781
775
if (timestamp ) {
782
776
length = iio_storage_bytes_for_timestamp (indio_dev );
783
- if (length < 0 )
784
- return length ;
785
-
786
777
bytes = ALIGN (bytes , length );
787
778
bytes += length ;
788
779
largest = max (largest , length );
@@ -1061,22 +1052,14 @@ static int iio_buffer_update_demux(struct iio_dev *indio_dev,
1061
1052
indio_dev -> masklength ,
1062
1053
in_ind + 1 );
1063
1054
while (in_ind != out_ind ) {
1064
- ret = iio_storage_bytes_for_si (indio_dev , in_ind );
1065
- if (ret < 0 )
1066
- goto error_clear_mux_table ;
1067
-
1068
- length = ret ;
1055
+ length = iio_storage_bytes_for_si (indio_dev , in_ind );
1069
1056
/* Make sure we are aligned */
1070
1057
in_loc = roundup (in_loc , length ) + length ;
1071
1058
in_ind = find_next_bit (indio_dev -> active_scan_mask ,
1072
1059
indio_dev -> masklength ,
1073
1060
in_ind + 1 );
1074
1061
}
1075
- ret = iio_storage_bytes_for_si (indio_dev , in_ind );
1076
- if (ret < 0 )
1077
- goto error_clear_mux_table ;
1078
-
1079
- length = ret ;
1062
+ length = iio_storage_bytes_for_si (indio_dev , in_ind );
1080
1063
out_loc = roundup (out_loc , length );
1081
1064
in_loc = roundup (in_loc , length );
1082
1065
ret = iio_buffer_add_demux (buffer , & p , in_loc , out_loc , length );
@@ -1087,11 +1070,7 @@ static int iio_buffer_update_demux(struct iio_dev *indio_dev,
1087
1070
}
1088
1071
/* Relies on scan_timestamp being last */
1089
1072
if (buffer -> scan_timestamp ) {
1090
- ret = iio_storage_bytes_for_timestamp (indio_dev );
1091
- if (ret < 0 )
1092
- goto error_clear_mux_table ;
1093
-
1094
- length = ret ;
1073
+ length = iio_storage_bytes_for_timestamp (indio_dev );
1095
1074
out_loc = roundup (out_loc , length );
1096
1075
in_loc = roundup (in_loc , length );
1097
1076
ret = iio_buffer_add_demux (buffer , & p , in_loc , out_loc , length );
@@ -1920,14 +1899,16 @@ static int __iio_buffer_alloc_sysfs_and_mask(struct iio_buffer *buffer,
1920
1899
if (channels [i ].scan_index < 0 )
1921
1900
continue ;
1922
1901
1902
+ scan_type = & channels [i ].scan_type ;
1903
+
1923
1904
/* Verify that sample bits fit into storage */
1924
1905
if (scan_type -> storagebits <
1925
1906
scan_type -> realbits + scan_type -> shift ) {
1926
1907
dev_err (& indio_dev -> dev ,
1927
1908
"Channel %d storagebits (%d) < shifted realbits (%d + %d)\n" ,
1928
- i , channels [ i ]. scan_type . storagebits ,
1929
- channels [ i ]. scan_type . realbits ,
1930
- channels [ i ]. scan_type . shift );
1909
+ i , scan_type -> storagebits ,
1910
+ scan_type -> realbits ,
1911
+ scan_type -> shift );
1931
1912
ret = - EINVAL ;
1932
1913
goto error_cleanup_dynamic ;
1933
1914
}
0 commit comments