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

Configure Feed

Select the types of activity you want to include in your feed.

Input: elants_i2c - switch to using cleanup facilities

Start using __free() and guard() primitives to simplify the code
and error handling.

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

+40 -53
+40 -53
drivers/input/touchscreen/elants_i2c.c
··· 303 303 static const u8 rek[] = { CMD_HEADER_WRITE, 0x29, 0x00, 0x01 }; 304 304 static const u8 rek_resp[] = { CMD_HEADER_REK, 0x66, 0x66, 0x66 }; 305 305 306 - disable_irq(client->irq); 306 + scoped_guard(disable_irq, &client->irq) { 307 + ts->state = ELAN_WAIT_RECALIBRATION; 308 + reinit_completion(&ts->cmd_done); 307 309 308 - ts->state = ELAN_WAIT_RECALIBRATION; 309 - reinit_completion(&ts->cmd_done); 310 - 311 - elants_i2c_send(client, w_flashkey, sizeof(w_flashkey)); 312 - elants_i2c_send(client, rek, sizeof(rek)); 313 - 314 - enable_irq(client->irq); 310 + elants_i2c_send(client, w_flashkey, sizeof(w_flashkey)); 311 + elants_i2c_send(client, rek, sizeof(rek)); 312 + } 315 313 316 314 ret = wait_for_completion_interruptible_timeout(&ts->cmd_done, 317 315 msecs_to_jiffies(ELAN_CALI_TIMEOUT_MSEC)); ··· 904 906 static int elants_i2c_fw_update(struct elants_data *ts) 905 907 { 906 908 struct i2c_client *client = ts->client; 907 - const struct firmware *fw; 908 - char *fw_name; 909 909 int error; 910 910 911 - fw_name = kasprintf(GFP_KERNEL, "elants_i2c_%04x.bin", ts->hw_version); 911 + const char *fw_name __free(kfree) = 912 + kasprintf(GFP_KERNEL, "elants_i2c_%04x.bin", ts->hw_version); 912 913 if (!fw_name) 913 914 return -ENOMEM; 914 915 915 916 dev_info(&client->dev, "requesting fw name = %s\n", fw_name); 917 + 918 + const struct firmware *fw __free(firmware) = NULL; 916 919 error = request_firmware(&fw, fw_name, &client->dev); 917 - kfree(fw_name); 918 920 if (error) { 919 921 dev_err(&client->dev, "failed to request firmware: %d\n", 920 922 error); ··· 924 926 if (fw->size % ELAN_FW_PAGESIZE) { 925 927 dev_err(&client->dev, "invalid firmware length: %zu\n", 926 928 fw->size); 927 - error = -EINVAL; 928 - goto out; 929 + return -EINVAL; 929 930 } 930 931 931 - disable_irq(client->irq); 932 + scoped_guard(disable_irq, &client->irq) { 933 + bool force_update = ts->iap_mode == ELAN_IAP_RECOVERY; 932 934 933 - error = elants_i2c_do_update_firmware(client, fw, 934 - ts->iap_mode == ELAN_IAP_RECOVERY); 935 - if (error) { 936 - dev_err(&client->dev, "firmware update failed: %d\n", error); 937 - ts->iap_mode = ELAN_IAP_RECOVERY; 938 - goto out_enable_irq; 935 + error = elants_i2c_do_update_firmware(client, fw, force_update); 936 + if (error) { 937 + dev_err(&client->dev, "firmware update failed: %d\n", 938 + error); 939 + } else { 940 + error = elants_i2c_initialize(ts); 941 + if (error) 942 + dev_err(&client->dev, 943 + "failed to initialize device after firmware update: %d\n", 944 + error); 945 + } 946 + 947 + ts->iap_mode = error ? ELAN_IAP_RECOVERY : ELAN_IAP_OPERATIONAL; 948 + ts->state = ELAN_STATE_NORMAL; 939 949 } 940 - 941 - error = elants_i2c_initialize(ts); 942 - if (error) { 943 - dev_err(&client->dev, 944 - "failed to initialize device after firmware update: %d\n", 945 - error); 946 - ts->iap_mode = ELAN_IAP_RECOVERY; 947 - goto out_enable_irq; 948 - } 949 - 950 - ts->iap_mode = ELAN_IAP_OPERATIONAL; 951 - 952 - out_enable_irq: 953 - ts->state = ELAN_STATE_NORMAL; 954 - enable_irq(client->irq); 955 950 msleep(100); 956 951 957 952 if (!error) 958 953 elants_i2c_calibrate(ts); 959 - out: 960 - release_firmware(fw); 954 + 961 955 return error; 962 956 } 963 957 ··· 1176 1186 struct elants_data *ts = i2c_get_clientdata(client); 1177 1187 int error; 1178 1188 1179 - error = mutex_lock_interruptible(&ts->sysfs_mutex); 1180 - if (error) 1181 - return error; 1189 + scoped_cond_guard(mutex_intr, return -EINTR, &ts->sysfs_mutex) { 1190 + error = elants_i2c_calibrate(ts); 1191 + if (error) 1192 + return error; 1193 + } 1182 1194 1183 - error = elants_i2c_calibrate(ts); 1184 - 1185 - mutex_unlock(&ts->sysfs_mutex); 1186 - return error ?: count; 1195 + return count; 1187 1196 } 1188 1197 1189 1198 static ssize_t write_update_fw(struct device *dev, ··· 1193 1204 struct elants_data *ts = i2c_get_clientdata(client); 1194 1205 int error; 1195 1206 1196 - error = mutex_lock_interruptible(&ts->sysfs_mutex); 1197 - if (error) 1198 - return error; 1207 + scoped_cond_guard(mutex_intr, return -EINTR, &ts->sysfs_mutex) { 1208 + error = elants_i2c_fw_update(ts); 1209 + if (error) 1210 + return error; 1211 + } 1199 1212 1200 - error = elants_i2c_fw_update(ts); 1201 - dev_dbg(dev, "firmware update result: %d\n", error); 1202 - 1203 - mutex_unlock(&ts->sysfs_mutex); 1204 - return error ?: count; 1213 + return count; 1205 1214 } 1206 1215 1207 1216 static ssize_t show_iap_mode(struct device *dev,