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: raydium_i2c_ts - switch to using cleanup functions

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

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

+24 -32
+24 -32
drivers/input/touchscreen/raydium_i2c_ts.c
··· 169 169 { 170 170 int tries = 0; 171 171 int error; 172 - u8 *tx_buf; 173 172 u8 reg_addr = addr & 0xff; 174 173 175 - tx_buf = kmalloc(len + 1, GFP_KERNEL); 174 + u8 *tx_buf __free(kfree) = kmalloc(len + 1, GFP_KERNEL); 176 175 if (!tx_buf) 177 176 return -ENOMEM; 178 177 ··· 209 210 210 211 error = raydium_i2c_xfer(client, addr, xfer, ARRAY_SIZE(xfer)); 211 212 if (likely(!error)) 212 - goto out; 213 + return 0; 213 214 214 215 msleep(RM_RETRY_DELAY_MS); 215 216 } while (++tries < RM_MAX_RETRIES); 216 217 217 218 dev_err(&client->dev, "%s failed: %d\n", __func__, error); 218 - out: 219 - kfree(tx_buf); 220 219 return error; 221 220 } 222 221 ··· 812 815 static int raydium_i2c_fw_update(struct raydium_data *ts) 813 816 { 814 817 struct i2c_client *client = ts->client; 815 - const struct firmware *fw = NULL; 816 - char *fw_file; 817 818 int error; 818 819 819 - fw_file = kasprintf(GFP_KERNEL, "raydium_%#04x.fw", 820 - le32_to_cpu(ts->info.hw_ver)); 820 + const char *fw_file __free(kfree) = 821 + kasprintf(GFP_KERNEL, "raydium_%#04x.fw", 822 + le32_to_cpu(ts->info.hw_ver)); 821 823 if (!fw_file) 822 824 return -ENOMEM; 823 825 824 826 dev_dbg(&client->dev, "firmware name: %s\n", fw_file); 825 827 828 + const struct firmware *fw __free(firmware) = NULL; 826 829 error = request_firmware(&fw, fw_file, &client->dev); 827 830 if (error) { 828 831 dev_err(&client->dev, "Unable to open firmware %s\n", fw_file); 829 - goto out_free_fw_file; 832 + return error; 830 833 } 831 834 832 835 disable_irq(client->irq); ··· 852 855 out_enable_irq: 853 856 enable_irq(client->irq); 854 857 msleep(100); 855 - 856 - release_firmware(fw); 857 - 858 - out_free_fw_file: 859 - kfree(fw_file); 860 858 861 859 return error; 862 860 } ··· 957 965 struct raydium_data *ts = i2c_get_clientdata(client); 958 966 int error; 959 967 960 - error = mutex_lock_interruptible(&ts->sysfs_mutex); 961 - if (error) 962 - return error; 968 + scoped_guard(mutex_intr, &ts->sysfs_mutex) { 969 + error = raydium_i2c_fw_update(ts); 970 + return error ?: count; 971 + } 963 972 964 - error = raydium_i2c_fw_update(ts); 965 - 966 - mutex_unlock(&ts->sysfs_mutex); 967 - 968 - return error ?: count; 973 + return -EINTR; 969 974 } 970 975 971 976 static ssize_t raydium_i2c_calibrate_store(struct device *dev, ··· 974 985 static const u8 cal_cmd[] = { 0x00, 0x01, 0x9E }; 975 986 int error; 976 987 977 - error = mutex_lock_interruptible(&ts->sysfs_mutex); 978 - if (error) 979 - return error; 988 + scoped_guard(mutex_intr, &ts->sysfs_mutex) { 989 + error = raydium_i2c_write_object(client, 990 + cal_cmd, sizeof(cal_cmd), 991 + RAYDIUM_WAIT_READY); 992 + if (error) { 993 + dev_err(&client->dev, 994 + "calibrate command failed: %d\n", error); 995 + return error; 996 + } 980 997 981 - error = raydium_i2c_write_object(client, cal_cmd, sizeof(cal_cmd), 982 - RAYDIUM_WAIT_READY); 983 - if (error) 984 - dev_err(&client->dev, "calibrate command failed: %d\n", error); 998 + return count; 999 + } 985 1000 986 - mutex_unlock(&ts->sysfs_mutex); 987 - return error ?: count; 1001 + return -EINTR; 988 1002 } 989 1003 990 1004 static DEVICE_ATTR(fw_version, S_IRUGO, raydium_i2c_fw_ver_show, NULL);