Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

tpm: Fix a possible dereference of ERR_PTR in tpm_init()

Smatch reports:
drivers/char/tpm/tpm-interface.c:470 tpm_init() error:
'tpm_class' dereferencing possible ERR_PTR()

If class_create() returns error pointer, we are dereferencing a possible
error pointer. Fix this by moving the dereference post error handling.

Fixes: a010eb881243 ("tpm: fix up the tpm_class shutdown_pre pointer when created")
Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
Link: https://lore.kernel.org/r/20230321061416.626561-1-harshit.m.mogalapalli@oracle.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Harshit Mogalapalli and committed by
Greg Kroah-Hartman
6b301ded fea087fc

+2 -1
+2 -1
drivers/char/tpm/tpm-interface.c
··· 467 467 int rc; 468 468 469 469 tpm_class = class_create("tpm"); 470 - tpm_class->shutdown_pre = tpm_class_shutdown; 471 470 if (IS_ERR(tpm_class)) { 472 471 pr_err("couldn't create tpm class\n"); 473 472 return PTR_ERR(tpm_class); 474 473 } 474 + 475 + tpm_class->shutdown_pre = tpm_class_shutdown; 475 476 476 477 tpmrm_class = class_create("tpmrm"); 477 478 if (IS_ERR(tpmrm_class)) {