Skip to content

Commit 6797540

Browse files
rfvirgilbroonie
authored andcommitted
ASoC: cs-amp-lib: Use __free(kfree) instead of manual freeing
Use the __free(kfree) cleanup to replace instances of manually calling kfree(). Also make some code path simplifications that this allows. Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com> Link: https://patch.msgid.link/20251127155817.1374079-1-rf@opensource.cirrus.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent c45d5d9 commit 6797540

1 file changed

Lines changed: 12 additions & 17 deletions

File tree

sound/soc/codecs/cs-amp-lib.c

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <asm/byteorder.h>
99
#include <kunit/static_stub.h>
10+
#include <linux/cleanup.h>
1011
#include <linux/debugfs.h>
1112
#include <linux/dev_printk.h>
1213
#include <linux/efi.h>
@@ -309,9 +310,8 @@ static struct cirrus_amp_efi_data *cs_amp_get_cal_efi_buffer(struct device *dev,
309310
efi_guid_t **guid,
310311
u32 *attr)
311312
{
312-
struct cirrus_amp_efi_data *efi_data;
313+
struct cirrus_amp_efi_data *efi_data __free(kfree) = NULL;
313314
unsigned long data_size = 0;
314-
u8 *data;
315315
efi_status_t status;
316316
int i, ret;
317317

@@ -339,19 +339,18 @@ static struct cirrus_amp_efi_data *cs_amp_get_cal_efi_buffer(struct device *dev,
339339
}
340340

341341
/* Get variable contents into buffer */
342-
data = kmalloc(data_size, GFP_KERNEL);
343-
if (!data)
342+
efi_data = kmalloc(data_size, GFP_KERNEL);
343+
if (!efi_data)
344344
return ERR_PTR(-ENOMEM);
345345

346346
status = cs_amp_get_efi_variable(cs_amp_lib_cal_efivars[i].name,
347347
cs_amp_lib_cal_efivars[i].guid,
348-
attr, &data_size, data);
348+
attr, &data_size, efi_data);
349349
if (status != EFI_SUCCESS) {
350350
ret = -EINVAL;
351351
goto err;
352352
}
353353

354-
efi_data = (struct cirrus_amp_efi_data *)data;
355354
dev_dbg(dev, "Calibration: Size=%d, Amp Count=%d\n", efi_data->size, efi_data->count);
356355

357356
if ((efi_data->count > 128) ||
@@ -365,10 +364,9 @@ static struct cirrus_amp_efi_data *cs_amp_get_cal_efi_buffer(struct device *dev,
365364
if (efi_data->size == 0)
366365
efi_data->size = data_size;
367366

368-
return efi_data;
367+
return_ptr(efi_data);
369368

370369
err:
371-
kfree(data);
372370
dev_err(dev, "Failed to read calibration data from EFI: %d\n", ret);
373371

374372
return ERR_PTR(ret);
@@ -391,9 +389,9 @@ static int cs_amp_set_cal_efi_buffer(struct device *dev,
391389
static int _cs_amp_get_efi_calibration_data(struct device *dev, u64 target_uid, int amp_index,
392390
struct cirrus_amp_cal_data *out_data)
393391
{
394-
struct cirrus_amp_efi_data *efi_data;
392+
struct cirrus_amp_efi_data *efi_data __free(kfree) = NULL;
395393
struct cirrus_amp_cal_data *cal = NULL;
396-
int i, ret;
394+
int i;
397395

398396
efi_data = cs_amp_get_cal_efi_buffer(dev, NULL, NULL, NULL);
399397
if (IS_ERR(efi_data))
@@ -434,17 +432,14 @@ static int _cs_amp_get_efi_calibration_data(struct device *dev, u64 target_uid,
434432
dev_warn(dev, "Calibration entry %d does not match silicon ID", amp_index);
435433
}
436434

437-
if (cal) {
438-
memcpy(out_data, cal, sizeof(*out_data));
439-
ret = 0;
440-
} else {
435+
if (!cal) {
441436
dev_warn(dev, "No calibration for silicon ID %#llx\n", target_uid);
442-
ret = -ENOENT;
437+
return -ENOENT;
443438
}
444439

445-
kfree(efi_data);
440+
memcpy(out_data, cal, sizeof(*out_data));
446441

447-
return ret;
442+
return 0;
448443
}
449444

450445
static int _cs_amp_set_efi_calibration_data(struct device *dev, int amp_index, int num_amps,

0 commit comments

Comments
 (0)