mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-12-04 21:00:56 -06:00
ASoC: ntpfw: Use auto-cleanup for firmware loading
Simplify the code to manage the firmware loading with __free(firmware) auto-cleanup. Only the code refactoring, no functional changes. Signed-off-by: Takashi Iwai <tiwai@suse.de> Link: https://patch.msgid.link/20260806140006.1412298-11-tiwai@suse.de Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
@@ -89,7 +89,7 @@ int ntpfw_load(struct i2c_client *i2c, const char *name, u32 magic)
|
||||
{
|
||||
struct device *dev = &i2c->dev;
|
||||
const struct ntpfw_chunk *chunk;
|
||||
const struct firmware *fw;
|
||||
const struct firmware *fw __free(firmware) = NULL;
|
||||
const u8 *data;
|
||||
size_t leftover;
|
||||
int ret;
|
||||
@@ -101,10 +101,8 @@ int ntpfw_load(struct i2c_client *i2c, const char *name, u32 magic)
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (!ntpfw_verify(dev, fw->data, fw->size, magic)) {
|
||||
ret = -EINVAL;
|
||||
goto done;
|
||||
}
|
||||
if (!ntpfw_verify(dev, fw->data, fw->size, magic))
|
||||
return -EINVAL;
|
||||
|
||||
data = fw->data + sizeof(struct ntpfw_header);
|
||||
leftover = fw->size - sizeof(struct ntpfw_header);
|
||||
@@ -112,23 +110,18 @@ int ntpfw_load(struct i2c_client *i2c, const char *name, u32 magic)
|
||||
while (leftover) {
|
||||
chunk = (struct ntpfw_chunk *)data;
|
||||
|
||||
if (!ntpfw_verify_chunk(dev, chunk, leftover)) {
|
||||
ret = -EINVAL;
|
||||
goto done;
|
||||
}
|
||||
if (!ntpfw_verify_chunk(dev, chunk, leftover))
|
||||
return -EINVAL;
|
||||
|
||||
ret = ntpfw_send_chunk(i2c, chunk);
|
||||
if (ret)
|
||||
goto done;
|
||||
return ret;
|
||||
|
||||
data += be16_to_cpu(chunk->length) + sizeof(*chunk);
|
||||
leftover -= be16_to_cpu(chunk->length) + sizeof(*chunk);
|
||||
}
|
||||
|
||||
done:
|
||||
release_firmware(fw);
|
||||
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(ntpfw_load);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user