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

+21 -23
+21 -23
drivers/input/touchscreen/wdt87xx_i2c.c
··· 813 813 return 0; 814 814 } 815 815 816 - static int wdt87xx_do_update_firmware(struct i2c_client *client, 816 + static int wdt87xx_do_update_firmware(struct wdt87xx_data *wdt, 817 817 const struct firmware *fw, 818 818 unsigned int chunk_id) 819 819 { 820 - struct wdt87xx_data *wdt = i2c_get_clientdata(client); 820 + struct i2c_client *client = wdt->client; 821 821 int error; 822 - 823 - error = wdt87xx_validate_firmware(wdt, fw); 824 - if (error) 825 - return error; 826 - 827 - error = mutex_lock_interruptible(&wdt->fw_mutex); 828 - if (error) 829 - return error; 830 - 831 - disable_irq(client->irq); 832 822 833 823 error = wdt87xx_load_chunk(client, fw, chunk_id); 834 824 if (error) { 835 825 dev_err(&client->dev, 836 826 "firmware load failed (type: %d): %d\n", 837 827 chunk_id, error); 838 - goto out; 828 + return error; 839 829 } 840 830 841 831 error = wdt87xx_sw_reset(client); 842 832 if (error) { 843 833 dev_err(&client->dev, "soft reset failed: %d\n", error); 844 - goto out; 834 + return error; 845 835 } 846 836 847 837 /* Refresh the parameters */ 848 838 error = wdt87xx_get_sysparam(client, &wdt->param); 849 - if (error) 839 + if (error) { 850 840 dev_err(&client->dev, 851 841 "failed to refresh system parameters: %d\n", error); 852 - out: 853 - enable_irq(client->irq); 854 - mutex_unlock(&wdt->fw_mutex); 842 + return error; 843 + } 855 844 856 - return error ? error : 0; 845 + return 0; 857 846 } 858 847 859 848 static int wdt87xx_update_firmware(struct device *dev, 860 849 const char *fw_name, unsigned int chunk_id) 861 850 { 862 851 struct i2c_client *client = to_i2c_client(dev); 863 - const struct firmware *fw; 852 + struct wdt87xx_data *wdt = i2c_get_clientdata(client); 864 853 int error; 865 854 855 + const struct firmware *fw __free(firmware) = NULL; 866 856 error = request_firmware(&fw, fw_name, dev); 867 857 if (error) { 868 858 dev_err(&client->dev, "unable to retrieve firmware %s: %d\n", ··· 860 870 return error; 861 871 } 862 872 863 - error = wdt87xx_do_update_firmware(client, fw, chunk_id); 873 + error = wdt87xx_validate_firmware(wdt, fw); 874 + if (error) 875 + return error; 864 876 865 - release_firmware(fw); 877 + scoped_cond_guard(mutex_intr, return -EINTR, &wdt->fw_mutex) { 878 + guard(disable_irq)(&client->irq); 866 879 867 - return error ? error : 0; 880 + error = wdt87xx_do_update_firmware(wdt, fw, chunk_id); 881 + if (error) 882 + return error; 883 + } 884 + 885 + return 0; 868 886 } 869 887 870 888 static ssize_t config_csum_show(struct device *dev,