c06c76602e
clang static analysis flags this error
qat_uclo.c:297:3: warning: Attempt to free released memory
[unix.Malloc]
kfree(*init_tab_base);
^~~~~~~~~~~~~~~~~~~~~
When input *init_tab_base is null, the function allocates memory for
the head of the list. When there is problem allocating other list
elements the list is unwound and freed. Then a check is made if the
list head was allocated and is also freed.
Keeping track of the what may need to be freed is the variable 'tail_old'.
The unwinding/freeing block is
while (tail_old) {
mem_init = tail_old->next;
kfree(tail_old);
tail_old = mem_init;
}
The problem is that the first element of tail_old is also what was
allocated for the list head
init_header = kzalloc(sizeof(*init_header), GFP_KERNEL);
...
*init_tab_base = init_header;
flag = 1;
}
tail_old = init_header;
So *init_tab_base/init_header are freed twice.
There is another problem.
When the input *init_tab_base is non null the tail_old is calculated by
traveling down the list to first non null entry.
tail_old = init_header;
while (tail_old->next)
tail_old = tail_old->next;
When the unwinding free happens, the last entry of the input list will
be freed.
So the freeing needs a general changed.
If locally allocated the first element of tail_old is freed, else it
is skipped. As a bit of cleanup, reset *init_tab_base if it came in
as null.
Fixes:
|
||
---|---|---|
.. | ||
adf_accel_devices.h | ||
adf_accel_engine.c | ||
adf_admin.c | ||
adf_aer.c | ||
adf_cfg_common.h | ||
adf_cfg_strings.h | ||
adf_cfg_user.h | ||
adf_cfg.c | ||
adf_cfg.h | ||
adf_common_drv.h | ||
adf_ctl_drv.c | ||
adf_dev_mgr.c | ||
adf_hw_arbiter.c | ||
adf_init.c | ||
adf_isr.c | ||
adf_pf2vf_msg.c | ||
adf_pf2vf_msg.h | ||
adf_sriov.c | ||
adf_transport_access_macros.h | ||
adf_transport_debug.c | ||
adf_transport_internal.h | ||
adf_transport.c | ||
adf_transport.h | ||
adf_vf2pf_msg.c | ||
adf_vf_isr.c | ||
icp_qat_fw_init_admin.h | ||
icp_qat_fw_la.h | ||
icp_qat_fw_loader_handle.h | ||
icp_qat_fw_pke.h | ||
icp_qat_fw.h | ||
icp_qat_hal.h | ||
icp_qat_hw.h | ||
icp_qat_uclo.h | ||
Makefile | ||
qat_algs.c | ||
qat_asym_algs.c | ||
qat_crypto.c | ||
qat_crypto.h | ||
qat_hal.c | ||
qat_uclo.c |