diff mbox

[2/2] linux-generic: system info: check return codes for sscanf

Message ID 1459178612-10830-2-git-send-email-maxim.uvarov@linaro.org
State Accepted
Commit 425ea3f0e0c936028ec812cb0c685eae63cdab17
Headers show

Commit Message

Maxim Uvarov March 28, 2016, 3:23 p.m. UTC
Check return codes for Coverity issues:
https://bugs.linaro.org/show_bug.cgi?id=2129

Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
---
 platform/linux-generic/odp_system_info.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Comments

Maxim Uvarov March 30, 2016, 1:05 p.m. UTC | #1
ping, this simple patch needs a review.

Maxim.

On 03/28/16 18:23, Maxim Uvarov wrote:
> Check return codes for Coverity issues:
> https://bugs.linaro.org/show_bug.cgi?id=2129
>
> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
> ---
>   platform/linux-generic/odp_system_info.c | 9 ++++++---
>   1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/platform/linux-generic/odp_system_info.c b/platform/linux-generic/odp_system_info.c
> index 395b274..0277c3b 100644
> --- a/platform/linux-generic/odp_system_info.c
> +++ b/platform/linux-generic/odp_system_info.c
> @@ -66,7 +66,8 @@ static int systemcpu_cache_line_size(void)
>   
>   	if (fgets(str, sizeof(str), file) != NULL) {
>   		/* Read cache line size */
> -		sscanf(str, "%i", &size);
> +		if (sscanf(str, "%i", &size) != 1)
> +			size = 0;
>   	}
>   
>   	fclose(file);
> @@ -99,7 +100,9 @@ static int huge_page_size(void)
>   
>   	while ((dirent = readdir(dir)) != NULL) {
>   		int temp = 0;
> -		sscanf(dirent->d_name, "hugepages-%i", &temp);
> +
> +		if (sscanf(dirent->d_name, "hugepages-%i", &temp) != 1)
> +			continue;
>   
>   		if (temp > size)
>   			size = temp;
> @@ -110,7 +113,7 @@ static int huge_page_size(void)
>   		return 0;
>   	}
>   
> -	return size*1024;
> +	return size * 1024;
>   }
>   
>
Mike Holmes March 30, 2016, 4:16 p.m. UTC | #2
On 28 March 2016 at 11:23, Maxim Uvarov <maxim.uvarov@linaro.org> wrote:

> Check return codes for Coverity issues:

> https://bugs.linaro.org/show_bug.cgi?id=2129

>

> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>

>


Reviewed-by: Mike Holmes <mike.holmes@linaro.org>



> ---

>  platform/linux-generic/odp_system_info.c | 9 ++++++---

>  1 file changed, 6 insertions(+), 3 deletions(-)

>

> diff --git a/platform/linux-generic/odp_system_info.c

> b/platform/linux-generic/odp_system_info.c

> index 395b274..0277c3b 100644

> --- a/platform/linux-generic/odp_system_info.c

> +++ b/platform/linux-generic/odp_system_info.c

> @@ -66,7 +66,8 @@ static int systemcpu_cache_line_size(void)

>

>         if (fgets(str, sizeof(str), file) != NULL) {

>                 /* Read cache line size */

> -               sscanf(str, "%i", &size);

> +               if (sscanf(str, "%i", &size) != 1)

> +                       size = 0;

>         }

>

>         fclose(file);

> @@ -99,7 +100,9 @@ static int huge_page_size(void)

>

>         while ((dirent = readdir(dir)) != NULL) {

>                 int temp = 0;

> -               sscanf(dirent->d_name, "hugepages-%i", &temp);

> +

> +               if (sscanf(dirent->d_name, "hugepages-%i", &temp) != 1)

> +                       continue;

>

>                 if (temp > size)

>                         size = temp;

> @@ -110,7 +113,7 @@ static int huge_page_size(void)

>                 return 0;

>         }

>

> -       return size*1024;

> +       return size * 1024;

>  }

>

>

> --

> 2.7.1.250.gff4ea60

>

> _______________________________________________

> lng-odp mailing list

> lng-odp@lists.linaro.org

