mirror of
https://github.com/torvalds/linux.git
synced 2024-12-14 15:13:52 +00:00
media: dvb-frontends: drx39xyj: Refactor firmware upload
Do not cache the file, instead load it on demand. This makes smatch a happy parser: drivers/media/dvb-frontends/drx39xyj/drxj.c:11908 drx_ctrl_u_code() warn: 'fw' from request_firmware() not released on lines: 11877,11886,11896. Signed-off-by: Ricardo Ribalda <ribalda@chromium.org> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
This commit is contained in:
parent
8e1f5da59d
commit
7bc6966115
@ -33,7 +33,6 @@
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/firmware.h>
|
||||
#include <linux/i2c.h>
|
||||
|
||||
/*
|
||||
@ -1910,7 +1909,6 @@ struct drx_demod_instance {
|
||||
/* generic demodulator data */
|
||||
|
||||
struct i2c_adapter *i2c;
|
||||
const struct firmware *firmware;
|
||||
};
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
|
@ -56,6 +56,7 @@ INCLUDE FILES
|
||||
#define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/firmware.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/string.h>
|
||||
#include <linux/slab.h>
|
||||
@ -11750,6 +11751,7 @@ static int drx_ctrl_u_code(struct drx_demod_instance *demod,
|
||||
u8 *mc_data = NULL;
|
||||
unsigned size;
|
||||
char *mc_file;
|
||||
const struct firmware *fw;
|
||||
|
||||
/* Check arguments */
|
||||
if (!mc_info || !mc_info->mc_file)
|
||||
@ -11757,28 +11759,22 @@ static int drx_ctrl_u_code(struct drx_demod_instance *demod,
|
||||
|
||||
mc_file = mc_info->mc_file;
|
||||
|
||||
if (!demod->firmware) {
|
||||
const struct firmware *fw = NULL;
|
||||
|
||||
rc = request_firmware(&fw, mc_file, demod->i2c->dev.parent);
|
||||
if (rc < 0) {
|
||||
pr_err("Couldn't read firmware %s\n", mc_file);
|
||||
return rc;
|
||||
}
|
||||
demod->firmware = fw;
|
||||
|
||||
if (demod->firmware->size < 2 * sizeof(u16)) {
|
||||
rc = -EINVAL;
|
||||
pr_err("Firmware is too short!\n");
|
||||
goto release;
|
||||
}
|
||||
|
||||
pr_info("Firmware %s, size %zu\n",
|
||||
mc_file, demod->firmware->size);
|
||||
rc = request_firmware(&fw, mc_file, demod->i2c->dev.parent);
|
||||
if (rc < 0) {
|
||||
pr_err("Couldn't read firmware %s\n", mc_file);
|
||||
return rc;
|
||||
}
|
||||
|
||||
mc_data_init = demod->firmware->data;
|
||||
size = demod->firmware->size;
|
||||
if (fw->size < 2 * sizeof(u16)) {
|
||||
rc = -EINVAL;
|
||||
pr_err("Firmware is too short!\n");
|
||||
goto release;
|
||||
}
|
||||
|
||||
pr_info("Firmware %s, size %zu\n", mc_file, fw->size);
|
||||
|
||||
mc_data_init = fw->data;
|
||||
size = fw->size;
|
||||
|
||||
mc_data = (void *)mc_data_init;
|
||||
/* Check data */
|
||||
@ -11874,7 +11870,8 @@ static int drx_ctrl_u_code(struct drx_demod_instance *demod,
|
||||
0x0000)) {
|
||||
pr_err("error reading firmware at pos %zd\n",
|
||||
mc_data - mc_data_init);
|
||||
return -EIO;
|
||||
rc = -EIO;
|
||||
goto release;
|
||||
}
|
||||
|
||||
result = memcmp(curr_ptr, mc_data_buffer,
|
||||
@ -11883,7 +11880,8 @@ static int drx_ctrl_u_code(struct drx_demod_instance *demod,
|
||||
if (result) {
|
||||
pr_err("error verifying firmware at pos %zd\n",
|
||||
mc_data - mc_data_init);
|
||||
return -EIO;
|
||||
rc = -EIO;
|
||||
goto release;
|
||||
}
|
||||
|
||||
curr_addr += ((dr_xaddr_t)(bytes_to_comp / 2));
|
||||
@ -11893,17 +11891,17 @@ static int drx_ctrl_u_code(struct drx_demod_instance *demod,
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return -EINVAL;
|
||||
rc = -EINVAL;
|
||||
goto release;
|
||||
|
||||
}
|
||||
mc_data += mc_block_nr_bytes;
|
||||
}
|
||||
|
||||
return 0;
|
||||
rc = 0;
|
||||
|
||||
release:
|
||||
release_firmware(demod->firmware);
|
||||
demod->firmware = NULL;
|
||||
release_firmware(fw);
|
||||
|
||||
return rc;
|
||||
}
|
||||
@ -12271,7 +12269,6 @@ static void drx39xxj_release(struct dvb_frontend *fe)
|
||||
kfree(demod->my_ext_attr);
|
||||
kfree(demod->my_common_attr);
|
||||
kfree(demod->my_i2c_dev_addr);
|
||||
release_firmware(demod->firmware);
|
||||
kfree(demod);
|
||||
kfree(state);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user