diff options
author | Benjamin Tissoires <benjamin.tissoires@redhat.com> | 2013-07-24 13:38:05 -0400 |
---|---|---|
committer | Jiri Kosina <jkosina@suse.cz> | 2013-07-31 04:13:15 -0400 |
commit | c08d46aa805ba46d501f610c2448d07bea979780 (patch) | |
tree | e4764c97f9a235688f9012787a6f8a24f5af1de0 | |
parent | abf832bfc349b54fd500f1e3b612f7f3cd9dfcc6 (diff) |
HID: multitouch: devm conversion
HID special drivers can use safely the devres API.
Use it to remove 25 lines of code and to clean up a little the error paths.
Besides the basic kzalloc -> devm_kzalloc conversions, I changed the
place of the allocation of the new name. Doing this right in
mt_input_configured() removes the kstrdup call which was not very helpful
and the new way is simpler to understand (and to debug).
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
-rw-r--r-- | drivers/hid/hid-multitouch.c | 71 |
1 files changed, 23 insertions, 48 deletions
diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c index cb0e361d7a4b..0fe00e2552f2 100644 --- a/drivers/hid/hid-multitouch.c +++ b/drivers/hid/hid-multitouch.c | |||
@@ -261,17 +261,6 @@ static struct mt_class mt_classes[] = { | |||
261 | { } | 261 | { } |
262 | }; | 262 | }; |
263 | 263 | ||
264 | static void mt_free_input_name(struct hid_input *hi) | ||
265 | { | ||
266 | struct hid_device *hdev = hi->report->device; | ||
267 | const char *name = hi->input->name; | ||
268 | |||
269 | if (name != hdev->name) { | ||
270 | hi->input->name = hdev->name; | ||
271 | kfree(name); | ||
272 | } | ||
273 | } | ||
274 | |||
275 | static ssize_t mt_show_quirks(struct device *dev, | 264 | static ssize_t mt_show_quirks(struct device *dev, |
276 | struct device_attribute *attr, | 265 | struct device_attribute *attr, |
277 | char *buf) | 266 | char *buf) |
@@ -415,13 +404,6 @@ static void mt_pen_report(struct hid_device *hid, struct hid_report *report) | |||
415 | static void mt_pen_input_configured(struct hid_device *hdev, | 404 | static void mt_pen_input_configured(struct hid_device *hdev, |
416 | struct hid_input *hi) | 405 | struct hid_input *hi) |
417 | { | 406 | { |
418 | char *name = kzalloc(strlen(hi->input->name) + 5, GFP_KERNEL); | ||
419 | if (name) { | ||
420 | sprintf(name, "%s Pen", hi->input->name); | ||
421 | mt_free_input_name(hi); | ||
422 | hi->input->name = name; | ||
423 | } | ||
424 | |||
425 | /* force BTN_STYLUS to allow tablet matching in udev */ | 407 | /* force BTN_STYLUS to allow tablet matching in udev */ |
426 | __set_bit(BTN_STYLUS, hi->input->keybit); | 408 | __set_bit(BTN_STYLUS, hi->input->keybit); |
427 | } | 409 | } |
@@ -928,16 +910,26 @@ static void mt_post_parse(struct mt_device *td) | |||
928 | static void mt_input_configured(struct hid_device *hdev, struct hid_input *hi) | 910 | static void mt_input_configured(struct hid_device *hdev, struct hid_input *hi) |
929 | { | 911 | { |
930 | struct mt_device *td = hid_get_drvdata(hdev); | 912 | struct mt_device *td = hid_get_drvdata(hdev); |
931 | char *name = kstrdup(hdev->name, GFP_KERNEL); | 913 | char *name; |
932 | 914 | const char *suffix = NULL; | |
933 | if (name) | ||
934 | hi->input->name = name; | ||
935 | 915 | ||
936 | if (hi->report->id == td->mt_report_id) | 916 | if (hi->report->id == td->mt_report_id) |
937 | mt_touch_input_configured(hdev, hi); | 917 | mt_touch_input_configured(hdev, hi); |
938 | 918 | ||
939 | if (hi->report->id == td->pen_report_id) | 919 | if (hi->report->field[0]->physical == HID_DG_STYLUS) { |
920 | suffix = "Pen"; | ||
940 | mt_pen_input_configured(hdev, hi); | 921 | mt_pen_input_configured(hdev, hi); |
922 | } | ||
923 | |||
924 | if (suffix) { | ||
925 | name = devm_kzalloc(&hi->input->dev, | ||
926 | strlen(hdev->name) + strlen(suffix) + 2, | ||
927 | GFP_KERNEL); | ||
928 | if (name) { | ||
929 | sprintf(name, "%s %s", hdev->name, suffix); | ||
930 | hi->input->name = name; | ||
931 | } | ||
932 | } | ||
941 | } | 933 | } |
942 | 934 | ||
943 | static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) | 935 | static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) |
@@ -945,7 +937,6 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) | |||
945 | int ret, i; | 937 | int ret, i; |
946 | struct mt_device *td; | 938 | struct mt_device *td; |
947 | struct mt_class *mtclass = mt_classes; /* MT_CLS_DEFAULT */ | 939 | struct mt_class *mtclass = mt_classes; /* MT_CLS_DEFAULT */ |
948 | struct hid_input *hi; | ||
949 | 940 | ||
950 | for (i = 0; mt_classes[i].name ; i++) { | 941 | for (i = 0; mt_classes[i].name ; i++) { |
951 | if (id->driver_data == mt_classes[i].name) { | 942 | if (id->driver_data == mt_classes[i].name) { |
@@ -967,7 +958,7 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) | |||
967 | hdev->quirks |= HID_QUIRK_MULTI_INPUT; | 958 | hdev->quirks |= HID_QUIRK_MULTI_INPUT; |
968 | hdev->quirks |= HID_QUIRK_NO_EMPTY_INPUT; | 959 | hdev->quirks |= HID_QUIRK_NO_EMPTY_INPUT; |
969 | 960 | ||
970 | td = kzalloc(sizeof(struct mt_device), GFP_KERNEL); | 961 | td = devm_kzalloc(&hdev->dev, sizeof(struct mt_device), GFP_KERNEL); |
971 | if (!td) { | 962 | if (!td) { |
972 | dev_err(&hdev->dev, "cannot allocate multitouch data\n"); | 963 | dev_err(&hdev->dev, "cannot allocate multitouch data\n"); |
973 | return -ENOMEM; | 964 | return -ENOMEM; |
@@ -980,11 +971,11 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) | |||
980 | td->pen_report_id = -1; | 971 | td->pen_report_id = -1; |
981 | hid_set_drvdata(hdev, td); | 972 | hid_set_drvdata(hdev, td); |
982 | 973 | ||
983 | td->fields = kzalloc(sizeof(struct mt_fields), GFP_KERNEL); | 974 | td->fields = devm_kzalloc(&hdev->dev, sizeof(struct mt_fields), |
975 | GFP_KERNEL); | ||
984 | if (!td->fields) { | 976 | if (!td->fields) { |
985 | dev_err(&hdev->dev, "cannot allocate multitouch fields data\n"); | 977 | dev_err(&hdev->dev, "cannot allocate multitouch fields data\n"); |
986 | ret = -ENOMEM; | 978 | return -ENOMEM; |
987 | goto fail; | ||
988 | } | 979 | } |
989 | 980 | ||
990 | if (id->vendor == HID_ANY_ID && id->product == HID_ANY_ID) | 981 | if (id->vendor == HID_ANY_ID && id->product == HID_ANY_ID) |
@@ -992,29 +983,22 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) | |||
992 | 983 | ||
993 | ret = hid_parse(hdev); | 984 | ret = hid_parse(hdev); |
994 | if (ret != 0) | 985 | if (ret != 0) |
995 | goto fail; | 986 | return ret; |
996 | 987 | ||
997 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); | 988 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); |
998 | if (ret) | 989 | if (ret) |
999 | goto hid_fail; | 990 | return ret; |
1000 | 991 | ||
1001 | ret = sysfs_create_group(&hdev->dev.kobj, &mt_attribute_group); | 992 | ret = sysfs_create_group(&hdev->dev.kobj, &mt_attribute_group); |
1002 | 993 | ||
1003 | mt_set_maxcontacts(hdev); | 994 | mt_set_maxcontacts(hdev); |
1004 | mt_set_input_mode(hdev); | 995 | mt_set_input_mode(hdev); |
1005 | 996 | ||
1006 | kfree(td->fields); | 997 | /* release .fields memory as it is not used anymore */ |
998 | devm_kfree(&hdev->dev, td->fields); | ||
1007 | td->fields = NULL; | 999 | td->fields = NULL; |
1008 | 1000 | ||
1009 | return 0; | 1001 | return 0; |
1010 | |||
1011 | hid_fail: | ||
1012 | list_for_each_entry(hi, &hdev->inputs, list) | ||
1013 | mt_free_input_name(hi); | ||
1014 | fail: | ||
1015 | kfree(td->fields); | ||
1016 | kfree(td); | ||
1017 | return ret; | ||
1018 | } | 1002 | } |
1019 | 1003 | ||
1020 | #ifdef CONFIG_PM | 1004 | #ifdef CONFIG_PM |
@@ -1039,17 +1023,8 @@ static int mt_resume(struct hid_device *hdev) | |||
1039 | 1023 | ||
1040 | static void mt_remove(struct hid_device *hdev) | 1024 | static void mt_remove(struct hid_device *hdev) |
1041 | { | 1025 | { |
1042 | struct mt_device *td = hid_get_drvdata(hdev); | ||
1043 | struct hid_input *hi; | ||
1044 | |||
1045 | sysfs_remove_group(&hdev->dev.kobj, &mt_attribute_group); | 1026 | sysfs_remove_group(&hdev->dev.kobj, &mt_attribute_group); |
1046 | list_for_each_entry(hi, &hdev->inputs, list) | ||
1047 | mt_free_input_name(hi); | ||
1048 | |||
1049 | hid_hw_stop(hdev); | 1027 | hid_hw_stop(hdev); |
1050 | |||
1051 | kfree(td); | ||
1052 | hid_set_drvdata(hdev, NULL); | ||
1053 | } | 1028 | } |
1054 | 1029 | ||
1055 | static const struct hid_device_id mt_devices[] = { | 1030 | static const struct hid_device_id mt_devices[] = { |