From 196f0bb081db462bc0f9a9462f47c9639101204b Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Sun, 18 Mar 2012 16:45:04 +0000 Subject: [PATCH] [rng] Allow entropy_enable() to return an error Signed-off-by: Michael Brown --- src/arch/i386/interface/pcbios/rtc_entropy.c | 5 ++++- src/crypto/entropy.c | 3 ++- src/include/ipxe/entropy.h | 3 ++- src/include/ipxe/null_entropy.h | 3 ++- src/tests/entropy_sample.c | 3 ++- 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/arch/i386/interface/pcbios/rtc_entropy.c b/src/arch/i386/interface/pcbios/rtc_entropy.c index 03189659e..257cf08a0 100644 --- a/src/arch/i386/interface/pcbios/rtc_entropy.c +++ b/src/arch/i386/interface/pcbios/rtc_entropy.c @@ -165,12 +165,15 @@ static void rtc_disable_int ( void ) { /** * Enable entropy gathering * + * @ret rc Return status code */ -static void rtc_entropy_enable ( void ) { +static int rtc_entropy_enable ( void ) { rtc_hook_isr(); enable_irq ( RTC_IRQ ); rtc_enable_int(); + + return 0; } /** diff --git a/src/crypto/entropy.c b/src/crypto/entropy.c index cb3d54d8f..03e7290a3 100644 --- a/src/crypto/entropy.c +++ b/src/crypto/entropy.c @@ -422,7 +422,8 @@ int get_entropy_input_tmp ( unsigned int num_samples, uint8_t *tmp, int rc; /* Enable entropy gathering */ - entropy_enable(); + if ( ( rc = entropy_enable() ) != 0 ) + return rc; /* Perform mandatory startup tests, if not yet performed */ for ( ; startup_tested < startup_test_count() ; startup_tested++ ) { diff --git a/src/include/ipxe/entropy.h b/src/include/ipxe/entropy.h index 02dde2f1d..50ba4fc63 100644 --- a/src/include/ipxe/entropy.h +++ b/src/include/ipxe/entropy.h @@ -61,8 +61,9 @@ typedef uint8_t entropy_sample_t; /** * Enable entropy gathering * + * @ret rc Return status code */ -void entropy_enable ( void ); +int entropy_enable ( void ); /** * Disable entropy gathering diff --git a/src/include/ipxe/null_entropy.h b/src/include/ipxe/null_entropy.h index 0bfec802d..646d1a17e 100644 --- a/src/include/ipxe/null_entropy.h +++ b/src/include/ipxe/null_entropy.h @@ -19,9 +19,10 @@ FILE_LICENCE ( GPL2_OR_LATER ); #define ENTROPY_PREFIX_null __null_ #endif -static inline __always_inline void +static inline __always_inline int ENTROPY_INLINE ( null, entropy_enable ) ( void ) { /* Do nothing */ + return 0; } static inline __always_inline void diff --git a/src/tests/entropy_sample.c b/src/tests/entropy_sample.c index e00bb484e..9e75b4e9b 100644 --- a/src/tests/entropy_sample.c +++ b/src/tests/entropy_sample.c @@ -48,7 +48,8 @@ static void entropy_sample_test_exec ( void ) { for ( i = 0 ; i < ( SAMPLE_COUNT / SAMPLE_BLOCKSIZE ) ; i++ ) { /* Collect one block of samples */ - entropy_enable(); + rc = entropy_enable(); + ok ( rc == 0 ); for ( j = 0 ; j < SAMPLE_BLOCKSIZE ; j++ ) { rc = get_noise ( &samples[j] ); ok ( rc == 0 );