public inbox for linux-integrity@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH next] tpm: Fix a possible dereference of ERR_PTR in tpm_init()
@ 2023-03-21  6:14 Harshit Mogalapalli
  2023-03-21  8:01 ` Greg Kroah-Hartman
  2023-03-29 21:59 ` Jarkko Sakkinen
  0 siblings, 2 replies; 4+ messages in thread
From: Harshit Mogalapalli @ 2023-03-21  6:14 UTC (permalink / raw)
  Cc: error27, Harshit Mogalapalli, Peter Huewe, Jarkko Sakkinen,
	Jason Gunthorpe, Greg Kroah-Hartman, linux-integrity,
	linux-kernel

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>
---
This is based on static analysis, only compile tested.
---
 drivers/char/tpm/tpm-interface.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index 43e23a04433a..4463d0018290 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -467,12 +467,13 @@ static int __init tpm_init(void)
 	int rc;
 
 	tpm_class = class_create("tpm");
-	tpm_class->shutdown_pre = tpm_class_shutdown;
 	if (IS_ERR(tpm_class)) {
 		pr_err("couldn't create tpm class\n");
 		return PTR_ERR(tpm_class);
 	}
 
+	tpm_class->shutdown_pre = tpm_class_shutdown;
+
 	tpmrm_class = class_create("tpmrm");
 	if (IS_ERR(tpmrm_class)) {
 		pr_err("couldn't create tpmrm class\n");
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-03-29 21:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-21  6:14 [PATCH next] tpm: Fix a possible dereference of ERR_PTR in tpm_init() Harshit Mogalapalli
2023-03-21  8:01 ` Greg Kroah-Hartman
2023-03-29 21:59   ` Jarkko Sakkinen
2023-03-29 21:59 ` Jarkko Sakkinen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox