diff mbox

[2/4] lib: fwts_ipmi: remove redundant for loop

Message ID 1464691358-18134-3-git-send-email-colin.king@canonical.com
State Accepted
Headers show

Commit Message

Colin Ian King May 31, 2016, 10:42 a.m. UTC
From: Colin Ian King <colin.king@canonical.com>

The for loop is redundant; it never gets to the end to do more than
1 loop; so remove the loop.  Instead, return if the poll failed or
timed out. This simplifies the code and keeps the same functionality.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/lib/src/fwts_ipmi.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

Comments

Alex Hung June 1, 2016, 12:35 a.m. UTC | #1
On 2016-05-31 06:42 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> The for loop is redundant; it never gets to the end to do more than
> 1 loop; so remove the loop.  Instead, return if the poll failed or
> timed out. This simplifies the code and keeps the same functionality.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/lib/src/fwts_ipmi.c | 16 ++++++----------
>   1 file changed, 6 insertions(+), 10 deletions(-)
>
> diff --git a/src/lib/src/fwts_ipmi.c b/src/lib/src/fwts_ipmi.c
> index f5f5a56..d4492cc 100644
> --- a/src/lib/src/fwts_ipmi.c
> +++ b/src/lib/src/fwts_ipmi.c
> @@ -55,16 +55,12 @@ int fwts_ipmi_exec_query(
>   		return FWTS_ERROR;
>   	}
>
> -	for (;;) {
> -		fwts_pfd.events = POLLIN | POLLPRI;
> -		fwts_pfd.fd = fd;
> -		fwts_pollfd_rc = poll(&fwts_pfd,1,5000);
> -		if (fwts_pollfd_rc > 0) {
> -			break;
> -		} else {
> -			close(fd);
> -			return FWTS_ERROR;
> -		}
> +	fwts_pfd.events = POLLIN | POLLPRI;
> +	fwts_pfd.fd = fd;
> +	fwts_pollfd_rc = poll(&fwts_pfd, 1, 5000);
> +	if (fwts_pollfd_rc <= 0) {
> +		close(fd);
> +		return FWTS_ERROR;
>   	}
>
>   	memset(&recv_data, 0, sizeof(IPMI_MAX_MSG_LENGTH));
>

Acked-by: Alex Hung <alex.hung@canonical.com>
Ivan Hu June 3, 2016, 2:32 a.m. UTC | #2
On 05/31/2016 06:42 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> The for loop is redundant; it never gets to the end to do more than
> 1 loop; so remove the loop.  Instead, return if the poll failed or
> timed out. This simplifies the code and keeps the same functionality.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/lib/src/fwts_ipmi.c | 16 ++++++----------
>   1 file changed, 6 insertions(+), 10 deletions(-)
>
> diff --git a/src/lib/src/fwts_ipmi.c b/src/lib/src/fwts_ipmi.c
> index f5f5a56..d4492cc 100644
> --- a/src/lib/src/fwts_ipmi.c
> +++ b/src/lib/src/fwts_ipmi.c
> @@ -55,16 +55,12 @@ int fwts_ipmi_exec_query(
>   		return FWTS_ERROR;
>   	}
>   
> -	for (;;) {
> -		fwts_pfd.events = POLLIN | POLLPRI;
> -		fwts_pfd.fd = fd;
> -		fwts_pollfd_rc = poll(&fwts_pfd,1,5000);
> -		if (fwts_pollfd_rc > 0) {
> -			break;
> -		} else {
> -			close(fd);
> -			return FWTS_ERROR;
> -		}
> +	fwts_pfd.events = POLLIN | POLLPRI;
> +	fwts_pfd.fd = fd;
> +	fwts_pollfd_rc = poll(&fwts_pfd, 1, 5000);
> +	if (fwts_pollfd_rc <= 0) {
> +		close(fd);
> +		return FWTS_ERROR;
>   	}
>   
>   	memset(&recv_data, 0, sizeof(IPMI_MAX_MSG_LENGTH));
Acked-by: Ivan Hu <ivan.hu@canonical.com>
diff mbox

Patch

diff --git a/src/lib/src/fwts_ipmi.c b/src/lib/src/fwts_ipmi.c
index f5f5a56..d4492cc 100644
--- a/src/lib/src/fwts_ipmi.c
+++ b/src/lib/src/fwts_ipmi.c
@@ -55,16 +55,12 @@  int fwts_ipmi_exec_query(
 		return FWTS_ERROR;
 	}
 
-	for (;;) {
-		fwts_pfd.events = POLLIN | POLLPRI;
-		fwts_pfd.fd = fd;
-		fwts_pollfd_rc = poll(&fwts_pfd,1,5000);
-		if (fwts_pollfd_rc > 0) {
-			break;
-		} else {
-			close(fd);
-			return FWTS_ERROR;
-		}
+	fwts_pfd.events = POLLIN | POLLPRI;
+	fwts_pfd.fd = fd;
+	fwts_pollfd_rc = poll(&fwts_pfd, 1, 5000);
+	if (fwts_pollfd_rc <= 0) {
+		close(fd);
+		return FWTS_ERROR;
 	}
 
 	memset(&recv_data, 0, sizeof(IPMI_MAX_MSG_LENGTH));