Message ID | 1459862140-10160-1-git-send-email-mario.six@gdsys.cc |
---|---|
State | Accepted |
Delegated to: | Simon Glass |
Headers | show |
On 5 April 2016 at 07:15, Mario Six <mario.six@gdsys.cc> wrote: > > uclass_first_device might return NULL for the device despite a zero > return code. Currently, this might lead to null pointer dereferencing, > since the returned device is not properly checked. > > We switch to uclass_first_device_err to make sure that the returned device is > valid. > > Signed-off-by: Mario Six <mario.six@gdsys.cc> > Cc: Simon Glass <sjg@chromium.org> > --- > > v2: > - Use uclass_first_device_err instead of explicit null checking > > > lib/tpm.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) Thanks! Acked-by: Simon Glass <sjg@chromium.org>
diff --git a/lib/tpm.c b/lib/tpm.c index f428d45..88f2406 100644 --- a/lib/tpm.c +++ b/lib/tpm.c @@ -242,7 +242,7 @@ static uint32_t tpm_sendrecv_command(const void *command, response_length = sizeof(response_buffer); } - ret = uclass_first_device(UCLASS_TPM, &dev); + ret = uclass_first_device_err(UCLASS_TPM, &dev); if (ret) return ret; err = tpm_xfer(dev, command, tpm_command_size(command), @@ -261,8 +261,8 @@ int tpm_init(void) int err; struct udevice *dev; - err = uclass_first_device(UCLASS_TPM, &dev); - if (err || !dev) + err = uclass_first_device_err(UCLASS_TPM, &dev); + if (err) return err; return tpm_open(dev); }
uclass_first_device might return NULL for the device despite a zero return code. Currently, this might lead to null pointer dereferencing, since the returned device is not properly checked. We switch to uclass_first_device_err to make sure that the returned device is valid. Signed-off-by: Mario Six <mario.six@gdsys.cc> Cc: Simon Glass <sjg@chromium.org> --- v2: - Use uclass_first_device_err instead of explicit null checking lib/tpm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) -- 2.7.0.GIT