misc: fix the secure coding style violations of tpm

There is an secure coding style violations of tmp, this patch add some
NULL check to fix these violations.

Tracked-On: #6690
Signed-off-by: Chenli Wei <chenli.wei@linux.intel.com>
This commit is contained in:
Chenli Wei 2022-06-14 15:18:52 +08:00 committed by acrnsi-robot
parent 31b9312f2f
commit 6a3807748c
3 changed files with 7 additions and 6 deletions

View File

@ -115,11 +115,11 @@ int create_pt_acpidev(char *opt)
* *
* @pre (name != NULL) && (strlen(name) > 0) * @pre (name != NULL) && (strlen(name) > 0)
*/ */
int get_mmio_hpa_resource(char *name, uint64_t *res_start, uint64_t *res_size) bool get_mmio_hpa_resource(char *name, uint64_t *res_start, uint64_t *res_size)
{ {
FILE *fp; FILE *fp;
uint64_t start, end; uint64_t start, end;
int found = false; bool found = false;
char line[128]; char line[128];
char *cp; char *cp;

View File

@ -119,9 +119,10 @@ static int init_tpm2_pt(char *opts, struct mmio_dev *tpm2dev)
} }
devopts = strdup(opts); devopts = strdup(opts);
if (devopts != NULL) { if (devopts == NULL) {
vtopts = strstr(devopts,","); return -ENODEV;
} }
vtopts = strstr(devopts,",");
/* Check whether user set the uid to identify same hid devices for /* Check whether user set the uid to identify same hid devices for
* several instances. * several instances.
@ -131,7 +132,7 @@ static int init_tpm2_pt(char *opts, struct mmio_dev *tpm2dev)
} }
/* parse /proc/iomem to find the address and size of tpm buffer */ /* parse /proc/iomem to find the address and size of tpm buffer */
if ((devopts != NULL) && (!get_mmio_hpa_resource(devopts, &tpm2_buffer_hpa, &tpm2_buffer_size))) { if (!get_mmio_hpa_resource(devopts, &tpm2_buffer_hpa, &tpm2_buffer_size)) {
free(devopts); free(devopts);
return -ENODEV; return -ENODEV;
} }

View File

@ -27,7 +27,7 @@ struct acpi_dev_pt_ops {
#define DEFINE_ACPI_PT_DEV(x) DATA_SET(acpi_dev_pt_ops_set, x); #define DEFINE_ACPI_PT_DEV(x) DATA_SET(acpi_dev_pt_ops_set, x);
struct mmio_dev *get_mmiodev(char *name); struct mmio_dev *get_mmiodev(char *name);
int get_mmio_hpa_resource(char *name, uint64_t *res_start, uint64_t *res_size); bool get_mmio_hpa_resource(char *name, uint64_t *res_start, uint64_t *res_size);
int get_more_acpi_dev_info(char *hid, uint32_t instance, struct acpi_dev_pt_ops *ops); int get_more_acpi_dev_info(char *hid, uint32_t instance, struct acpi_dev_pt_ops *ops);
void acpi_dev_write_dsdt(struct vmctx *ctx); void acpi_dev_write_dsdt(struct vmctx *ctx);