Patchwork dmi: dmi_decode: remove redundant snprintf

login
register
mail settings
Submitter Colin King
Date May 7, 2013, 12:03 a.m.
Message ID <1367885035-23221-1-git-send-email-colin.king@canonical.com>
Download mbox | patch
Permalink /patch/241855/
State Accepted
Headers show

Comments

Colin King - May 7, 2013, 12:03 a.m.
From: Colin Ian King <colin.king@canonical.com>

Coverity CID #997280, Nesting level does not match indentation

Fix two bugs; the first is that the snprintf is redundant, the
second is that the following fwts_failed was should only be
printed on the if ((val < 0x1) || (val > 0xd)).  Add explicit
{ } brackets just to clarify the intent.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/dmi/dmi_decode/dmi_decode.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Alex Hung - May 9, 2013, 6:23 a.m.
On 05/07/2013 08:03 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Coverity CID #997280, Nesting level does not match indentation
>
> Fix two bugs; the first is that the snprintf is redundant, the
> second is that the following fwts_failed was should only be
> printed on the if ((val < 0x1) || (val > 0xd)).  Add explicit
> { } brackets just to clarify the intent.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/dmi/dmi_decode/dmi_decode.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/src/dmi/dmi_decode/dmi_decode.c b/src/dmi/dmi_decode/dmi_decode.c
> index 0e775db..d89ab28 100644
> --- a/src/dmi/dmi_decode/dmi_decode.c
> +++ b/src/dmi/dmi_decode/dmi_decode.c
> @@ -597,8 +597,7 @@ static void dmi_decode_entry(fwts_framework *fw,
>   								"offset 0x%2.2x",
>   								val, table, addr, i, 0x15 + (i*len));
>   					} else {
> -						if ((val < 0x1) || (val > 0xd))
> -							snprintf(tmp, sizeof(tmp), "Base Board Type %d", i);
> +						if ((val < 0x1) || (val > 0xd)) {
>   							fwts_failed(fw, LOG_LEVEL_HIGH, DMI_VALUE_OUT_OF_RANGE,
>   								"Out of range value 0x%2.2" PRIx8
>   								" (range allowed 0x00..0x42) "
> @@ -606,6 +605,7 @@ static void dmi_decode_entry(fwts_framework *fw,
>   								"0x%8.8" PRIx32 ", field "
>   								"'Base Board Type %d', offset 0x%2.2x",
>   								val, table, addr, i, 0x15 + (i*len));
> +						}
>   					}
>   				}
>   			}
>
Acked-by: Alex Hung <alex.hung@canonical.com>
Ivan Hu - May 16, 2013, 4 a.m.
On 05/07/2013 08:03 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Coverity CID #997280, Nesting level does not match indentation
>
> Fix two bugs; the first is that the snprintf is redundant, the
> second is that the following fwts_failed was should only be
> printed on the if ((val < 0x1) || (val > 0xd)).  Add explicit
> { } brackets just to clarify the intent.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/dmi/dmi_decode/dmi_decode.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/src/dmi/dmi_decode/dmi_decode.c b/src/dmi/dmi_decode/dmi_decode.c
> index 0e775db..d89ab28 100644
> --- a/src/dmi/dmi_decode/dmi_decode.c
> +++ b/src/dmi/dmi_decode/dmi_decode.c
> @@ -597,8 +597,7 @@ static void dmi_decode_entry(fwts_framework *fw,
>   								"offset 0x%2.2x",
>   								val, table, addr, i, 0x15 + (i*len));
>   					} else {
> -						if ((val < 0x1) || (val > 0xd))
> -							snprintf(tmp, sizeof(tmp), "Base Board Type %d", i);
> +						if ((val < 0x1) || (val > 0xd)) {
>   							fwts_failed(fw, LOG_LEVEL_HIGH, DMI_VALUE_OUT_OF_RANGE,
>   								"Out of range value 0x%2.2" PRIx8
>   								" (range allowed 0x00..0x42) "
> @@ -606,6 +605,7 @@ static void dmi_decode_entry(fwts_framework *fw,
>   								"0x%8.8" PRIx32 ", field "
>   								"'Base Board Type %d', offset 0x%2.2x",
>   								val, table, addr, i, 0x15 + (i*len));
> +						}
>   					}
>   				}
>   			}
>

Acked-by: Ivan Hu <ivan.hu@canonical.com>

Patch

diff --git a/src/dmi/dmi_decode/dmi_decode.c b/src/dmi/dmi_decode/dmi_decode.c
index 0e775db..d89ab28 100644
--- a/src/dmi/dmi_decode/dmi_decode.c
+++ b/src/dmi/dmi_decode/dmi_decode.c
@@ -597,8 +597,7 @@  static void dmi_decode_entry(fwts_framework *fw,
 								"offset 0x%2.2x",
 								val, table, addr, i, 0x15 + (i*len));
 					} else {
-						if ((val < 0x1) || (val > 0xd))
-							snprintf(tmp, sizeof(tmp), "Base Board Type %d", i);
+						if ((val < 0x1) || (val > 0xd)) {
 							fwts_failed(fw, LOG_LEVEL_HIGH, DMI_VALUE_OUT_OF_RANGE,
 								"Out of range value 0x%2.2" PRIx8
 								" (range allowed 0x00..0x42) "
@@ -606,6 +605,7 @@  static void dmi_decode_entry(fwts_framework *fw,
 								"0x%8.8" PRIx32 ", field "
 								"'Base Board Type %d', offset 0x%2.2x",
 								val, table, addr, i, 0x15 + (i*len));
+						}
 					}
 				}
 			}