diff options
author | Hans Verkuil <hverkuil-cisco@xs4all.nl> | 2023-05-24 15:11:50 +0300 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@kernel.org> | 2023-06-09 17:12:08 +0300 |
commit | 5e131b80605a391bb61c23e1f5950a343b4d8a58 (patch) | |
tree | 5a34b1d767d67bdb2d9109614ef1e8e3f35f1e76 /drivers/staging/media/atomisp/pci | |
parent | 66c1dfad00120d15abb1bca4e97b1dcf82002019 (diff) | |
download | linux-5e131b80605a391bb61c23e1f5950a343b4d8a58.tar.xz |
media: atomisp: move up sanity checks
The sanity checks were done too late, so move them up.
This fixes this smatch warning:
drivers/staging/media/atomisp/pci/sh_css_firmware.c:247 sh_css_load_firmware() warn: variable dereferenced before check 'fw_data' (see line 237)
Link: https://lore.kernel.org/r/20230524121150.435736-9-hverkuil-cisco@xs4all.nl
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
Diffstat (limited to 'drivers/staging/media/atomisp/pci')
-rw-r--r-- | drivers/staging/media/atomisp/pci/sh_css_firmware.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/drivers/staging/media/atomisp/pci/sh_css_firmware.c b/drivers/staging/media/atomisp/pci/sh_css_firmware.c index 49ee88fe151d..197ab2085e8d 100644 --- a/drivers/staging/media/atomisp/pci/sh_css_firmware.c +++ b/drivers/staging/media/atomisp/pci/sh_css_firmware.c @@ -233,8 +233,16 @@ sh_css_load_firmware(struct device *dev, const char *fw_data, struct sh_css_fw_bi_file_h *file_header; int ret; + /* some sanity checks */ + if (!fw_data || fw_size < sizeof(struct sh_css_fw_bi_file_h)) + return -EINVAL; + firmware_header = (struct firmware_header *)fw_data; file_header = &firmware_header->file_header; + + if (file_header->h_size != sizeof(struct sh_css_fw_bi_file_h)) + return -EINVAL; + binaries = &firmware_header->binary_header; strscpy(FW_rel_ver_name, file_header->version, min(sizeof(FW_rel_ver_name), sizeof(file_header->version))); @@ -251,13 +259,6 @@ sh_css_load_firmware(struct device *dev, const char *fw_data, IA_CSS_LOG("successfully load firmware version %s", release_version); } - /* some sanity checks */ - if (!fw_data || fw_size < sizeof(struct sh_css_fw_bi_file_h)) - return -EINVAL; - - if (file_header->h_size != sizeof(struct sh_css_fw_bi_file_h)) - return -EINVAL; - sh_css_num_binaries = file_header->binary_nr; /* Only allocate memory for ISP blob info */ if (sh_css_num_binaries > NUM_OF_SPS) { |