Skip to content

Commit

Permalink
staging: gpib: Move free after the variable use has been completed
Browse files Browse the repository at this point in the history
The variable `in_data` is freed, but used later in the code.
Fix it by moving the freeing the memory after it use has been
completed.

This issue was reported by Coverity Scan.
Report:
CID 1600783: (#1 of 1): Use after free (USE_AFTER_FREE)
19. pass_freed_arg: Passing freed pointer in_data as an argument to
ni_usb_dump_raw_block.

Fixes: 4e127de ("staging: gpib: Add National Instruments USB GPIB driver")
Signed-off-by: Everest K.C. <[email protected]>
Reviewed-by: Shuah Khan <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
everestkc authored and gregkh committed Oct 16, 2024
1 parent afa0ab0 commit b0a7dfe
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/staging/gpib/ni_usb/ni_usb_gpib.c
Original file line number Diff line number Diff line change
Expand Up @@ -690,12 +690,12 @@ static int ni_usb_read(gpib_board_t *board, uint8_t *buffer, size_t length,
kfree(in_data);
return parse_retval;
}
kfree(in_data);
if (actual_length != length - status.count) {
pr_err("%s: actual_length=%i expected=%li\n",
__func__, actual_length, (long)(length - status.count));
ni_usb_dump_raw_block(in_data, usb_bytes_read);
}
kfree(in_data);
switch (status.error_code) {
case NIUSB_NO_ERROR:
retval = 0;
Expand Down

0 comments on commit b0a7dfe

Please sign in to comment.