Skip to content

Commit 7f75812

Browse files
andy-shevBenjamin Tissoires
authored andcommitted
HID: cp2112: Convert to DEVICE_ATTR_RW()
Instead of custom wrapper, use DEVICE_tATTR_RW() directly. Signed-off-by: Andy Shevchenko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Benjamin Tissoires <[email protected]>
1 parent 5120bf0 commit 7f75812

File tree

1 file changed

+19
-23
lines changed

1 file changed

+19
-23
lines changed

drivers/hid/hid-cp2112.c

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -944,26 +944,18 @@ CP2112_CONFIG_ATTR(release_version, ({
944944

945945
#undef CP2112_CONFIG_ATTR
946946

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)
955949
{
956950
struct hid_device *hdev = to_hid_device(kdev);
957-
struct cp2112_pstring_attribute *attr =
958-
container_of(kattr, struct cp2112_pstring_attribute, attr);
959951
struct cp2112_string_report report;
960952
int ret;
961953

962954
memset(&report, 0, sizeof(report));
963955

964956
ret = utf8s_to_utf16s(buf, count, UTF16_LITTLE_ENDIAN,
965957
report.string, ARRAY_SIZE(report.string));
966-
report.report = attr->report;
958+
report.report = number;
967959
report.length = ret * sizeof(report.string[0]) + 2;
968960
report.type = USB_DT_STRING;
969961

@@ -981,17 +973,15 @@ static ssize_t pstr_store(struct device *kdev,
981973
return count;
982974
}
983975

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)
986978
{
987979
struct hid_device *hdev = to_hid_device(kdev);
988-
struct cp2112_pstring_attribute *attr =
989-
container_of(kattr, struct cp2112_pstring_attribute, attr);
990980
struct cp2112_string_report report;
991981
u8 length;
992982
int ret;
993983

994-
ret = cp2112_hid_get(hdev, attr->report, (u8 *)&report.contents,
984+
ret = cp2112_hid_get(hdev, number, (u8 *)&report.contents,
995985
sizeof(report.contents), HID_FEATURE_REPORT);
996986
if (ret < 3) {
997987
hid_err(hdev, "error reading %s string: %d\n", kattr->attr.name,
@@ -1016,10 +1006,16 @@ static ssize_t pstr_show(struct device *kdev,
10161006
}
10171007

10181008
#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);
10231019

10241020
CP2112_PSTR_ATTR(manufacturer, CP2112_MANUFACTURER_STRING);
10251021
CP2112_PSTR_ATTR(product, CP2112_PRODUCT_STRING);
@@ -1034,9 +1030,9 @@ static const struct attribute_group cp2112_attr_group = {
10341030
&dev_attr_max_power.attr,
10351031
&dev_attr_power_mode.attr,
10361032
&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,
10401036
NULL
10411037
}
10421038
};

0 commit comments

Comments
 (0)