diff mbox

[04/46] acpi: brightness: reduce scope of variables

Message ID 1421175905-17035-5-git-send-email-colin.king@canonical.com
State Accepted
Headers show

Commit Message

Colin Ian King Jan. 13, 2015, 7:04 p.m. UTC
From: Colin Ian King <colin.king@canonical.com>

cppcheck is picking up some minor style issues which can
be easily fixed:

[src/acpi/brightness/brightness.c:120]:
	(style) The scope of the variable 'i' can be reduced.
[src/acpi/brightness/brightness.c:173]:
	(style) The scope of the variable 'buffer' can be reduced.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/acpi/brightness/brightness.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

Comments

Ivan Hu Jan. 15, 2015, 7:28 a.m. UTC | #1
On 01/14/2015 03:04 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> cppcheck is picking up some minor style issues which can
> be easily fixed:
>
> [src/acpi/brightness/brightness.c:120]:
> 	(style) The scope of the variable 'i' can be reduced.
> [src/acpi/brightness/brightness.c:173]:
> 	(style) The scope of the variable 'buffer' can be reduced.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/acpi/brightness/brightness.c | 7 +++----
>   1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/src/acpi/brightness/brightness.c b/src/acpi/brightness/brightness.c
> index ffc9d5b..15486e9 100644
> --- a/src/acpi/brightness/brightness.c
> +++ b/src/acpi/brightness/brightness.c
> @@ -117,8 +117,6 @@ static int brightness_test2(fwts_framework *fw)
>
>   	rewinddir(brightness_dir);
>   	do {
> -		int i;
> -
>   		entry = readdir(brightness_dir);
>   		if (entry == NULL || entry->d_name[0] == '.')
>   			continue;
> @@ -141,7 +139,7 @@ static int brightness_test2(fwts_framework *fw)
>   		fwts_printf(fw, "==== Backlight will now slowly transition from dim to bright ====\n");
>   		if (brightness_get_setting(entry->d_name, "actual_brightness", &saved_brightness) == FWTS_OK) {
>   			long delay = 5000000 / max_brightness;
> -			int ch;
> +			int ch, i;
>
>   			if (delay > 1000000)
>   				delay = 1000000;
> @@ -170,7 +168,6 @@ static int brightness_wait_event(fwts_framework *fw)
>   {
>   	int fd;
>   	int events = 0;
> -	char *buffer;
>   	size_t len;
>   	int i;
>
> @@ -180,6 +177,8 @@ static int brightness_wait_event(fwts_framework *fw)
>   	}
>
>   	for (i = 0; i <= 20; i++) {
> +		char *buffer;
> +
>   		if ((buffer = fwts_acpi_event_read(fd, &len, 1)) != NULL)
>   			if (strstr(buffer, "video")) {
>   				free(buffer);
>

Acked-by: Ivan Hu <ivan.hu@canonical.com>
Keng-Yu Lin Jan. 20, 2015, 6:44 a.m. UTC | #2
On Wed, Jan 14, 2015 at 3:04 AM, Colin King <colin.king@canonical.com> wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> cppcheck is picking up some minor style issues which can
> be easily fixed:
>
> [src/acpi/brightness/brightness.c:120]:
>         (style) The scope of the variable 'i' can be reduced.
> [src/acpi/brightness/brightness.c:173]:
>         (style) The scope of the variable 'buffer' can be reduced.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/acpi/brightness/brightness.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/src/acpi/brightness/brightness.c b/src/acpi/brightness/brightness.c
> index ffc9d5b..15486e9 100644
> --- a/src/acpi/brightness/brightness.c
> +++ b/src/acpi/brightness/brightness.c
> @@ -117,8 +117,6 @@ static int brightness_test2(fwts_framework *fw)
>
>         rewinddir(brightness_dir);
>         do {
> -               int i;
> -
>                 entry = readdir(brightness_dir);
>                 if (entry == NULL || entry->d_name[0] == '.')
>                         continue;
> @@ -141,7 +139,7 @@ static int brightness_test2(fwts_framework *fw)
>                 fwts_printf(fw, "==== Backlight will now slowly transition from dim to bright ====\n");
>                 if (brightness_get_setting(entry->d_name, "actual_brightness", &saved_brightness) == FWTS_OK) {
>                         long delay = 5000000 / max_brightness;
> -                       int ch;
> +                       int ch, i;
>
>                         if (delay > 1000000)
>                                 delay = 1000000;
> @@ -170,7 +168,6 @@ static int brightness_wait_event(fwts_framework *fw)
>  {
>         int fd;
>         int events = 0;
> -       char *buffer;
>         size_t len;
>         int i;
>
> @@ -180,6 +177,8 @@ static int brightness_wait_event(fwts_framework *fw)
>         }
>
>         for (i = 0; i <= 20; i++) {
> +               char *buffer;
> +
>                 if ((buffer = fwts_acpi_event_read(fd, &len, 1)) != NULL)
>                         if (strstr(buffer, "video")) {
>                                 free(buffer);
> --
> 2.1.4
>
>
Acked-by: Keng-Yu Lin <kengyu@canonical.com>
diff mbox

Patch

diff --git a/src/acpi/brightness/brightness.c b/src/acpi/brightness/brightness.c
index ffc9d5b..15486e9 100644
--- a/src/acpi/brightness/brightness.c
+++ b/src/acpi/brightness/brightness.c
@@ -117,8 +117,6 @@  static int brightness_test2(fwts_framework *fw)
 
 	rewinddir(brightness_dir);
 	do {
-		int i;
-
 		entry = readdir(brightness_dir);
 		if (entry == NULL || entry->d_name[0] == '.')
 			continue;
@@ -141,7 +139,7 @@  static int brightness_test2(fwts_framework *fw)
 		fwts_printf(fw, "==== Backlight will now slowly transition from dim to bright ====\n");
 		if (brightness_get_setting(entry->d_name, "actual_brightness", &saved_brightness) == FWTS_OK) {
 			long delay = 5000000 / max_brightness;
-			int ch;
+			int ch, i;
 
 			if (delay > 1000000)
 				delay = 1000000;
@@ -170,7 +168,6 @@  static int brightness_wait_event(fwts_framework *fw)
 {
 	int fd;
 	int events = 0;
-	char *buffer;
 	size_t len;
 	int i;
 
@@ -180,6 +177,8 @@  static int brightness_wait_event(fwts_framework *fw)
 	}
 
 	for (i = 0; i <= 20; i++) {
+		char *buffer;
+
 		if ((buffer = fwts_acpi_event_read(fd, &len, 1)) != NULL)
 			if (strstr(buffer, "video")) {
 				free(buffer);