Skip to content

Commit f2845b4

Browse files
committed
Input: rohm_bu21023 - switch to using cleanup functions
Start using __free() and guard() primitives to simplify the code and error handling. Link: https://lore.kernel.org/r/20240609235134.614592-3-dmitry.torokhov@gmail.com Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
1 parent bf5cba8 commit f2845b4

1 file changed

Lines changed: 19 additions & 21 deletions

File tree

drivers/input/touchscreen/rohm_bu21023.c

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -643,12 +643,12 @@ static int rohm_ts_load_firmware(struct i2c_client *client,
643643
const char *firmware_name)
644644
{
645645
struct device *dev = &client->dev;
646-
const struct firmware *fw;
647646
s32 status;
648647
unsigned int offset, len, xfer_len;
649648
unsigned int retry = 0;
650649
int error, error2;
651650

651+
const struct firmware *fw __free(firmware) = NULL;
652652
error = request_firmware(&fw, firmware_name, dev);
653653
if (error) {
654654
dev_err(dev, "unable to retrieve firmware %s: %d\n",
@@ -722,8 +722,6 @@ static int rohm_ts_load_firmware(struct i2c_client *client,
722722
out:
723723
error2 = i2c_smbus_write_byte_data(client, INT_MASK, INT_ALL);
724724

725-
release_firmware(fw);
726-
727725
return error ? error : error2;
728726
}
729727

@@ -732,22 +730,22 @@ static int rohm_ts_update_setting(struct rohm_ts_data *ts,
732730
{
733731
int error;
734732

735-
error = mutex_lock_interruptible(&ts->input->mutex);
736-
if (error)
737-
return error;
738-
739-
if (on)
740-
ts->setup2 |= setting_bit;
741-
else
742-
ts->setup2 &= ~setting_bit;
733+
scoped_cond_guard(mutex_intr, return -EINTR, &ts->input->mutex) {
734+
if (on)
735+
ts->setup2 |= setting_bit;
736+
else
737+
ts->setup2 &= ~setting_bit;
743738

744-
if (ts->initialized)
745-
error = i2c_smbus_write_byte_data(ts->client, COMMON_SETUP2,
746-
ts->setup2);
747-
748-
mutex_unlock(&ts->input->mutex);
739+
if (ts->initialized) {
740+
error = i2c_smbus_write_byte_data(ts->client,
741+
COMMON_SETUP2,
742+
ts->setup2);
743+
if (error)
744+
return error;
745+
}
746+
}
749747

750-
return error;
748+
return 0;
751749
}
752750

753751
static ssize_t swap_xy_show(struct device *dev, struct device_attribute *attr,
@@ -842,7 +840,7 @@ static int rohm_ts_device_init(struct i2c_client *client, u8 setup2)
842840
struct device *dev = &client->dev;
843841
int error;
844842

845-
disable_irq(client->irq);
843+
guard(disable_irq)(&client->irq);
846844

847845
/*
848846
* Wait 200usec for reset
@@ -1017,10 +1015,10 @@ static int rohm_ts_device_init(struct i2c_client *client, u8 setup2)
10171015
/* controller CPU power on */
10181016
error = i2c_smbus_write_byte_data(client, SYSTEM,
10191017
ANALOG_POWER_ON | CPU_POWER_ON);
1018+
if (error)
1019+
return error;
10201020

1021-
enable_irq(client->irq);
1022-
1023-
return error;
1021+
return 0;
10241022
}
10251023

10261024
static int rohm_ts_power_off(struct i2c_client *client)

0 commit comments

Comments
 (0)