Skip to content

Commit cbdc3f9

Browse files
committed
Input: synaptics-rmi4 - switch to using cleanup functions in F34
Start using __free() and guard() primitives to simplify the code and error handling. Reviewed-by: Lyude Paul <lyude@redhat.com> Link: https://lore.kernel.org/r/Zxwd9c0njasZZoal@google.com Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
1 parent 7ec151f commit cbdc3f9

File tree

1 file changed

+14
-23
lines changed

1 file changed

+14
-23
lines changed

drivers/input/rmi4/rmi_f34.c

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,6 @@ static int rmi_f34_update_firmware(struct f34_data *f34,
246246
(const struct rmi_f34_firmware *)fw->data;
247247
u32 image_size = le32_to_cpu(syn_fw->image_size);
248248
u32 config_size = le32_to_cpu(syn_fw->config_size);
249-
int ret;
250249

251250
BUILD_BUG_ON(offsetof(struct rmi_f34_firmware, data) !=
252251
F34_FW_IMAGE_OFFSET);
@@ -267,8 +266,7 @@ static int rmi_f34_update_firmware(struct f34_data *f34,
267266
dev_err(&f34->fn->dev,
268267
"Bad firmware image: fw size %d, expected %d\n",
269268
image_size, f34->v5.fw_blocks * f34->v5.block_size);
270-
ret = -EILSEQ;
271-
goto out;
269+
return -EILSEQ;
272270
}
273271

274272
if (config_size &&
@@ -277,25 +275,18 @@ static int rmi_f34_update_firmware(struct f34_data *f34,
277275
"Bad firmware image: config size %d, expected %d\n",
278276
config_size,
279277
f34->v5.config_blocks * f34->v5.block_size);
280-
ret = -EILSEQ;
281-
goto out;
278+
return -EILSEQ;
282279
}
283280

284281
if (image_size && !config_size) {
285282
dev_err(&f34->fn->dev, "Bad firmware image: no config data\n");
286-
ret = -EILSEQ;
287-
goto out;
283+
return -EILSEQ;
288284
}
289285

290286
dev_info(&f34->fn->dev, "Firmware image OK\n");
291-
mutex_lock(&f34->v5.flash_mutex);
292-
293-
ret = rmi_f34_flash_firmware(f34, syn_fw);
294287

295-
mutex_unlock(&f34->v5.flash_mutex);
296-
297-
out:
298-
return ret;
288+
guard(mutex)(&f34->v5.flash_mutex);
289+
return rmi_f34_flash_firmware(f34, syn_fw);
299290
}
300291

301292
static int rmi_f34_status(struct rmi_function *fn)
@@ -461,9 +452,8 @@ static ssize_t rmi_driver_update_fw_store(struct device *dev,
461452
{
462453
struct rmi_driver_data *data = dev_get_drvdata(dev);
463454
char fw_name[NAME_MAX];
464-
const struct firmware *fw;
465455
size_t copy_count = count;
466-
int ret;
456+
int error;
467457

468458
if (count == 0 || count >= NAME_MAX)
469459
return -EINVAL;
@@ -474,17 +464,18 @@ static ssize_t rmi_driver_update_fw_store(struct device *dev,
474464
memcpy(fw_name, buf, copy_count);
475465
fw_name[copy_count] = '\0';
476466

477-
ret = request_firmware(&fw, fw_name, dev);
478-
if (ret)
479-
return ret;
467+
const struct firmware *fw __free(firmware) = NULL;
468+
error = request_firmware(&fw, fw_name, dev);
469+
if (error)
470+
return error;
480471

481472
dev_info(dev, "Flashing %s\n", fw_name);
482473

483-
ret = rmi_firmware_update(data, fw);
484-
485-
release_firmware(fw);
474+
error = rmi_firmware_update(data, fw);
475+
if (error)
476+
return error;
486477

487-
return ret ?: count;
478+
return count;
488479
}
489480

490481
static DEVICE_ATTR(update_fw, 0200, NULL, rmi_driver_update_fw_store);

0 commit comments

Comments
 (0)