Skip to content

Commit 2b69bee

Browse files
rfvirgilbroonie
authored andcommitted
ASoC: cs-amp-lib: Revert use of __free(kfree) back to normal C cleanup
Revert commit 6797540 ("ASoC: cs-amp-lib: Use __free(kfree) instead of manual freeing"). Krzysztof Kozlowski pointed out that __free() can be dangerous. It can introduce new cleanup bugs. These are more subtle and difficult to spot than a missing goto in traditional cleanup, because they are triggered by writing regular idiomatic C code instead of using C++ conventions. As it's regular C style it's more likely to be missed because the code is as would be expected for C. The traditional goto also more obviously flags to anyone changing the code in the future that they must be careful about the cleanup. We can just revert the change. There was nothing wrong with the original code and as Krzysztof noted: "it does not make the code simpler." Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com> Fixes: 6797540 ("ASoC: cs-amp-lib: Use __free(kfree) instead of manual freeing") Link: https://patch.msgid.link/20251201111429.43517-1-rf@opensource.cirrus.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent c5fae31 commit 2b69bee

1 file changed

Lines changed: 17 additions & 12 deletions

File tree

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

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

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

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

341341
/* Get variable contents into buffer */
342-
efi_data = kmalloc(data_size, GFP_KERNEL);
343-
if (!efi_data)
342+
data = kmalloc(data_size, GFP_KERNEL);
343+
if (!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, efi_data);
348+
attr, &data_size, data);
349349
if (status != EFI_SUCCESS) {
350350
ret = -EINVAL;
351351
goto err;
352352
}
353353

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

356357
if ((efi_data->count > 128) ||
@@ -364,9 +365,10 @@ static struct cirrus_amp_efi_data *cs_amp_get_cal_efi_buffer(struct device *dev,
364365
if (efi_data->size == 0)
365366
efi_data->size = data_size;
366367

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

369370
err:
371+
kfree(data);
370372
dev_err(dev, "Failed to read calibration data from EFI: %d\n", ret);
371373

372374
return ERR_PTR(ret);
@@ -389,9 +391,9 @@ static int cs_amp_set_cal_efi_buffer(struct device *dev,
389391
static int _cs_amp_get_efi_calibration_data(struct device *dev, u64 target_uid, int amp_index,
390392
struct cirrus_amp_cal_data *out_data)
391393
{
392-
struct cirrus_amp_efi_data *efi_data __free(kfree) = NULL;
394+
struct cirrus_amp_efi_data *efi_data;
393395
struct cirrus_amp_cal_data *cal = NULL;
394-
int i;
396+
int i, ret;
395397

396398
efi_data = cs_amp_get_cal_efi_buffer(dev, NULL, NULL, NULL);
397399
if (IS_ERR(efi_data))
@@ -432,14 +434,17 @@ static int _cs_amp_get_efi_calibration_data(struct device *dev, u64 target_uid,
432434
dev_warn(dev, "Calibration entry %d does not match silicon ID", amp_index);
433435
}
434436

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

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

442-
return 0;
447+
return ret;
443448
}
444449

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

0 commit comments

Comments
 (0)