@@ -944,26 +944,18 @@ CP2112_CONFIG_ATTR(release_version, ({
944
944
945
945
#undef CP2112_CONFIG_ATTR
946
946
947
- struct cp2112_pstring_attribute {
948
- struct device_attribute attr ;
949
- unsigned char report ;
950
- };
951
-
952
- static ssize_t pstr_store (struct device * kdev ,
953
- struct device_attribute * kattr , const char * buf ,
954
- size_t count )
947
+ static ssize_t pstr_store (struct device * kdev , struct device_attribute * kattr ,
948
+ const char * buf , size_t count , int number )
955
949
{
956
950
struct hid_device * hdev = to_hid_device (kdev );
957
- struct cp2112_pstring_attribute * attr =
958
- container_of (kattr , struct cp2112_pstring_attribute , attr );
959
951
struct cp2112_string_report report ;
960
952
int ret ;
961
953
962
954
memset (& report , 0 , sizeof (report ));
963
955
964
956
ret = utf8s_to_utf16s (buf , count , UTF16_LITTLE_ENDIAN ,
965
957
report .string , ARRAY_SIZE (report .string ));
966
- report .report = attr -> report ;
958
+ report .report = number ;
967
959
report .length = ret * sizeof (report .string [0 ]) + 2 ;
968
960
report .type = USB_DT_STRING ;
969
961
@@ -981,17 +973,15 @@ static ssize_t pstr_store(struct device *kdev,
981
973
return count ;
982
974
}
983
975
984
- static ssize_t pstr_show (struct device * kdev ,
985
- struct device_attribute * kattr , char * buf )
976
+ static ssize_t pstr_show (struct device * kdev , struct device_attribute * kattr ,
977
+ char * buf , int number )
986
978
{
987
979
struct hid_device * hdev = to_hid_device (kdev );
988
- struct cp2112_pstring_attribute * attr =
989
- container_of (kattr , struct cp2112_pstring_attribute , attr );
990
980
struct cp2112_string_report report ;
991
981
u8 length ;
992
982
int ret ;
993
983
994
- ret = cp2112_hid_get (hdev , attr -> report , (u8 * )& report .contents ,
984
+ ret = cp2112_hid_get (hdev , number , (u8 * )& report .contents ,
995
985
sizeof (report .contents ), HID_FEATURE_REPORT );
996
986
if (ret < 3 ) {
997
987
hid_err (hdev , "error reading %s string: %d\n" , kattr -> attr .name ,
@@ -1016,10 +1006,16 @@ static ssize_t pstr_show(struct device *kdev,
1016
1006
}
1017
1007
1018
1008
#define CP2112_PSTR_ATTR (name , _report ) \
1019
- static struct cp2112_pstring_attribute dev_attr_##name = { \
1020
- .attr = __ATTR(name, (S_IWUSR | S_IRUGO), pstr_show, pstr_store), \
1021
- .report = _report, \
1022
- };
1009
+ static ssize_t name##_store(struct device *kdev, struct device_attribute *kattr, \
1010
+ const char *buf, size_t count) \
1011
+ { \
1012
+ return pstr_store(kdev, kattr, buf, count, _report); \
1013
+ } \
1014
+ static ssize_t name##_show(struct device *kdev, struct device_attribute *kattr, char *buf) \
1015
+ { \
1016
+ return pstr_show(kdev, kattr, buf, _report); \
1017
+ } \
1018
+ static DEVICE_ATTR_RW(name);
1023
1019
1024
1020
CP2112_PSTR_ATTR (manufacturer , CP2112_MANUFACTURER_STRING );
1025
1021
CP2112_PSTR_ATTR (product , CP2112_PRODUCT_STRING );
@@ -1034,9 +1030,9 @@ static const struct attribute_group cp2112_attr_group = {
1034
1030
& dev_attr_max_power .attr ,
1035
1031
& dev_attr_power_mode .attr ,
1036
1032
& dev_attr_release_version .attr ,
1037
- & dev_attr_manufacturer .attr . attr ,
1038
- & dev_attr_product .attr . attr ,
1039
- & dev_attr_serial .attr . attr ,
1033
+ & dev_attr_manufacturer .attr ,
1034
+ & dev_attr_product .attr ,
1035
+ & dev_attr_serial .attr ,
1040
1036
NULL
1041
1037
}
1042
1038
};
0 commit comments