Skip to content

Commit 73da074

Browse files
KiranPadwalgregkh
authored andcommitted
char: tpm: Add missing error check for devm_kzalloc
commit bb95cd3 upstream. Currently these driver are missing a check on the return value of devm_kzalloc, which would cause a NULL pointer dereference in a OOM situation. This patch adds a missing check for tpm_i2c_atmel.c and tpm_i2c_nuvoton.c Signed-off-by: Kiran Padwal <kiran.padwal@smartplayin.com> Reviewed-By: Jason Gunthorpe <jgunthorpe@obsidianresearch.com> Signed-off-by: Peter Huewe <peterhuewe@gmx.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 2bce1b5 commit 73da074

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

‎drivers/char/tpm/tpm_i2c_atmel.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ static int i2c_atmel_probe(struct i2c_client *client,
168168

169169
chip->vendor.priv = devm_kzalloc(dev, sizeof(struct priv_data),
170170
GFP_KERNEL);
171+
if (!chip->vendor.priv) {
172+
rc = -ENOMEM;
173+
goto out_err;
174+
}
171175

172176
/* Default timeouts */
173177
chip->vendor.timeout_a = msecs_to_jiffies(TPM_I2C_SHORT_TIMEOUT);

‎drivers/char/tpm/tpm_i2c_nuvoton.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,11 @@ static int i2c_nuvoton_probe(struct i2c_client *client,
538538

539539
chip->vendor.priv = devm_kzalloc(dev, sizeof(struct priv_data),
540540
GFP_KERNEL);
541+
if (!chip->vendor.priv) {
542+
rc = -ENOMEM;
543+
goto out_err;
544+
}
545+
541546
init_waitqueue_head(&chip->vendor.read_queue);
542547
init_waitqueue_head(&chip->vendor.int_queue);
543548

0 commit comments

Comments
 (0)