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