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: hideep - 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>

+20 -34
+20 -34
drivers/input/touchscreen/hideep.c
··· 869 869 { 870 870 struct i2c_client *client = to_i2c_client(dev); 871 871 struct hideep_ts *ts = i2c_get_clientdata(client); 872 - const struct firmware *fw_entry; 873 - char *fw_name; 874 872 int mode; 875 873 int error; 876 874 ··· 876 878 if (error) 877 879 return error; 878 880 879 - fw_name = kasprintf(GFP_KERNEL, "hideep_ts_%04x.bin", 880 - be16_to_cpu(ts->dwz_info.product_id)); 881 + const char *fw_name __free(kfree) = 882 + kasprintf(GFP_KERNEL, "hideep_ts_%04x.bin", 883 + be16_to_cpu(ts->dwz_info.product_id)); 881 884 if (!fw_name) 882 885 return -ENOMEM; 883 886 887 + const struct firmware *fw_entry __free(firmware) = NULL; 884 888 error = request_firmware(&fw_entry, fw_name, dev); 885 889 if (error) { 886 890 dev_err(dev, "failed to request firmware %s: %d", 887 891 fw_name, error); 888 - goto out_free_fw_name; 892 + return error; 889 893 } 890 894 891 895 if (fw_entry->size % sizeof(__be32)) { 892 896 dev_err(dev, "invalid firmware size %zu\n", fw_entry->size); 893 - error = -EINVAL; 894 - goto out_release_fw; 897 + return -EINVAL; 895 898 } 896 899 897 900 if (fw_entry->size > ts->fw_size) { 898 901 dev_err(dev, "fw size (%zu) is too big (memory size %d)\n", 899 902 fw_entry->size, ts->fw_size); 900 - error = -EFBIG; 901 - goto out_release_fw; 903 + return -EFBIG; 902 904 } 903 905 904 - mutex_lock(&ts->dev_mutex); 905 - disable_irq(client->irq); 906 + scoped_guard(mutex, &ts->dev_mutex) { 907 + guard(disable_irq)(&client->irq); 906 908 907 - error = hideep_update_firmware(ts, (const __be32 *)fw_entry->data, 908 - fw_entry->size); 909 + error = hideep_update_firmware(ts, 910 + (const __be32 *)fw_entry->data, 911 + fw_entry->size); 912 + if (error) 913 + return error; 914 + } 909 915 910 - enable_irq(client->irq); 911 - mutex_unlock(&ts->dev_mutex); 912 - 913 - out_release_fw: 914 - release_firmware(fw_entry); 915 - out_free_fw_name: 916 - kfree(fw_name); 917 - 918 - return error ?: count; 916 + return count; 919 917 } 920 918 921 919 static ssize_t hideep_fw_version_show(struct device *dev, ··· 919 925 { 920 926 struct i2c_client *client = to_i2c_client(dev); 921 927 struct hideep_ts *ts = i2c_get_clientdata(client); 922 - ssize_t len; 923 928 924 - mutex_lock(&ts->dev_mutex); 925 - len = sysfs_emit(buf, "%04x\n", be16_to_cpu(ts->dwz_info.release_ver)); 926 - mutex_unlock(&ts->dev_mutex); 927 - 928 - return len; 929 + guard(mutex)(&ts->dev_mutex); 930 + return sysfs_emit(buf, "%04x\n", be16_to_cpu(ts->dwz_info.release_ver)); 929 931 } 930 932 931 933 static ssize_t hideep_product_id_show(struct device *dev, ··· 929 939 { 930 940 struct i2c_client *client = to_i2c_client(dev); 931 941 struct hideep_ts *ts = i2c_get_clientdata(client); 932 - ssize_t len; 933 942 934 - mutex_lock(&ts->dev_mutex); 935 - len = sysfs_emit(buf, "%04x\n", be16_to_cpu(ts->dwz_info.product_id)); 936 - mutex_unlock(&ts->dev_mutex); 937 - 938 - return len; 943 + guard(mutex)(&ts->dev_mutex); 944 + return sysfs_emit(buf, "%04x\n", be16_to_cpu(ts->dwz_info.product_id)); 939 945 } 940 946 941 947 static DEVICE_ATTR(version, 0664, hideep_fw_version_show, NULL);