Skip to content

Commit da52f4b

Browse files
committed
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>
1 parent e65407f commit da52f4b

1 file changed

Lines changed: 21 additions & 23 deletions

File tree

drivers/input/touchscreen/wdt87xx_i2c.c

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -813,68 +813,66 @@ static int wdt87xx_load_chunk(struct i2c_client *client,
813813
return 0;
814814
}
815815

816-
static int wdt87xx_do_update_firmware(struct i2c_client *client,
816+
static int wdt87xx_do_update_firmware(struct wdt87xx_data *wdt,
817817
const struct firmware *fw,
818818
unsigned int chunk_id)
819819
{
820-
struct wdt87xx_data *wdt = i2c_get_clientdata(client);
820+
struct i2c_client *client = wdt->client;
821821
int error;
822822

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-
833823
error = wdt87xx_load_chunk(client, fw, chunk_id);
834824
if (error) {
835825
dev_err(&client->dev,
836826
"firmware load failed (type: %d): %d\n",
837827
chunk_id, error);
838-
goto out;
828+
return error;
839829
}
840830

841831
error = wdt87xx_sw_reset(client);
842832
if (error) {
843833
dev_err(&client->dev, "soft reset failed: %d\n", error);
844-
goto out;
834+
return error;
845835
}
846836

847837
/* Refresh the parameters */
848838
error = wdt87xx_get_sysparam(client, &wdt->param);
849-
if (error)
839+
if (error) {
850840
dev_err(&client->dev,
851841
"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+
}
855844

856-
return error ? error : 0;
845+
return 0;
857846
}
858847

859848
static int wdt87xx_update_firmware(struct device *dev,
860849
const char *fw_name, unsigned int chunk_id)
861850
{
862851
struct i2c_client *client = to_i2c_client(dev);
863-
const struct firmware *fw;
852+
struct wdt87xx_data *wdt = i2c_get_clientdata(client);
864853
int error;
865854

855+
const struct firmware *fw __free(firmware) = NULL;
866856
error = request_firmware(&fw, fw_name, dev);
867857
if (error) {
868858
dev_err(&client->dev, "unable to retrieve firmware %s: %d\n",
869859
fw_name, error);
870860
return error;
871861
}
872862

873-
error = wdt87xx_do_update_firmware(client, fw, chunk_id);
863+
error = wdt87xx_validate_firmware(wdt, fw);
864+
if (error)
865+
return error;
866+
867+
scoped_cond_guard(mutex_intr, return -EINTR, &wdt->fw_mutex) {
868+
guard(disable_irq)(&client->irq);
874869

875-
release_firmware(fw);
870+
error = wdt87xx_do_update_firmware(wdt, fw, chunk_id);
871+
if (error)
872+
return error;
873+
}
876874

877-
return error ? error : 0;
875+
return 0;
878876
}
879877

880878
static ssize_t config_csum_show(struct device *dev,

0 commit comments

Comments
 (0)