> https://lists.linaro.org/mailman/listinfo/lng-odp

>




-- 
Mike Holmes
Technical Manager - Linaro Networking Group
Linaro.org <http://www.linaro.org/> *│ *Open source software for ARM SoCs
"Work should be fun and collaborative, the rest follows"
Maxim Uvarov March 31, 2016, 6:49 p.m. UTC | #3
Merged,
Maxim.

On 03/30/16 19:16, Mike Holmes wrote:
>
>
> On 28 March 2016 at 11:23, Maxim Uvarov <maxim.uvarov@linaro.org 
> <mailto:maxim.uvarov@linaro.org>> wrote:
>
>     Check return codes for Coverity issues:
>     https://bugs.linaro.org/show_bug.cgi?id=2129
>
>     Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org
>     <mailto:maxim.uvarov@linaro.org>>
>
>
> Reviewed-by: Mike Holmes <mike.holmes@linaro.org 
> <mailto:mike.holmes@linaro.org>>
>
>     ---
>      platform/linux-generic/odp_system_info.c | 9 ++++++---
>      1 file changed, 6 insertions(+), 3 deletions(-)
>
>     diff --git a/platform/linux-generic/odp_system_info.c
>     b/platform/linux-generic/odp_system_info.c
>     index 395b274..0277c3b 100644
>     --- a/platform/linux-generic/odp_system_info.c
>     +++ b/platform/linux-generic/odp_system_info.c
>     @@ -66,7 +66,8 @@ static int systemcpu_cache_line_size(void)
>
>             if (fgets(str, sizeof(str), file) != NULL) {
>                     /* Read cache line size */
>     -               sscanf(str, "%i", &size);
>     +               if (sscanf(str, "%i", &size) != 1)
>     +                       size = 0;
>             }
>
>             fclose(file);
>     @@ -99,7 +100,9 @@ static int huge_page_size(void)
>
>             while ((dirent = readdir(dir)) != NULL) {
>                     int temp = 0;
>     -               sscanf(dirent->d_name, "hugepages-%i", &temp);
>     +
>     +               if (sscanf(dirent->d_name, "hugepages-%i", &temp)
>     != 1)
>     +                       continue;
>
>                     if (temp > size)
>                             size = temp;
>     @@ -110,7 +113,7 @@ static int huge_page_size(void)
>                     return 0;
>             }
>
>     -       return size*1024;
>     +       return size * 1024;
>      }
>
>
>     --
>     2.7.1.250.gff4ea60
>
>     _______________________________________________
>     lng-odp mailing list
>     lng-odp@lists.linaro.org <mailto:lng-odp@lists.linaro.org>
>     https://lists.linaro.org/mailman/listinfo/lng-odp
>
>
>
>
> -- 
> Mike Holmes
> Technical Manager - Linaro Networking Group
> Linaro.org <http://www.linaro.org/>***│ *Open source software for ARM SoCs
> "Work should be fun and collaborative, the rest follows"
>
diff mbox

Patch

diff --git a/platform/linux-generic/odp_system_info.c b/platform/linux-generic/odp_system_info.c
index 395b274..0277c3b 100644
--- a/platform/linux-generic/odp_system_info.c
+++ b/platform/linux-generic/odp_system_info.c
@@ -66,7 +66,8 @@  static int systemcpu_cache_line_size(void)
 
 	if (fgets(str, sizeof(str), file) != NULL) {
 		/* Read cache line size */
-		sscanf(str, "%i", &size);
+		if (sscanf(str, "%i", &size) != 1)
+			size = 0;
 	}
 
 	fclose(file);
@@ -99,7 +100,9 @@  static int huge_page_size(void)
 
 	while ((dirent = readdir(dir)) != NULL) {
 		int temp = 0;
-		sscanf(dirent->d_name, "hugepages-%i", &temp);
+
+		if (sscanf(dirent->d_name, "hugepages-%i", &temp) != 1)
+			continue;
 
 		if (temp > size)
 			size = temp;
@@ -110,7 +113,7 @@  static int huge_page_size(void)
 		return 0;
 	}
 
-	return size*1024;
+	return size * 1024;
 }