Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Input: ad714x - convert to using managed resources

Use managed resource functions devm_request_threaded_irq,
devm_inpute_allocate_device and devm_kzalloc to simplify error handling.
Also, remove use of input_unregister_device as input_register_device itself
handles it and works as resource managed function.

To be compatible with the change, various gotos are replaced with direct
returns, and unneeded labels are dropped. With these changes remove
ad714x_remove and corresponding calls of it as they are now redundant.

Signed-off-by: Vaishali Thakkar <vthakkar1994@gmail.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

authored by

Vaishali Thakkar and committed by
Dmitry Torokhov
c5c18a06 ade9c1a4

+79 -150
-10
drivers/input/misc/ad714x-i2c.c
··· 85 85 return 0; 86 86 } 87 87 88 - static int ad714x_i2c_remove(struct i2c_client *client) 89 - { 90 - struct ad714x_chip *chip = i2c_get_clientdata(client); 91 - 92 - ad714x_remove(chip); 93 - 94 - return 0; 95 - } 96 - 97 88 static const struct i2c_device_id ad714x_id[] = { 98 89 { "ad7142_captouch", 0 }, 99 90 { "ad7143_captouch", 0 }, ··· 101 110 .pm = &ad714x_i2c_pm, 102 111 }, 103 112 .probe = ad714x_i2c_probe, 104 - .remove = ad714x_i2c_remove, 105 113 .id_table = ad714x_id, 106 114 }; 107 115
-10
drivers/input/misc/ad714x-spi.c
··· 101 101 return 0; 102 102 } 103 103 104 - static int ad714x_spi_remove(struct spi_device *spi) 105 - { 106 - struct ad714x_chip *chip = spi_get_drvdata(spi); 107 - 108 - ad714x_remove(chip); 109 - 110 - return 0; 111 - } 112 - 113 104 static struct spi_driver ad714x_spi_driver = { 114 105 .driver = { 115 106 .name = "ad714x_captouch", ··· 108 117 .pm = &ad714x_spi_pm, 109 118 }, 110 119 .probe = ad714x_spi_probe, 111 - .remove = ad714x_spi_remove, 112 120 }; 113 121 114 122 module_spi_driver(ad714x_spi_driver);
+79 -129
drivers/input/misc/ad714x.c
··· 960 960 return IRQ_HANDLED; 961 961 } 962 962 963 - #define MAX_DEVICE_NUM 8 964 963 struct ad714x_chip *ad714x_probe(struct device *dev, u16 bus_type, int irq, 965 964 ad714x_read_t read, ad714x_write_t write) 966 965 { 967 - int i, alloc_idx; 966 + int i; 968 967 int error; 969 - struct input_dev *input[MAX_DEVICE_NUM]; 968 + struct input_dev *input; 970 969 971 970 struct ad714x_platform_data *plat_data = dev_get_platdata(dev); 972 971 struct ad714x_chip *ad714x; ··· 981 982 if (irq <= 0) { 982 983 dev_err(dev, "IRQ not configured!\n"); 983 984 error = -EINVAL; 984 - goto err_out; 985 + return ERR_PTR(error); 985 986 } 986 987 987 988 if (dev_get_platdata(dev) == NULL) { 988 989 dev_err(dev, "platform data for ad714x doesn't exist\n"); 989 990 error = -EINVAL; 990 - goto err_out; 991 + return ERR_PTR(error); 991 992 } 992 993 993 - ad714x = kzalloc(sizeof(*ad714x) + sizeof(*ad714x->sw) + 994 - sizeof(*sd_drv) * plat_data->slider_num + 995 - sizeof(*wl_drv) * plat_data->wheel_num + 996 - sizeof(*tp_drv) * plat_data->touchpad_num + 997 - sizeof(*bt_drv) * plat_data->button_num, GFP_KERNEL); 994 + ad714x = devm_kzalloc(dev, sizeof(*ad714x) + sizeof(*ad714x->sw) + 995 + sizeof(*sd_drv) * plat_data->slider_num + 996 + sizeof(*wl_drv) * plat_data->wheel_num + 997 + sizeof(*tp_drv) * plat_data->touchpad_num + 998 + sizeof(*bt_drv) * plat_data->button_num, 999 + GFP_KERNEL); 998 1000 if (!ad714x) { 999 1001 error = -ENOMEM; 1000 - goto err_out; 1002 + return ERR_PTR(error); 1001 1003 } 1002 - 1003 1004 ad714x->hw = plat_data; 1004 1005 1005 1006 drv_mem = ad714x + 1; ··· 1021 1022 1022 1023 error = ad714x_hw_detect(ad714x); 1023 1024 if (error) 1024 - goto err_free_mem; 1025 + return ERR_PTR(error); 1025 1026 1026 1027 /* initialize and request sw/hw resources */ 1027 1028 1028 1029 ad714x_hw_init(ad714x); 1029 1030 mutex_init(&ad714x->mutex); 1030 1031 1031 - /* 1032 - * Allocate and register AD714X input device 1033 - */ 1034 - alloc_idx = 0; 1035 - 1036 1032 /* a slider uses one input_dev instance */ 1037 1033 if (ad714x->hw->slider_num > 0) { 1038 1034 struct ad714x_slider_plat *sd_plat = ad714x->hw->slider; 1039 1035 1040 1036 for (i = 0; i < ad714x->hw->slider_num; i++) { 1041 - sd_drv[i].input = input[alloc_idx] = input_allocate_device(); 1042 - if (!input[alloc_idx]) { 1043 - error = -ENOMEM; 1044 - goto err_free_dev; 1045 - } 1037 + input = devm_input_allocate_device(dev); 1038 + if (!input) 1039 + return ERR_PTR(-ENOMEM); 1046 1040 1047 - __set_bit(EV_ABS, input[alloc_idx]->evbit); 1048 - __set_bit(EV_KEY, input[alloc_idx]->evbit); 1049 - __set_bit(ABS_X, input[alloc_idx]->absbit); 1050 - __set_bit(BTN_TOUCH, input[alloc_idx]->keybit); 1051 - input_set_abs_params(input[alloc_idx], 1041 + __set_bit(EV_ABS, input->evbit); 1042 + __set_bit(EV_KEY, input->evbit); 1043 + __set_bit(ABS_X, input->absbit); 1044 + __set_bit(BTN_TOUCH, input->keybit); 1045 + input_set_abs_params(input, 1052 1046 ABS_X, 0, sd_plat->max_coord, 0, 0); 1053 1047 1054 - input[alloc_idx]->id.bustype = bus_type; 1055 - input[alloc_idx]->id.product = ad714x->product; 1056 - input[alloc_idx]->id.version = ad714x->version; 1057 - input[alloc_idx]->name = "ad714x_captouch_slider"; 1058 - input[alloc_idx]->dev.parent = dev; 1048 + input->id.bustype = bus_type; 1049 + input->id.product = ad714x->product; 1050 + input->id.version = ad714x->version; 1051 + input->name = "ad714x_captouch_slider"; 1052 + input->dev.parent = dev; 1059 1053 1060 - error = input_register_device(input[alloc_idx]); 1054 + error = input_register_device(input); 1061 1055 if (error) 1062 - goto err_free_dev; 1056 + return ERR_PTR(error); 1063 1057 1064 - alloc_idx++; 1058 + sd_drv[i].input = input; 1065 1059 } 1066 1060 } 1067 1061 ··· 1063 1071 struct ad714x_wheel_plat *wl_plat = ad714x->hw->wheel; 1064 1072 1065 1073 for (i = 0; i < ad714x->hw->wheel_num; i++) { 1066 - wl_drv[i].input = input[alloc_idx] = input_allocate_device(); 1067 - if (!input[alloc_idx]) { 1068 - error = -ENOMEM; 1069 - goto err_free_dev; 1070 - } 1074 + input = devm_input_allocate_device(dev); 1075 + if (!input) 1076 + return ERR_PTR(-ENOMEM); 1071 1077 1072 - __set_bit(EV_KEY, input[alloc_idx]->evbit); 1073 - __set_bit(EV_ABS, input[alloc_idx]->evbit); 1074 - __set_bit(ABS_WHEEL, input[alloc_idx]->absbit); 1075 - __set_bit(BTN_TOUCH, input[alloc_idx]->keybit); 1076 - input_set_abs_params(input[alloc_idx], 1078 + __set_bit(EV_KEY, input->evbit); 1079 + __set_bit(EV_ABS, input->evbit); 1080 + __set_bit(ABS_WHEEL, input->absbit); 1081 + __set_bit(BTN_TOUCH, input->keybit); 1082 + input_set_abs_params(input, 1077 1083 ABS_WHEEL, 0, wl_plat->max_coord, 0, 0); 1078 1084 1079 - input[alloc_idx]->id.bustype = bus_type; 1080 - input[alloc_idx]->id.product = ad714x->product; 1081 - input[alloc_idx]->id.version = ad714x->version; 1082 - input[alloc_idx]->name = "ad714x_captouch_wheel"; 1083 - input[alloc_idx]->dev.parent = dev; 1085 + input->id.bustype = bus_type; 1086 + input->id.product = ad714x->product; 1087 + input->id.version = ad714x->version; 1088 + input->name = "ad714x_captouch_wheel"; 1089 + input->dev.parent = dev; 1084 1090 1085 - error = input_register_device(input[alloc_idx]); 1091 + error = input_register_device(input); 1086 1092 if (error) 1087 - goto err_free_dev; 1093 + return ERR_PTR(error); 1088 1094 1089 - alloc_idx++; 1095 + wl_drv[i].input = input; 1090 1096 } 1091 1097 } 1092 1098 ··· 1093 1103 struct ad714x_touchpad_plat *tp_plat = ad714x->hw->touchpad; 1094 1104 1095 1105 for (i = 0; i < ad714x->hw->touchpad_num; i++) { 1096 - tp_drv[i].input = input[alloc_idx] = input_allocate_device(); 1097 - if (!input[alloc_idx]) { 1098 - error = -ENOMEM; 1099 - goto err_free_dev; 1100 - } 1106 + input = devm_input_allocate_device(dev); 1107 + if (!input) 1108 + return ERR_PTR(-ENOMEM); 1101 1109 1102 - __set_bit(EV_ABS, input[alloc_idx]->evbit); 1103 - __set_bit(EV_KEY, input[alloc_idx]->evbit); 1104 - __set_bit(ABS_X, input[alloc_idx]->absbit); 1105 - __set_bit(ABS_Y, input[alloc_idx]->absbit); 1106 - __set_bit(BTN_TOUCH, input[alloc_idx]->keybit); 1107 - input_set_abs_params(input[alloc_idx], 1110 + __set_bit(EV_ABS, input->evbit); 1111 + __set_bit(EV_KEY, input->evbit); 1112 + __set_bit(ABS_X, input->absbit); 1113 + __set_bit(ABS_Y, input->absbit); 1114 + __set_bit(BTN_TOUCH, input->keybit); 1115 + input_set_abs_params(input, 1108 1116 ABS_X, 0, tp_plat->x_max_coord, 0, 0); 1109 - input_set_abs_params(input[alloc_idx], 1117 + input_set_abs_params(input, 1110 1118 ABS_Y, 0, tp_plat->y_max_coord, 0, 0); 1111 1119 1112 - input[alloc_idx]->id.bustype = bus_type; 1113 - input[alloc_idx]->id.product = ad714x->product; 1114 - input[alloc_idx]->id.version = ad714x->version; 1115 - input[alloc_idx]->name = "ad714x_captouch_pad"; 1116 - input[alloc_idx]->dev.parent = dev; 1120 + input->id.bustype = bus_type; 1121 + input->id.product = ad714x->product; 1122 + input->id.version = ad714x->version; 1123 + input->name = "ad714x_captouch_pad"; 1124 + input->dev.parent = dev; 1117 1125 1118 - error = input_register_device(input[alloc_idx]); 1126 + error = input_register_device(input); 1119 1127 if (error) 1120 - goto err_free_dev; 1128 + return ERR_PTR(error); 1121 1129 1122 - alloc_idx++; 1130 + tp_drv[i].input = input; 1123 1131 } 1124 1132 } 1125 1133 ··· 1125 1137 if (ad714x->hw->button_num > 0) { 1126 1138 struct ad714x_button_plat *bt_plat = ad714x->hw->button; 1127 1139 1128 - input[alloc_idx] = input_allocate_device(); 1129 - if (!input[alloc_idx]) { 1140 + input = devm_input_allocate_device(dev); 1141 + if (!input) { 1130 1142 error = -ENOMEM; 1131 - goto err_free_dev; 1143 + return ERR_PTR(error); 1132 1144 } 1133 1145 1134 - __set_bit(EV_KEY, input[alloc_idx]->evbit); 1146 + __set_bit(EV_KEY, input->evbit); 1135 1147 for (i = 0; i < ad714x->hw->button_num; i++) { 1136 - bt_drv[i].input = input[alloc_idx]; 1137 - __set_bit(bt_plat[i].keycode, input[alloc_idx]->keybit); 1148 + bt_drv[i].input = input; 1149 + __set_bit(bt_plat[i].keycode, input->keybit); 1138 1150 } 1139 1151 1140 - input[alloc_idx]->id.bustype = bus_type; 1141 - input[alloc_idx]->id.product = ad714x->product; 1142 - input[alloc_idx]->id.version = ad714x->version; 1143 - input[alloc_idx]->name = "ad714x_captouch_button"; 1144 - input[alloc_idx]->dev.parent = dev; 1152 + input->id.bustype = bus_type; 1153 + input->id.product = ad714x->product; 1154 + input->id.version = ad714x->version; 1155 + input->name = "ad714x_captouch_button"; 1156 + input->dev.parent = dev; 1145 1157 1146 - error = input_register_device(input[alloc_idx]); 1158 + error = input_register_device(input); 1147 1159 if (error) 1148 - goto err_free_dev; 1149 - 1150 - alloc_idx++; 1160 + return ERR_PTR(error); 1151 1161 } 1152 1162 1153 1163 irqflags = plat_data->irqflags ?: IRQF_TRIGGER_FALLING; 1154 1164 irqflags |= IRQF_ONESHOT; 1155 1165 1156 - error = request_threaded_irq(ad714x->irq, NULL, ad714x_interrupt_thread, 1157 - irqflags, "ad714x_captouch", ad714x); 1166 + error = devm_request_threaded_irq(dev, ad714x->irq, NULL, 1167 + ad714x_interrupt_thread, 1168 + irqflags, "ad714x_captouch", ad714x); 1158 1169 if (error) { 1159 1170 dev_err(dev, "can't allocate irq %d\n", ad714x->irq); 1160 - goto err_unreg_dev; 1171 + return ERR_PTR(error); 1161 1172 } 1162 1173 1163 1174 return ad714x; 1164 - 1165 - err_free_dev: 1166 - dev_err(dev, "failed to setup AD714x input device %i\n", alloc_idx); 1167 - input_free_device(input[alloc_idx]); 1168 - err_unreg_dev: 1169 - while (--alloc_idx >= 0) 1170 - input_unregister_device(input[alloc_idx]); 1171 - err_free_mem: 1172 - kfree(ad714x); 1173 - err_out: 1174 - return ERR_PTR(error); 1175 1175 } 1176 1176 EXPORT_SYMBOL(ad714x_probe); 1177 - 1178 - void ad714x_remove(struct ad714x_chip *ad714x) 1179 - { 1180 - struct ad714x_platform_data *hw = ad714x->hw; 1181 - struct ad714x_driver_data *sw = ad714x->sw; 1182 - int i; 1183 - 1184 - free_irq(ad714x->irq, ad714x); 1185 - 1186 - /* unregister and free all input devices */ 1187 - 1188 - for (i = 0; i < hw->slider_num; i++) 1189 - input_unregister_device(sw->slider[i].input); 1190 - 1191 - for (i = 0; i < hw->wheel_num; i++) 1192 - input_unregister_device(sw->wheel[i].input); 1193 - 1194 - for (i = 0; i < hw->touchpad_num; i++) 1195 - input_unregister_device(sw->touchpad[i].input); 1196 - 1197 - if (hw->button_num) 1198 - input_unregister_device(sw->button[0].input); 1199 - 1200 - kfree(ad714x); 1201 - } 1202 - EXPORT_SYMBOL(ad714x_remove); 1203 1177 1204 1178 #ifdef CONFIG_PM 1205 1179 int ad714x_disable(struct ad714x_chip *ad714x)
-1
drivers/input/misc/ad714x.h
··· 50 50 int ad714x_enable(struct ad714x_chip *ad714x); 51 51 struct ad714x_chip *ad714x_probe(struct device *dev, u16 bus_type, int irq, 52 52 ad714x_read_t read, ad714x_write_t write); 53 - void ad714x_remove(struct ad714x_chip *ad714x); 54 53 55 54 #endif