ASoC: cs-amp-lib: Revert use of __free(kfree) back to normal C cleanup
Revert commitpull/1354/merge6797540c8b("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:6797540c8b("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>
parent
c5fae31f60
commit
2b69bee5a2
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
#include <asm/byteorder.h>
|
||||
#include <kunit/static_stub.h>
|
||||
#include <linux/cleanup.h>
|
||||
#include <linux/debugfs.h>
|
||||
#include <linux/dev_printk.h>
|
||||
#include <linux/efi.h>
|
||||
|
|
@ -310,8 +309,9 @@ static struct cirrus_amp_efi_data *cs_amp_get_cal_efi_buffer(struct device *dev,
|
|||
efi_guid_t **guid,
|
||||
u32 *attr)
|
||||
{
|
||||
struct cirrus_amp_efi_data *efi_data __free(kfree) = NULL;
|
||||
struct cirrus_amp_efi_data *efi_data;
|
||||
unsigned long data_size = 0;
|
||||
u8 *data;
|
||||
efi_status_t status;
|
||||
int i, ret;
|
||||
|
||||
|
|
@ -339,18 +339,19 @@ static struct cirrus_amp_efi_data *cs_amp_get_cal_efi_buffer(struct device *dev,
|
|||
}
|
||||
|
||||
/* Get variable contents into buffer */
|
||||
efi_data = kmalloc(data_size, GFP_KERNEL);
|
||||
if (!efi_data)
|
||||
data = kmalloc(data_size, GFP_KERNEL);
|
||||
if (!data)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
status = cs_amp_get_efi_variable(cs_amp_lib_cal_efivars[i].name,
|
||||
cs_amp_lib_cal_efivars[i].guid,
|
||||
attr, &data_size, efi_data);
|
||||
attr, &data_size, data);
|
||||
if (status != EFI_SUCCESS) {
|
||||
ret = -EINVAL;
|
||||
goto err;
|
||||
}
|
||||
|
||||
efi_data = (struct cirrus_amp_efi_data *)data;
|
||||
dev_dbg(dev, "Calibration: Size=%d, Amp Count=%d\n", efi_data->size, efi_data->count);
|
||||
|
||||
if ((efi_data->count > 128) ||
|
||||
|
|
@ -364,9 +365,10 @@ static struct cirrus_amp_efi_data *cs_amp_get_cal_efi_buffer(struct device *dev,
|
|||
if (efi_data->size == 0)
|
||||
efi_data->size = data_size;
|
||||
|
||||
return_ptr(efi_data);
|
||||
return efi_data;
|
||||
|
||||
err:
|
||||
kfree(data);
|
||||
dev_err(dev, "Failed to read calibration data from EFI: %d\n", ret);
|
||||
|
||||
return ERR_PTR(ret);
|
||||
|
|
@ -389,9 +391,9 @@ static int cs_amp_set_cal_efi_buffer(struct device *dev,
|
|||
static int _cs_amp_get_efi_calibration_data(struct device *dev, u64 target_uid, int amp_index,
|
||||
struct cirrus_amp_cal_data *out_data)
|
||||
{
|
||||
struct cirrus_amp_efi_data *efi_data __free(kfree) = NULL;
|
||||
struct cirrus_amp_efi_data *efi_data;
|
||||
struct cirrus_amp_cal_data *cal = NULL;
|
||||
int i;
|
||||
int i, ret;
|
||||
|
||||
efi_data = cs_amp_get_cal_efi_buffer(dev, NULL, NULL, NULL);
|
||||
if (IS_ERR(efi_data))
|
||||
|
|
@ -432,14 +434,17 @@ static int _cs_amp_get_efi_calibration_data(struct device *dev, u64 target_uid,
|
|||
dev_warn(dev, "Calibration entry %d does not match silicon ID", amp_index);
|
||||
}
|
||||
|
||||
if (!cal) {
|
||||
if (cal) {
|
||||
memcpy(out_data, cal, sizeof(*out_data));
|
||||
ret = 0;
|
||||
} else {
|
||||
dev_warn(dev, "No calibration for silicon ID %#llx\n", target_uid);
|
||||
return -ENOENT;
|
||||
ret = -ENOENT;
|
||||
}
|
||||
|
||||
memcpy(out_data, cal, sizeof(*out_data));
|
||||
kfree(efi_data);
|
||||
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int _cs_amp_set_efi_calibration_data(struct device *dev, int amp_index, int num_amps,
|
||||
|
|
|
|||
Loading…
Reference in New Issue